Showing posts with label XML. Show all posts
Showing posts with label XML. 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>



Thursday, May 16, 2013

Response based on Service Types in OSB


Restful services can be implemented using either Proxy type- Any XML Service or Messaging Service types.
·         Messaging Service - to create a service that can receive messages of one data type and respond with messages of a different data type. These exchanges can be either request/response or one-way.

·         Any XML Service - to create an XML service that does not have an explicitly defined, concrete interface.
There is a difference in the way the responses are handled in each case. It’s interesting to see how the response looks like if we add a proxy layer before the existing proxies. I was implementing the Gateway approach where all existing proxies need to be plugged in into the Gateway proxy. In Gateway I am converting the response to either JSON or pass through XML based on the response format requested by the consumer.
Messaging Service response
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<![CDATA[<GetStatusResponseMsg xmlns="http://geo.com/v1.0">
 <GetStatusResponse xmlns="http://geo.com/test/v1.0">
<ResponseStatus xmlns="http://geo.com/status">PENDING</ResponseStatus>
</ GetStatusResponse >
</ GetStatusResponseMsg >]]>
</soapenv:Body>>
In case your proxy is Messaging service based then the response will be encapsulated in the CDATA tag. You will need to use fn-bea:inlinedXML($body) to fetch the XML from the response body.
Any XML Service response
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <GetStatusResponseMsg xmlns="http://geo.com/v1.0">
 <GetStatusResponse xmlns="http://geo.com/test/v1.0">
<ResponseStatus xmlns="http://geo.com/status">PENDING</ResponseStatus>
</ GetStatusResponse >
</ GetStatusResponseMsg>
</soapenv:Body>>
In case of this approach the response will be in proper XML format without any CDATA encoding.