Pages

Saturday, April 14, 2012

Retrieve or set a HTTP header from Oracle BPEL

With Oracle SOA Suite 11g patch 12928372  you can finally retrieve or set a HTTP header from BPEL. This patch comes with Patch Set 5 ( 11.1.1.6 )  and this patch can also be applied on PS3 ( 11.1.1.4 ), please download it from http://support.oracle.com

I made a simple test case with soapUI which adds an username and a message as HTTP header to the  service invocation.  In a second testcase I will mock this service in soapUI and BPEL will invoke this service and set an extra HTTP header property.

First step is to add a property to the binding.ws element of the service in the composite.xml. Add a property with name oracle.webservices.http.headers and as value the HTTP headers you want to use in BPEL
<property name="oracle.webservices.http.headers">username,message</property>


Next step is to define some BPEL variables for those HTTP Headers


In the receive activity of the BPEL process we can use fromProperty to copy the HTTP header property value to the BPEL variable. 

Do this in the BPEL source mode. 


Now you can use these variables in BPEL, I will use these vars in the return message.

Let's invoke the service from soapUI, we need to set the HTTP header properties with their values.



When we want to invoke a reference service and we also want to set some HTTP header properties.

We need also need to set the http.headers property on the binding.ws element on the reference in the composite.xml

<property name="oracle.webservices.http.headers">username,message,message2</property>


On the invoke of the reference service we need to use the toProperty and set the BPEL vars to these HTTP header properties.


When we test it again in soapUI we can see the invoke request of the soapUI mockservice, this contains the HTTP headers which we set in the BPEL process.


