Friday, April 5, 2013

RESTful Services - OSB transport headers for passing HTTP header / custom values



            In one of my projects I was implementing the Gateway architecture, where I have grouped together all common activities and will route to the different project /modules, based on relative URI and needs to pass on the http headers.
There is a misconception that HTTP headers can only be passed if the backend Proxies are using transport protocol as HTTP and not local. This is not true, even in the case of local proxies the headers can be passed through. I am explaining how this can be done using the frontend and backend proxies and using local and HTTP transport protocols.

 This is how you fetch the values from header in front –end proxy and set in the outbound to the backend proxy






Transport Protocol -HTTP





This is how the values will be passed in $inbound



    <tran:headers xsi:type="http:HttpRequestHeaders" xmlns:tran="http://www.bea.com/wli/sb/transports">
        <tran:user-header name="http-method" value="GET"/>
        <tran:user-header name="query-string" value="name=George"/>
        <tran:user-header name="relative-URI" value=”Customer/GetCustomerDetails”/>
        <http:Content-Type>text/xml</http:Content-Type>
      </tran:headers>


Transport Protocol -Local


This is how the values will be passed in $inbound


<con:qualityOfService>best-effort</con:qualityOfService>
    <con:request xsi:type="loc:LocalRequestMetaData" xmlns:loc="http://www.bea.com/wli/sb/transports/local" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <tran:headers xsi:type="loc:LocalRequestHeaders" xmlns:tran="http://www.bea.com/wli/sb/transports">
        <tran:user-header name="http-method" value="GET"/>
        <tran:user-header name="query-string" value="name=George"/>
        <tran:user-header name="relative-URI" value=”Customer/GetCustomerDetails”/>
      </tran:headers>


Receiving proxy
-----------------------------------
The caller will embedd the values in the user-header name-value pairs.
The receiving proxy can retreive the values  from tp:user-header and pass in the required the name to fetch the corresponding values..The syntax is below.

$inbound/ctx:transport/ctx:request/tp:headers/tp:user-header[@name="relative-URI"]/@value




Similarly you can fetch all the header values in backend proxy.
That’s it from my desk J

3 comments:

Nikhil said...

Hi,

I am doing something similar to this, but am calling a BS from PS(REST based). In message flow did the publish to BS and set transport headers within the publish.

I have set Content-Type,http-method and two user headers to "$inbound/ctx:transport/ctx:request/tp:headers/tp:user-header/@name" and "$inbound/ctx:transport/ctx:request/tp:headers/tp:user-header/@value".

Also, my PS has "Pass all Headers through Pipeline" set and have also created a pass-through service account on BS so that headers pass through till the endpoint via BS.

Also, I've set "Get All Headers" to Yes under Transport Configuration tab on PS.

What else am missing? My request is getting echoed. BS is not even getting called.

Please advise.

Thanks,
Nikhil


Unknown said...

You will need to log the inbound and outbound variables and see what is being passed.
Hope you have added Route to BS.In Request log the inbound and outbound variables.
Send me the process ,I will have a look.

Nikhil said...

Hi,
My BS is getting invoked now but the user credentials are not getting passed.

Invoked Services
Publish to: "BrowserCheck_BS"
$outbound:




https://host/subscriber.php?post_data=api_key:3cbd8a26a9a9212f5f321c2dd4779dc16651b8730f78eb4bc5a2b,function:create_subscriber,arguments:firstname:nikhil,lastname:jain,company:qualys,email:njain1@qualys.com
$outbound:




https://browsercheck.qualys.com/bo/subscriber.php?post_data=api_key:3cbd8a26a9a9212f5f321c2dd4779dc16651b8730f78eb4bc5a2b,function:create_subscriber,arguments:firstname:nikhil,lastname:jain,company:qualys,email:njain1@qualys.com

request
exactly-once




application/x-www-form-urlencoded




false


The error returned from BS is
"General runtime error: com.bea.wli.sb.security.CredentialNotFoundException"
Above, I've created a custom HTTP header named Authorization and value is Base 64 encoded key.

Regards,
Nikhil