<definitions xmlns="http://ws.apache.org/ns/synapse">
<sequence name="main">
<in>
<filter source="get-property('Action')" regex="urn:uploadFileUsingMTOM">
<then>
<property name="example" value="mtom"/>
<send>
<endpoint>
<address uri="http://localhost:9000/services/MTOMSwASampleService"
optimize="mtom"/>
</endpoint>
</send>
</then>
</filter>
<filter source="get-property('Action')" regex="urn:uploadFileUsingSwA">
<then>
<property name="example" value="swa"/>
<send>
<endpoint>
<address uri="http://localhost:9000/services/MTOMSwASampleService"
optimize="swa"/>
</endpoint>
</send>
</then>
</filter>
</in>
<out>
<filter source="get-property('example')" regex="mtom">
<then>
<property name="enableMTOM" value="true" scope="axis2"/>
</then>
</filter>
<filter source="get-property('example')" regex="swa">
<then>
<property name="enableSwA" value="true" scope="axis2"/>
</then>
</filter>
<send/>
</out>
</sequence>
</definitions>
Executing the Client
Execute the client as follows to send a MTOM optimized request to Synapse.
ant optimizeclient -Dopt_mode=mtom
Synapse sets a local message context property, and forwards the message to
'http://localhost:9000/services/MTOMSwASampleService', while optimizing binary
content as MTOM. By sending this message through TCPMon you will be able to see
the actual message sent by Synapse if required.
POST /services/MTOMSwASampleService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:uploadFileUsingMTOM
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177413845353; type="application/xop+xml";
start="<0.urn:uuid:B94996494E1DD5F9B51177413845354@apache.org>"; start-info="text/xml"; charset=UTF-8
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO
--MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177413845353241
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID:
<0.urn:uuid:B94996494E1DD5F9B51177413845354@apache.org>221b1
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<m0:uploadFileUsingMTOM xmlns:m0="http://www.apache-synapse.org/test">
<m0:request>
<m0:image>
<xop:Include href="cid:1.urn:uuid:78F94BC50B68D76FB41177413845003@apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include" />
</m0:image>
</m0:request>
</m0:uploadFileUsingMTOM>
</soapenv:Body>
</soapenv:Envelope>
--MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177413845353217
Content-Type: image/gif
Content-Transfer-Encoding: binary
Content-ID:
<1.urn:uuid:78F94BC50B68D76FB41177413845003@apache.org>22800GIF89a... << binary content >>
During response processing, by checking the local message property Synapse can
discover past information about the current message context, and use this
knowledge to send the response back to the client in the same format as the
original request.
When the client executes successfully, it will upload a file containing the ASF
logo and receive a response which is savesd a temporary file.
[java] Sending file : ./../../repository/conf/sample/resources/mtom/asf-logo.gif as MTOM
[java] Saved response to file : ./../../work/temp/sampleClient/mtom-4417.gif
Now invoke the client as follows to send a SwA optimized request.
ant optimizeclient -Dopt_mode=swa
This is identical to the previous invocation with only difference being the use
of SwA (SOAP with Attachement) instead of MTOM for content optimization. You
will get an output similar to following.
[java] Sending file : ./../../repository/conf/sample/resources/mtom/asf-logo.gif as SwA
[java] Saved response to file : ./../../work/temp/sampleClient/swa-30391.gif
By using TCPMon and sending the message through it, one can see that the
requests and responses sent are indeed sent as HTTP attachments as follows.
POST /services/MTOMSwASampleService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:uploadFileUsingSwA
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177414170491; type="text/xml";
start="<0.urn:uuid:B94996494E1DD5F9B51177414170492@apache.org>"; charset=UTF-8
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO
--MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177414170491225
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID:
<0.urn:uuid:B94996494E1DD5F9B51177414170492@apache.org>22159
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<m0:uploadFileUsingSwA xmlns:m0="http://www.apache-synapse.org/test">
<m0:request>
<m0:imageId>urn:uuid:15FD2DA2584A32BF7C1177414169826</m0:imageId>
</m0:request>
</m0:uploadFileUsingSwA>
</soapenv:Body>
</soapenv:Envelope>22--34MIMEBoundaryurn_uuid_B94996494E1DD5F9B511774141704912
17
Content-Type: image/gif
Content-Transfer-Encoding: binary
Content-ID:
<urn:uuid:15FD2DA2584A32BF7C1177414169826>22800GIF89a... << binary content >>