45 comments:

  1. Thanks for sharing this useful information. This would simplify handling http headers. I had a similar usecase in 11.1.1.3, tried several things in bpel, gave up and finally created a proxy service in OSB that can set http headers and let bpel call osb proxy service. Once we upgrade I will modify bpel to directly set http header. Thank you!!

    ReplyDelete
  2. Given the features like httpbinding and http header manipualtion from bpel, Do you have an exmaple to invoke Rest based web service call directly from BPEL?

    ReplyDelete
    Replies
    1. Hi,

      this comes close, use the http adapter.
      http://biemond.blogspot.com/2010/05/http-binding-in-soa-suite-11g-ps2.html

      thanks

      Delete
  3. Thanks for the pointer, it certainly helps in case of sending XML payload using REST but not for JSON. I know one of your old article talked about using JSON within OSB by adding JSON libraries to OSB server classpath. I was hoping to find an easy and efficient way to deal with REST/JSON directly from within BPEL.

    ReplyDelete
    Replies
    1. Not possible,

      maybe you can make your own owsm policy who can do the conversion for you.

      thanks

      Delete
  4. Edwin,

    We are using SOA 11g PS2.
    How can we achieve this in that.?

    We need to pass the following custom http headers.
    x_company_wss_username
    x_company_wss_password

    Thanks,
    Siddhardha.

    ReplyDelete
    Replies
    1. Sorry only ps3 and higher.
      you can ask for a backport. by the way ps2 is not so stable, please upgrade.
      thanks

      Delete
  5. Hi Edwin,

    I have installed SOA Suite 11.1.1.4 and weblogic server 10.1.3.4. I have deployed some composites on to the SOA Server where in i have used human tasks i.e. workflows inside the composites. I am trying to send a request from one of my webapplication but it is throwing me an exception which is described below.


    <ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase RENDER_RESPONSE 6
    javax.faces.FacesException: javax.servlet.ServletException: OracleJSP error:
    javax.faces.FacesException: javax.el.PropertyNotFoundException: Target Unreachable, 'requestInfoView' returned null

    Can you please through a light if you have come acrossed it. As it is an urgent which needs to be resolved.


    Regards,
    Chakri

    ReplyDelete
  6. Hi Edwin,

    We are using SOA 11.1.1.6.0; I tried the steps you have listed above to access the http header variable however BPEL could not read the header variable value.

    There was no error but header variable was blank; do we need to apply any patch separately?

    Is there a way to propagate http header (username/password) received from caller in composite/BPEL to the web service called by BPEL - as there was in 10g?

    Thanks,

    ReplyDelete
    Replies
    1. Hi,

      is the bpel wired to a service or is there a mediator before the bpel service component.
      it should work, but to do identity propagation you should use saml.

      try to set http headers and see if that works

      thanks

      Delete
  7. Same problem. I'm trying to send a http redirect with a http binding setting status code 302 and Location http headers. Is that possible ?

    I'm using 11.1.1.6 and cannot read or write the http header.

    Can I use this on a http binding interface ?

    I'm setting http response headers on the reply.

    ReplyDelete
    Replies
    1. Hi,

      it should work with PS5 but don't know if a re-direct will work.

      thanks

      Delete
    2. Isnt this a limitation with SOA suite ?
      http://docs.oracle.com/cd/E25054_01/dev.1111/e10224/sca_bindingcomps.htm#autoId3 or it is sorted in PS6 ?

      Delete
  8. Hi Edwin,

    Can this be used to pass the 'Authorization' header as well?
    This would enable us to use this to pass values dynamically for Basic Authentication in BPEL (been looking for such a solution).

    Thanks,
    Vivek

    ReplyDelete
    Replies
    1. Hi,

      Don't think it is designed for this , but I think you can retrieve and pass on http headers.

      Thanks

      Delete
  9. Hi,
    We are running oracle soa 11.1.1.7 and I tried to use the similar solution but its not working for me the way it worked for you. can you please confirm if I it will work with 11.1.1.7 ?

    ReplyDelete
    Replies
    1. Hi,

      I didn't test it on PS6 but it should work in 11.1.1.7 else you can log a support call.

      Thanks

      Delete
  10. Hello Biemond,

    I tried to get the HTTP Headers from an Invoke Response using the way mentioned:

    In composite.xml under reference:
    Set-Cookie

    In bpel, under Invoke activity:




    It doesn't work. I checked with HTTP Analyzer, Set-Cookie is coming back in HTTP response Header. But In BPEL in get null.

    Any Help, please.

    Thanks,
    --Inder

    ReplyDelete
    Replies
    1. Adding HTML Tags. Hopefully they would come this time:

      In composite.xml under reference:
      <property name="oracle.webservices.http.headers">Set-Cookie</property>

      In bpel, under Invoke activity:
      <bpelx:fromProperties>
      <bpelx:fromProperty name="Set-Cookie" variable="lvarHTTPSession"/>
      </bpelx:fromProperties>

      Delete
    2. Hi,

      Did you got it working?

      Thanks

      Delete
    3. Hi Biemond,

      I have raised an SR with Oracle. Will let know here if i get something.

      It is working for retrieving Request Header, setting Request Header but doesn't work for retrieving Response Header.

      Thanks,
      --Inder

      Delete
    4. No help from Oracle yet!

      It is working for retrieving Request Header.
      Working for setting Request Header. But doesn't work for retrieving Response Header.

      That given me a feeling that it could be that i am doing something wrong.

      Anybody if have tried it.. please share if it worked for you?

      Thanks,
      --Inder

      Delete
    5. Hi,

      it is very simple testcase, so I think it is a bug or did you add a mediator in between.

      Thanks

      Delete
    6. Hi

      I have a similar requirement with Set-Cookie. Was someone able to get this working?

      Thanks

      Delete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Hi Edwin,
    I am trying to pass Authorization header which has following value : 'Basic Yw79u1jshbihchjasj=='
    where, Yw79u1jshbihchjasj== represents Base64Encoded username:password
    I have following configuration
    1) I have added following in composite.xml under reference

    property name="oracle.webservices.http.headers">Authorization
    bpelx:toProperty name="Authorization" variable="Authorization"/>
    /bpelx:toProperties>

    I am assigning the value to Autorization(string variable) using Assign activity.
    But, it is not working for me. I am using SOA 11.1.1.5
    In addition, do I need to add bpelx:inputHeaderVariable="Autorization" along with the Custom Header properties?

    Please help as I am not able to figure out other ways to send this Header while making a HTTP POST call using HTTP Bindings adapter
    PS : I

    ReplyDelete
  13. Hi Edwin,
    I am trying to pass Authorization header which has following value : 'Basic Yw79u1jshbihchjasj=='
    where, Yw79u1jshbihchjasj== represents Base64Encoded username:password
    I have following configuration
    1) I have added following in composite.xml under reference
    property name="oracle.webservices.http.headers">Authorization/property>
    2) I have added following in MyBPEL.bpel under invoke
    bpelx:toProperties>
    bpelx:toProperty name="Authorization" variable="Authorization"/>
    /bpelx:toProperties>


    I am assigning the value to Autorization(string variable) using Assign activity.
    But, it is not working for me. I am using SOA 11.1.1.5
    In addition, do I need to add bpelx:inputHeaderVariable="Autorization" along with the Custom Header properties?

    Please help as I am not able to figure out other ways to send this Header while making a HTTP POST call using HTTP Bindings adapter

    ReplyDelete
  14. Hi Edwin,
    I am trying to pass Authorization header which has following value : 'Basic Yw79u1jshbihchjasj=='
    where, Yw79u1jshbihchjasj== represents Base64Encoded username:password
    I have following configuration
    1) I have added following in composite.xml under reference
    property name="oracle.webservices.http.headers">Authorization/property>
    2) I have added following in MyBPEL.bpel under invoke
    bpelx:toProperties>
    bpelx:toProperty name="Authorization" variable="tempString1"/>
    /bpelx:toProperties>


    I am assigning the value to Autorization(string variable) using Assign activity.
    But, it is not working for me. I am using SOA 11.1.1.5
    In addition, do I need to add bpelx:inputHeaderVariable="Autorization" along with the Custom Header properties?

    Please help as I am not able to figure out other ways to send this Header while making a HTTP POST call using HTTP Bindings adapter

    ReplyDelete
    Replies
    1. Hi,

      Did you add the patch cause I think it is not support in PS4 , I know PS3 with patch and is added to PS5.

      thanks

      Delete
    2. Yes Edwin, not only the patch was missing but the SOA 11.1.1.5 is not able to understand toProperties.
      I changed the toProperties to inputProperty and the Header information was being passed successfully.
      But, the issue is still not resolved as the service is returning 200 OK message and I am getting following error :
      javax.xml.ws.WebServiceException: javax.xml.soap.SOAPException: javax.xml.soap.SOAPException: Unable to read response: org.xml.sax.SAXParseException: Content is not allowed in prolog.

      Am I missing something or Is it that the HTTP Bindings adapter can't read the response header.
      Please help
      Thanks

      Delete
  15. Edwin- Thanks for this post. However I didnt get it working when Bpel is calling a Mediator.

    I set the Reference properties for Mediator + Invoke for Mediator in Bpel.
    But Bpel is not sending the Header to Mediator.

    If I test mediator separately it works fine , I am working on 11.1.1.17 and used the sample for mediator from : https://java.net/projects/oraclesoasuite11g/downloads/directory/Mediator

    Please suggest.

    Thanks
    Sam

    ReplyDelete
  16. was able to send the Header from Bpel to Mediator , But now the mediator is not able to fetch the Header value from header. Looks like Mediator always expects the header in format like :
    $in.header.inp1_UserNameHeader/inp1:UserNameHeader

    However when i send from Bpel , it is passed as below :


    SamInBpel





    Test




    Not sure what I am missing ?

    - Sam

    ReplyDelete
    Replies
    1. Hi,

      never got this working with BPEL and mediator, only with BPEL.
      can you set or retrieve the http properties you want on the mediator component or just some fixed ones



      Delete
  17. Hi Edwin,

    I have a HTTP Binding that does a post with a XML payload as an exposed service. I've been trying to set the mime:content-type of the input and output messages to application/xml but have been unsuccessful so far. Do you know where I set the content-type anywhere in BPEL?

    I've tried adding a tag in the WSDL file but that doesn't seem to work as well.










    Regards,
    Mark

    ReplyDelete
    Replies
    1. http://stackoverflow.com/questions/21086549/bpel-unable-to-set-mimecontent-type-in-wsdl

      Delete
    2. Hi,

      Soa suite is not so flexible, can you use OSB or create a Java WS
      thanks

      Delete
  18. Hi,
    We are unable to invoke a REST based service through BPEL using a HTTP Binding adapter. We are using jdev 11.1.1.6
    1. we are passing the following header to invoke a REST based service
    a) Authorization
    b) X-API-Key
    2. We have set the following properties in the composite.xml, under the reference tag of the service
    property name="oracle.webservices.http.headers" type="xs:string"
    many="false">Authorization,X-API-Key
    3. Also in the BPEL we are setting the header values in the Invoke




    4.The xsd for invoking the service is a complex xsd
    But we get the following error while invoking the service
    "unable to access the following endpoint(s): REPLACE_WITH_ACTUAL_URL"
    But we are able to get a response from the service through SOAPUI application

    Can you please suggest what can he going wrong here or what more needs to be done?

    ReplyDelete
  19. Thanks for the wonderful tutorial, it didn't work on BPEL 1.1 so i tried BPEL 2.0 and it's work..............
    don't know why it's not worked on BPEL 1.1.............I tested it on 11.1.1.6

    ReplyDelete
  20. I am using SOA 11.1.1.7 and need to pass a custom HTTP request header to a REST service on POST method. Is there a way for passing the header using BPEL 2.0 ?

    ReplyDelete
  21. Hi Edwin,

    I am using Jdeveloper 11.1.1.7.0. I need to invoke RESTful service by using HTTP Binding adapter in BPEL using OAuth 2.0 . In order to use this, I need to set Custom HTTP header . I have try add header using soapui and postman and it has worked in both but I can't use it in BPEL.

    I have add this in the Composite.xml file
    Authorization
    This has been add under the reference section.

    Then, in BPEL I have create a new variable called Access_Token and add toProperties under the invoke section








    After I have set this in the BPEL i still get an error and fail to pass the custom HTTP headers. Below is the error.
    Error Message: Bad response: 401 Unauthorized.

    Is there any solution or guide for this? I need the solution urgently.

    Thanks.

    ReplyDelete
  22. Hi Edwin,

    I am using Jdeveloper 11.1.1.7.0. I need to invoke RESTful service by using HTTP Binding adapter in BPEL. To invoke this RESTful service I need to use OAuth 2.0 . In order to use this, I need to set Custom header . I have try add header using soapui and postman and it has worked in both but I can't use it in BPEL.

    I have add this in the Composite.xml file
    Authorization
    This has been add under the reference section.

    Then, in BPEL I have create a new variable called Access_Token and add toProperties under the invoke section








    After I have set this in the BPEL i still get an error and fail to pass the custom HTTP headers. Below is the error.
    Error Message: Bad response: 401 Unauthorized.

    Is there any solution or guide for this? I need the solution urgently.

    Thanks.

    ReplyDelete
  23. can you please share your example along with soapui project?

    ReplyDelete
  24. How does BPEL 10.1.3.5 supports similar kind of feature. We have such requirement that from BPEL we need to pass http-header details to ESB (via OHS). ESB could able to get but the OHS will not able to read it.

    We followed below links, but not worked for us Any clue

    clemensblog.blogspot.in/2006/02/consuming-statefull-webservices-from.html
    http://www.oracle.com/technetwork/middleware/ias/callingstatefulwsfrombpel-091022.html

    Thanks & Regards
    Venkata MR
    +91 98455 77125

    ReplyDelete
  25. If it's not working in 11.1.1.6 then use below syntex:

    Receive Activity:
    -----------------







    Invoke Activity:
    -----------------




    ReplyDelete
  26. We were able to accomplish this by using BPEL Specification 2.0

    ReplyDelete