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.


14 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
  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