Showing posts with label Transport-header. Show all posts
Showing posts with label Transport-header. Show all posts

Thursday, July 18, 2013

Behavior of OSB response Content-Type based on Request-Response message types/Trasport-Header



While designing a single proxy service which will return different formats- say for example json and xml, the response Content-Type plays a big role in browsers or consumer systems understanding the return structure. If the consumer receives the content –type populated as application/json then it can have the json parser interpret the data and if the response content-type is populated as application/xml , then consumer can have the xml parser in action.
For this test I choose the proxy service which has Request-Response message type as text, as the response can vary based on underlying service, as well as consumer requirement. When you design you need to support all the formats, so selecting TEXT type will be the best option.
The issue here is that response content-type will be text/plain by default. The solution is to have a Transport-Header which will overwrite the Content-Type as required. You can do it this way or have the Content-Type copied from the response header if underlying service has set it properly.

Proxy response - no transport header set
Response Metadata      
  -- Default behavior of the proxy
  
<con:metadata     xmlns:con="http://www.bea.com/wli/sb/test/config">
          <tran:headers            xsi:type="http:HttpResponseHeaders" xmlns:http="http://www.bea.com/wli/sb/transports/http" xmlns:tran="http://www.bea.com/wli/sb/transports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <http:Content-Type>text/plain; charset=utf-8</http:Content-Type>
                </tran:headers>
                <tran:response-code          xmlns:tran="http://www.bea.com/wli/sb/transports">0</tran:response-code>
                <tran:encoding    xmlns:tran="http://www.bea.com/wli/sb/transports">utf-8</tran:encoding>
</con:metadata>

Proxy response -transport header is set
 Response Metadata     
<con:metadata     xmlns:con="http://www.bea.com/wli/sb/test/config">
                <tran:headers      xsi:type="http:HttpResponseHeaders" xmlns:http="http://www.bea.com/wli/sb/transports/http" xmlns:tran="http://www.bea.com/wli/sb/transports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <http:Content-Type>application/json; charset=utf-8</http:Content-Type>
                </tran:headers>
                <tran:response-code          xmlns:tran="http://www.bea.com/wli/sb/transports">0</tran:response-code>
                <tran:encoding    xmlns:tran="http://www.bea.com/wli/sb/transports">utf-8</tran:encoding>
</con:metadata>



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