2010/03/18

OSB 10gR3 and SWA and MTOM

This blog is about using soap with attachments and the use of MTOM within the OSB (10gR3).
A service is created that accepts a soap with attachment (DocumentService) and translates it to a service that accepts a binary element. MTOM is used for performance reasons for the second.

Some notes:
* For the use of attachments you need RPC-style document instead of the usual document-style. This due to the fact that the document-style limits a message to a single .
* A service can not have both SWA and MTOM within OSB.

First a WSDL is setup for the DocumentService:

  
    
    
     
      
       
        
       
      
     
     
    
  
  
  
    
    
  

  
    
      
    
  
  
  
    
    
      
      
       
         
           
         
         
           
         
       
      
    
  
  
  
    
      
    
  



The $attachments variable holds the attachments and the body holds the attachment data. Also other data is stored within the attachment element (see here). In the case of a binary attachment (as described within this post), this data is not put in the body element. Instead the Oracle Service Bus run time stores it in an in-memory hash table and a reference to that content is inserted into the XML (binary-content element).



Then you can use the OSB Test console to send an attachment and view the attachment variable.
After the attachment is sent, you can view the content of the attachments variable and it shows the binary reference.

Now the business service wsdl is defined and configured. The following WSDL is used.

  
    
    
     
      
       
        
        
       
      
     

    
  
  
  
    
  

  
    
      
    
  
  
  
    
    
      
      
  
   
    
  
  
  
    
      
    
  

We now define the business service that uses MTOM/XOP as transport protocol. Make a WSDL Web Service with the previous defined WSDL. In the transport properties just use http://localhost:7001/ecm as the endpoint, leave HTTP transport properties the default. In the Message Content you can set the MTOM/XOP enabling of the format. You have two possibilities (I will show both options). First select the "Include Binary Data by Value".


  • Include Binary Data by Reference: (Default) In an outbound response message, replace xop:Include elements with ctx:binary-content elements when setting up the $body message context variable.
  • Include Binary Data by Value: In an outbound response message, replace xop:Include elements with Base64-encoded text versions of corresponding binary data when setting up the $body message context variable.
Now we call this business service from within the proxy service.
Of course we have to map the document attachment to the bas64Binary element within the business service.
We add a Replace (Replace Node Contents) of the $body variable after the Assign.
If you run this within the test console with a Word attachment (Content-Type: application/word), you get the following invocation tree.
You see a binary-content reference, so you do not actually see what goes over the HTTP transport. Therefore you can use tcpmon which is a HTPP monitoring tool.
Run the tool and set it up by listening on port 8090. Click Add Monitor.

You also need to change the endpoint of the business service so that the message is sent to tcpmon.
Now run the test console again with an attachment. Now you probably get the following error.
It says that mixing attachments with XOP/MTOM is not allowed. This is due to the fact that we did not change the $attachments variable. You have to delete the attachments so we add a Delete after the Replace.
If you now run the test console again with an attachment the tcpmon tool we show you the actual http call and it will look something like this.
You can see that the Post is a application/xop+xml type and the Doc element contains a inc:Include reference.
The MIMI boundary contains the actual binary data.

Include Binary Data by Reference
Now change the Message Content configuration of the business service to Include Binary Data by Reference and run the test tool again. You will notice that in this case the result is the same.

12 comments:

  1. Very Useful Article thanks for sharing..

    ReplyDelete
  2. alexander van der WoudeAugust 31, 2010 at 2:39 PM

    Hey Roger,

    usefull article. Just what I needed.

    Chck your WSDL though, closing tags are located in wrong place.

    ReplyDelete
  3. Alexander,

    Good that I could help and thanks for the WSDL remark !

    ReplyDelete
  4. Hi Roger,
    thank you very much for your example.

    But I have found a problem with missing the start-info attribute in the Context-Type.

    Without this attribute called ASP.NET MTOM WS returns 400 Bad Request.

    ReplyDelete
  5. Hi Miloslav,
    Thanks for sharing this!

    In which part do you have to add start-info attribute?

    Thx
    Roger

    ReplyDelete
  6. There is the Content-Type with missing the start-info attribute in a business service. Also in your image from tcpmon.

    If there is no the start-info attribute the IIS(WSE) MTOM web service returns 400 Bad Request.
    I do not know how to add the attribute to the Content-Type.

    Currently I use an Any SOAP(with MTOM support) proxy that sends request with this attribute from client(SoupUI) and the proxy ONLY sends the request to a business service.
    It works.

    See my business service trace log.
    [OSB Tracing] Outbound request was sent.
    multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="----=_Part_1_6447144.1284621320422"

    ReplyDelete
  7. Maybe you can have a look at:
    http://blogs.oracle.com/mneelapu/2010/09/how_to_serve_html_through_osb.html

    Hope this can help you with changing the Content-Type.

    ReplyDelete
  8. Roger,

    Do you have an example to do this with bpel in a composite?

    Thank You.

    JP

    ReplyDelete
  9. @JP: You mean within Oracle SOA Suite 11g?

    ReplyDelete
  10. Hello if this article is up to date? The WSDL are blanked. I am new to this and this example it is quite difficult to me withou proper WSDL.

    ReplyDelete
  11. From MTOM to SwA is possible, among proxies

    ReplyDelete
  12. Thanks!

    I had an issue and your article connected the DOTS.

    I also had blanked WSDL ... but the WSDL is not the answer to your issues.

    ReplyDelete