Monday, May 23, 2016

Attachment handling in OSB(InBound)

          There might be few scenarios wherein we might have to transfer image files/pdf files or any type of file as attachment between different components,lets see how can we achieve this in OSB. 
         We can process attachments by 3 ways in OSB


  • Inline attachments-- Encode the file/binary conent in base64 and place the contents inside XML elements(we cant place the binary content in XML it will break the XML structure,so it is essential to convert binary to base64)
    • this works well but the problem is base64 conversion makes the message very huge and it makes handling difficult, probably for smaller size attachments this might be an good option
    • Sample XML with Inline base64 contents
<Envelope>
<Body>
<Request>
<filename>loanapprovalform.pdf</filename>
<image>ZHNkc2Rhc2Rhc2Q=[base64 contents]</image>
</Request>
</Body>
</Envelope> 


  • SwA -- SOAP with Attachments it is basically a MIME message, try sending a request to OSB ProxyService from SOAPUI, you can see the soap message and attachment will be mime messages, 
    • In OSB, to process SwA(MIME) you have to parse $attachments/ctx:attachments/ctx:attachment/ctx:body/ctx:binary-content/
    • Note that there are 2 attachments in this request ,  jar file is sent as binary content we can't see the content as only reference to that binary content will be there , we have to pass the reference($attachments/ctx:attachments/ctx:attachment/ctx:body/ctx:binary-content/) to java method to process the same
                        

    • the problem with this approach is it breaks the SOAP message format and we can't apply ws policies 
    •  inter-operability is a concern
  • MTOM/XOP
    • SOAP Message Transmission Optimization Mechanism/XML-binary Optimized Packaging (MTOM/XOP) defines a method for optimizing the transmission of XML data of type xs:base64Binary or xs:hexBinary in SOAP messages. When the transport protocol is HTTP, MIME attachments are used to carry that data while at the same time allowing both the sender and the receiver direct access to the XML data in the SOAP message without having to be aware that any MIME artifacts were used to marshal the base64Binary or hexBinary data. The binary data optimization process involves the following steps:
      • encode the binary data,
      • remove the binary data from the SOAP envelope
      • compress the binary data, 
      • attach the binary data to the MIME package, and
      • add references to the MIME package in the SOAP envelope.
    • Enable MTOM/XOP in OSB 
    • Oracle Service Bus supports parsing inbound messages & sending outbound messages in MTOM/XOP format. This capability is available for any XML based (or) WSDL based services.
    • Include Binary data by Reference - can be used for pass through scenarios where in we don't really need to parse the attachment (or) to pass the attachment directly to MFL or Java callout. The attachment will be available as part of $body/ctx:binary-content variable.
    • Include Binary data by Value - can be used when you want to validate the xml schema (or) scenarios where the outbound service doesn't support MTOM. In this case, the xop:include will be replaced with the actual base64 binary content.
    • Sample MTOM XML ,cid:973517623829 points to the binary reference in the MIME 
      • <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Header/>
        <soapenv:Body>
        <Request>
        <file>
        <xop:Include href="cid:973517623829" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
        </file>
        </Request>
        </soapenv:Body>
        </soapenv:Envelope>
    • $attachments variable will not be generated for MTOM/XOP

3 comments:

  1. Hi!, do you know how i can test PS con MTOM attachment in osb console? I can not put the attachment...

    ReplyDelete
  2. I wish to show thanks to you just for bailing me out of this particular trouble. As a result of checking through the net and meeting techniques that were not productive, Same as your blog I found another one Oracle OSB 12c.Actually I was looking for the same information on internet for Oracle OSB 12c and came across your blog. I am impressed by the information that you have on this blog. Thanks once more for all the details.

    ReplyDelete