<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
  ~  Licensed to the Apache Software Foundation (ASF) under one
  ~  or more contributor license agreements.  See the NOTICE file
  ~  distributed with this work for additional information
  ~  regarding copyright ownership.  The ASF licenses this file
  ~  to you under the Apache License, Version 2.0 (the
  ~  "License"); you may not use this file except in compliance
  ~  with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<document>
    <properties>
        <title>Apache Synapse - Sample 51</title>
    </properties>
    <body>
        <section name="Sample 51: MTOM and SwA Optimizations and Request/Response Correlation">
            <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="main"&gt;
        &lt;in&gt;
            &lt;filter source="get-property('Action')" regex="urn:uploadFileUsingMTOM"&gt;
                &lt;then&gt;
                    &lt;property name="example" value="mtom"/&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;
                            &lt;address uri="http://localhost:9000/services/MTOMSwASampleService"
                                     optimize="mtom"/&gt;
                        &lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/then&gt;
            &lt;/filter&gt;
            &lt;filter source="get-property('Action')" regex="urn:uploadFileUsingSwA"&gt;
                &lt;then&gt;
                    &lt;property name="example" value="swa"/&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;
                            &lt;address uri="http://localhost:9000/services/MTOMSwASampleService"
                                     optimize="swa"/&gt;
                        &lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/then&gt;
            &lt;/filter&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;filter source="get-property('example')" regex="mtom"&gt;
                &lt;then&gt;
                    &lt;property name="enableMTOM" value="true" scope="axis2"/&gt;
                &lt;/then&gt;
            &lt;/filter&gt;
            &lt;filter source="get-property('example')" regex="swa"&gt;
                &lt;then&gt;
                    &lt;property name="enableSwA" value="true" scope="axis2"/&gt;
                &lt;/then&gt;
            &lt;/filter&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</div>
            <subsection name="Objective">
                <p>
                    Demonstrate the use of content optimization mechanisms like MTOM and SwA with
                    Synapse.
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>
                        <li>
                            Deploy the MTOMSwASampleService in the sample Axis2 server and start Axis2
                        </li>
                        <li>
                            Start Synapse using the configuration numbered 51 (repository/conf/sample/synapse_sample_51.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 51<br/>
                                Windows: synapse.bat -sample 51
                            </div>
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>
                    Execute the client as follows to send a MTOM optimized request to Synapse.
                </p>                
                <div class="command">ant optimizeclient -Dopt_mode=mtom</div>
                <p>
                    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.
                </p>
                <div class="consoleOutput">POST /services/MTOMSwASampleService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:uploadFileUsingMTOM
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177413845353; type=&quot;application/xop+xml&quot;;
start=&quot;&lt;0.urn:uuid:B94996494E1DD5F9B51177413845354@apache.org&gt;&quot;; start-info=&quot;text/xml&quot;; 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=&quot;text/xml&quot;
Content-Transfer-Encoding: binary
Content-ID:
   &lt;0.urn:uuid:B94996494E1DD5F9B51177413845354@apache.org&gt;221b1
      &lt;?xml version='1.0' encoding='UTF-8'?&gt;
         &lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
            &lt;soapenv:Body&gt;
               &lt;m0:uploadFileUsingMTOM xmlns:m0=&quot;http://www.apache-synapse.org/test&quot;&gt;
                  &lt;m0:request&gt;
                     &lt;m0:image&gt;
                        &lt;xop:Include href=&quot;cid:1.urn:uuid:78F94BC50B68D76FB41177413845003@apache.org&quot; xmlns:xop=&quot;http://www.w3.org/2004/08/xop/include&quot; /&gt;
                     &lt;/m0:image&gt;
                  &lt;/m0:request&gt;
               &lt;/m0:uploadFileUsingMTOM&gt;
            &lt;/soapenv:Body&gt;
         &lt;/soapenv:Envelope&gt;
--MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177413845353217
Content-Type: image/gif
Content-Transfer-Encoding: binary
Content-ID:
         &lt;1.urn:uuid:78F94BC50B68D76FB41177413845003@apache.org&gt;22800GIF89a... &lt;&lt; binary content &gt;&gt;</div>
                <p>
                    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.
                </p>
                <p>
                    When the client executes successfully, it will upload a file containing the ASF
                    logo and receive a response which is savesd a temporary file.
                </p>
                <div class="consoleOutput">[java] Sending file : ./../../repository/conf/sample/resources/mtom/asf-logo.gif as MTOM
[java] Saved response to file : ./../../work/temp/sampleClient/mtom-4417.gif</div>

                <p>
                    Now invoke the client as follows to send a SwA optimized request.
                </p>
                <div class="command">ant optimizeclient -Dopt_mode=swa</div>
                <p>
                    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.
                </p>
                <div class="consoleOutput">[java] Sending file : ./../../repository/conf/sample/resources/mtom/asf-logo.gif as SwA
[java] Saved response to file : ./../../work/temp/sampleClient/swa-30391.gif</div>
                <p>
                    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.
                </p>

                <div class="consoleOutput">POST /services/MTOMSwASampleService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:uploadFileUsingSwA
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177414170491; type=&quot;text/xml&quot;;
start=&quot;&lt;0.urn:uuid:B94996494E1DD5F9B51177414170492@apache.org&gt;&quot;; 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:
   &lt;0.urn:uuid:B94996494E1DD5F9B51177414170492@apache.org&gt;22159
      &lt;?xml version='1.0' encoding='UTF-8'?&gt;
         &lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
            &lt;soapenv:Body&gt;
               &lt;m0:uploadFileUsingSwA xmlns:m0=&quot;http://www.apache-synapse.org/test&quot;&gt;
                  &lt;m0:request&gt;
                     &lt;m0:imageId&gt;urn:uuid:15FD2DA2584A32BF7C1177414169826&lt;/m0:imageId&gt;
                  &lt;/m0:request&gt;
               &lt;/m0:uploadFileUsingSwA&gt;
            &lt;/soapenv:Body&gt;
         &lt;/soapenv:Envelope&gt;22--34MIMEBoundaryurn_uuid_B94996494E1DD5F9B511774141704912
17
Content-Type: image/gif
Content-Transfer-Encoding: binary
Content-ID:
         &lt;urn:uuid:15FD2DA2584A32BF7C1177414169826&gt;22800GIF89a... &lt;&lt; binary content &gt;&gt;</div>
                
            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>        
    </body>
</document>