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>



No comments: