Thursday, January 6, 2011

DataPower: Encoding base64Binary Inline Data into MTOM

Summary:
Learn how to encode base64Binary data as MTOM/XOP using an XSLT in DataPower.


MTOM (Message Transmission Optimization Mechanism) is a W3C standard that uses XOP (XML Binary Optimized Packaging) to transmit binary data. For more information on MTOM or XOP, please refer to [1] and [2] in the references section.

Scenario:
  1. Host service returning (images) base64Binary data inline.
  2. DataPower to encode the base64Binary data and send the response to the client as MTOM/XOP.
Scenario

In-order to achieve this, you will need to create a ‘MTOM Policy’ object. Find MTOM Policy object under Objects/XML Processing/MTOM Policy. MTOM policy object can be used for encoding or decoding by selecting the respective MTOM Mode on the Policy Object.

The name that I used for the MTOM Policy Object is ‘MTOM ‘ and for the scenario, we are trying to encode the base64Binary to MTOM so, I selected MTOM Mode as ‘encode’.

Under the MTOM Rules tab on the object, you will need to add a rule providing the XPath expression pointing to the element that has the base64Binary Data.

MTOM Policy Rule

Once the MTOM Policy object has been created, you can use it in any of your services in DataPower. You can do this in two ways.
  1. In your service response policy in DataPower, you can configure a Transform action and use the preshipped mtom.xsl with the MTOM Policy object that you have created as discussed in (References) [3].
  2. For scenarios where you have a generic DataPower service / processing rule for multiple back-end services and if you have a need to use different MTOM policy objects for different services, you could call the preshipped ‘mtom-implementation’ template in your own XSLT as follows.

You can use your own logic to pick the respective MTOM Policy name based on the backend service/operation being invoked.


<xsl:include href="store:///dp/mtom.xsl"/>
  <xsl:template match="/">
      <xsl:call-template>
            <xsl:with-param select="'MTOM'"/>
      </xsl:call-template>
  </xsl:template>


WSDL: Unlike SWA (SOAP With Attachments) definitions in the WSDL bindings, MTOM does not need any specific changes in the WSDL. In the above scenario, the element ‘image’ which holds the base64Binary data coming from the backend service  can be defined as

<xsd:element name="image" type="xsd:base64Binary" />

 The same definition for image element will also work for MTOM.

References:

[1] SOAP Message Transmission Optimization Mechanism

[2] XML-binary Optimized Packaging

[3]Processing Attachments in WebSphere DataPower SOA Appliances

2 comments:

  1. At long last, the AI even dealt with certain inquiries identifying with reasoning, for example, "What is the motivation behind life?"
    artificial intelligence training in pune

    ReplyDelete