title: multipart/form-data with WSO2 ESB
body: <p>I need to pass photo and access token to back end REST service. Content type</p>
  
  <p>is multipart/form-data I created html form and action is endpoint of esb And I have traced the traffic on the way to ESB [A] and going out from ESB [B]. It seems slide changes on those and I have no idea to fix this. When I send captured traffic on the way to ESB [A] its accepting by back end service. But traffic which going out by ESB[B] is not accepting by back end. Means not recognized the values in boundaries. It says “values empty”</p>
  
  <p>Output on the way to ESB – when this FWD to backend it recognize ==========================================================================</p>
  
  <p>POST /services/postPhotoToAlbumHttpSoap11Endpoint HTTP/1.1</p>
  
  <p>Host: localhost:8280</p>
  
  <p>Connection: keep-alive</p>
  
  <p>Content-Length: 4623</p>
  
  <p>Cache-Control: max-age=0</p>
  
  <p>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,<em>/</em>;q=0.8</p>
  
  <p>Origin: null</p>
  
  <p>User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36</p>
  
  <p>Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryPSfmjvLcmpwvN6Gt</p>
  
  <p>Accept-Encoding: gzip,deflate,sdch</p>
  
  <p>Accept-Language: en-US,en;q=0.8</p>
  
  <p>Cookie: menuPanel=visible; menuPanelType=main</p>
  
  <p>X-Forwarded-For: 0:0:0:0:0:0:0:1</p>
  
  <p>------WebKitFormBoundaryPSfmjvLcmpwvN6Gt</p>
  
  <p>Content-Disposition: form-data; name="accessToken"</p>
  
  <p>CAACEdEose0cBALXnbsnFzenjs7ni1bkLYx0Tybmfd4G5CBWifG3VnP9xWQDNT52mCWZA2dTESXYc4aMNOZAHfNUNO0jxV5IZC9PQzjeWBZCHuOOexnzpt5BmNCeZAAFb3juHU2aZAZCNLozkOYcyKUj1IOl2jYzCpTjLdnynqhsDrZCknPC9670N0bOw1cIVUohLh9OBEjqyogZDZD</p>
  
  <p>------WebKitFormBoundaryPSfmjvLcmpwvN6Gt</p>
  
  <p>Content-Disposition: form-data; name="source"; filename="kdinesh_LThumb.jpg"</p>
  
  <p>Content-Type: image/jpeg</p>
  
  <p>ÿØÿà_</p>
  
  <p>Output going OUT from ESB ==========================================================================</p>
  
  <p>POST /10150897830516344/photos HTTP/1.1</p>
  
  <p>Accept-Language: en-US,en;q=0.8</p>
  
  <p>Cookie: menuPanel=visible; menuPanelType=main</p>
  
  <p>Accept-Encoding: gzip,deflate,sdch</p>
  
  <p>X-Forwarded-For: 0:0:0:0:0:0:0:1</p>
  
  <p>Origin: null</p>
  
  <p>Content-Type: multipart/form-data</p>
  
  <p>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,<em>/</em>;q=0.8</p>
  
  <p>Cache-Control: max-age=0</p>
  
  <p>Transfer-Encoding: chunked</p>
  
  <p>Host: api.localhost</p>
  
  <p>Connection: Keep-Alive</p>
  
  <p>User-Agent: Synapse-PT-HttpComponents-NIO</p>
  
  <p>X-Forwarded-For: 0:0:0:0:0:0:0:1, 127.0.0.1</p>
  
  <p>1816</p>
  
  <p>--MIMEBoundary_960dd4bb3066b1fff153bc3151e7776b65947ba8dd00425e</p>
  
  <p>Content-Disposition: form-data; name="access_token"</p>
  
  <p>Content-Type: text/plain; charset=US-ASCII</p>
  
  <p>Content-Transfer-Encoding: 8bit</p>
  
  <p>CAACEdEose0cBALXnbsnFzenjs7ni1bkLYx0Tybmfd4G5CBWifG3VnP9xWQDNT52mCWZA2dTESXYc4aMNOZAHfNUNO0jxV5IZC9PQzjeWBZCHuOOexnzpt5BmNCeZAAFb3juHU2aZAZCNLozkOYcyKUj1IOl2jYzCpTjLdnynqhsDrZCknPC9670N0bOw1cIVUohLh9OBEjqyogZDZD</p>
  
  <p>--MIMEBoundary_960dd4bb3066b1fff153bc3151e7776b65947ba8dd00425e</p>
  
  <p>Content-Disposition: form-data; name="source"</p>
  
  <p>Content-Type: text/plain; charset=US-ASCII</p>
  
  <p>Content-Transfer-Encoding: 8bit</p>
  
  <p>/9j/4AAQSkZJRgABAgEAAAAAAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8KCwkMEQ8SEhEPERATFhwXExQaFRARGCEYGhwdHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCABvAG8DASIAAhE --MIMEBoundary_960dd4bb3066b1fff153bc3151e7776b65947ba8dd00425e--</p>
  
  <p>0</p>
  
  <h1>Proxy</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;proxy xmlns="http://ws.apache.org/ns/synapse" name="postPhoto"
  
         transports="https,http" statistics="disable" trace="disable"
  
         startOnLoad="true"&gt;
  
         &lt;target&gt;
  
  
  
                &lt;inSequence&gt;
  
                       &lt;property name="accessToken" expression="//accessToken/text()" /&gt;
  
                       &lt;property name="source" expression="//source/text()" /&gt;
  
  
  
  
  
                       &lt;conn.init&gt;
  
                             &lt;accessToken&gt;{$ctx:accessToken}&lt;/accessToken&gt;
  
                       &lt;/conn.init&gt;
  
  
  
                       &lt;conn.postPhotoToAlbum&gt;
  
                             &lt;source&gt;{$ctx:source}&lt;/source&gt;
  
                       &lt;/conn.postPhotoToAlbum&gt;
  
                       &lt;respond&gt;&lt;/respond&gt;
  
                &lt;/inSequence&gt;
  
                &lt;outSequence&gt;
  
                       &lt;log&gt;&lt;/log&gt;
  
                       &lt;send&gt;&lt;/send&gt;
  
                &lt;/outSequence&gt;
  
         &lt;/target&gt;
  
  &lt;/proxy&gt;
  </code></pre>
  
  <p>Template
   ==========================================================================</p>
  
  <p></p>
  
  <pre><code>   &lt;parameter name="source" description="The source" /&gt;
  
  
  
     &lt;sequence&gt;
  
  
  
            &lt;property name="enableMTOM" value="true" scope="axis2" /&gt;
  
            &lt;header name="Content-Type" value="multipart/form-data" scope="transport" action="add" /&gt;
  
            &lt;property name="preserveProcessedHeaders" value="true" scope="default"/&gt;
  
  
  
            &lt;property name="uri.var.source" expression="$func:source" /&gt;
  
  
  
            &lt;payloadFactory media-type="xml"&gt;
  
                   &lt;format&gt;
  
                         &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  
                                &lt;soapenv:Header&gt;&lt;/soapenv:Header&gt;
  
                                &lt;soapenv:Body&gt;
  
                                       &lt;root&gt;
  
                                              &lt;access_token&gt;$1&lt;/access_token&gt;
  
                                              &lt;source&gt;$2&lt;/source&gt;
  
                                       &lt;/root&gt;
  
  
  
                                &lt;/soapenv:Body&gt;
  
                         &lt;/soapenv:Envelope&gt;
  
                   &lt;/format&gt;
  
                   &lt;args&gt;
  
                         &lt;arg expression="get-property('uri.var.accessToken')" /&gt;
  
                         &lt;arg expression="get-property('uri.var.source')" /&gt;
  
                   &lt;/args&gt;
  
            &lt;/payloadFactory&gt;
  
            &lt;call&gt;
  
                   &lt;endpoint&gt;
  
                         &lt;http method="post" uri-template="http://localhost:8888/photos" /&gt;
  
                   &lt;/endpoint&gt;
  
            &lt;/call&gt;
  
     &lt;/sequence&gt;
  </code></pre>
  
  <p></p>
  
  <h1> front end</h1>
  
  <pre><code>&lt;html&gt; 
  
    &lt;head&gt;&lt;title&gt;multipart/form-data - Client&lt;/title&gt;&lt;/head&gt; 
  
    &lt;body&gt;  
  
   &lt;form action="http:/localhost:7777/services/postPhotoToAlbumHttpSoap11Endpoint" method="POST" enctype="multipart/form-data"&gt; 
  
    url: &lt;input type="text" name="accessToken" value=""&gt;&lt;br/&gt;  
  
   Profile pic :  
  
   &lt;input type="file" name="source" size="40" multiple&gt; 
  
   &lt;/p&gt; 
  
    &lt;input type="submit" value="Submit"&gt; 
  
    &lt;/form&gt; 
  
    &lt;/body&gt; 
  
   &lt;/html&gt;  
  </code></pre>
  
  <p>===========================================
  seems it is missing boundary when in leaving from ESB.. it that the problem?</p>
  
  <p>Content-Type: multipart/form-data;</p>
  
  <h1>boundary=----WebKitFormBoundaryPSfmjvLcmpwvN6Gt</h1>
  
  <p>Pls find the behaviors of output based on axis to relay configuration</p>
  
  <p><strong>INPUT to ESB</strong></p>
  
  <p>POST /services/postPhotoToAlbumHttpSoap11Endpoint HTTP/1.1</p>
  
  <p>Accept-Encoding: gzip,deflate</p>
  
  <p>Content-Type: text/xml;charset=UTF-8</p>
  
  <p>SOAPAction: "urn:mediate"</p>
  
  <p>Content-Length: 488</p>
  
  <p>Host: localhost:8280</p>
  
  <p>Connection: Keep-Alive</p>
  
  <p>User-Agent: Apache-HttpClient/4.1.1 (java 1.5)</p>
  
  <p>X-Forwarded-For: 127.0.0.1</p>
  
  
  
  <p></p>
  
  <p></p>
  
  <p></p>
  
  <p></p>
  
  <pre><code>&lt;accessToken&gt;CAACEdEose0cBAMotx64LhZBfX7VXAgdt1zsHJCnwJRewdi55clZBUIb6FdRdBKoU4INqXPI5NekgGkPEf5FwIk3ASIZBqmJQPkomlOZAxvj2tusLPl57tUk1RZBGvNq8iQmWKuoW1KsUerxhI4vA1Nol5DvQj4oVLqVO6hwTaC9rArNSWIbr99DZApGxIA5YGxFGi8E0JotgZDZD&lt;/accessToken&gt;
  
  &lt;source&gt;&lt;/source&gt;
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <p></p>
  
  <p><strong>output from ESB
  BinaryRelayBuilder&lt;->ExpandingMessageFormatter</strong></p>
  
  <p>POST /10150897830516344/photos HTTP/1.1</p>
  
  <p>Accept-Encoding: gzip,deflate</p>
  
  <p>X-Forwarded-For: 127.0.0.1</p>
  
  <p>Content-Type: multipart/form-data</p>
  
  <p>SOAPAction: "urn:mediate"</p>
  
  <p>Transfer-Encoding: chunked</p>
  
  <p>Host: a.b.com:443</p>
  
  <p>Connection: Keep-Alive</p>
  
  <p>User-Agent: Synapse-PT-HttpComponents-NIO</p>
  
  <p>X-Forwarded-For: 127.0.0.1, 127.0.0.1</p>
  
  <p>201</p>
  
  <p>CAACEdEose0cBAMotx64LhZBfX7VXAgdt1zsHJCnwJRewdi55clZBUIb6FdRdBKoU4INqXPI5NekgGkPEf5FwIk3ASIZBqmJQPkomlOZAxvj2tusLPl57tUk1RZBGvNq8iQmWKuoW1KsUerxhI4vA1Nol5DvQj4oVLqVO6hwTaC9rArNSWIbr99DZApGxIA5YGxFGi8E0JotgZDZD</p>
  
  <p>0</p>
  
  <p><strong>BinaryRelayBuilder&lt;-> MultipartFormDataFormatter</strong></p>
  
  <p>
  
  <pre><code>                    class="org.wso2.carbon.relay."/&gt;
  </code></pre>
  
  <p>
  
  <pre><code>                      class="org.apache.axis2.transport.http."/&gt;
  </code></pre>
  
  <p>fromESB</p>
  
  <p>--MIMEBoundary_4005c93d90f5f09d8bd30c0691e5b1ddf2192b5c862bdf91</p>
  
  <p>Content-Disposition: form-data; name="access_token"</p>
  
  <p>Content-Type: text/plain; charset=US-ASCII</p>
  
  <p>Content-Transfer-Encoding: 8bit</p>
  
  <p>CAACEdEose0cBAMotx64LhZBfX7VXAgdt1zsHJCnwJRewdi55clZBUIb6FdRdBKoU4INqXPI5NekgGkPEf5FwIk3ASIZBqmJQPkomlOZAxvj2tusLPl57tUk1RZBGvNq8iQmWKuoW1KsUerxhI4vA1Nol5DvQj4oVLqVO6hwTaC9rArNSWIbr99DZApGxIA5YGxFGi8E0JotgZDZD</p>
  
  <p>--MIMEBoundary_4005c93d90f5f09d8bd30c0691e5b1ddf2192b5c862bdf91</p>
  
  <p>Content-Disposition: form-data; name="source"</p>
  
  <p>Content-Type: text/plain; charset=US-ASCII</p>
  
  <p>Content-Transfer-Encoding: 8bit</p>
  
  <p>--MIMEBoundary_4005c93d90f5f09d8bd30c0691e5b1ddf2192b5c862bdf91--</p>
  
  <p><strong>MultipartFormDataBuilder&lt;-> ExpandingMessageFormatter</strong></p>
  
  <p>POST /10150897830516344/photos HTTP/1.1</p>
  
  <p>Accept-Encoding: gzip,deflate</p>
  
  <p>X-Forwarded-For: 127.0.0.1</p>
  
  <p>Content-Type: multipart/form-data</p>
  
  <p>SOAPAction: "urn:mediate"</p>
  
  <p>Transfer-Encoding: chunked</p>
  
  <p>Host: a.b.com:443</p>
  
  <p>Connection: Keep-Alive</p>
  
  <p>User-Agent: Synapse-PT-HttpComponents-NIO</p>
  
  <p>X-Forwarded-For: 127.0.0.1, 127.0.0.1</p>
  
  <p>201</p>
  
  <p>CAACEdEose0cBAMotx64LhZBfX7VXAgdt1zsHJCnwJRewdi55clZBUIb6FdRdBKoU4INqXPI5NekgGkPEf5FwIk3ASIZBqmJQPkomlOZAxvj2tusLPl57tUk1RZBGvNq8iQmWKuoW1KsUerxhI4vA1Nol5DvQj4oVLqVO6hwTaC9rArNSWIbr99DZApGxIA5YGxFGi8E0JotgZDZD</p>
  
  <p>0</p>
  
  <p><strong>MultipartFormDataBuilder &lt;-> MultipartFormDataFormatter</strong></p>
  
  <p>POST /10150897830516344/photos HTTP/1.1</p>
  
  <p>Accept-Encoding: gzip,deflate</p>
  
  <p>X-Forwarded-For: 127.0.0.1</p>
  
  <p>Content-Type: multipart/form-data</p>
  
  <p>SOAPAction: urn:mediate</p>
  
  <p>Transfer-Encoding: chunked</p>
  
  <p>Host: a.b.com:443</p>
  
  <p>Connection: Keep-Alive</p>
  
  <p>User-Agent: Synapse-PT-HttpComponents-NIO</p>
  
  <p>X-Forwarded-For: 127.0.0.1, 127.0.0.1</p>
  
  <p>29c</p>
  
  <p>--MIMEBoundary_588b3db44ce49dd52107589eea5fdcdc3d9a943eeeadcc5a</p>
  
  <p>Content-Disposition: form-data; name="access_token"</p>
  
  <p>Content-Type: text/plain; charset=US-ASCII</p>
  
  <p>Content-Transfer-Encoding: 8bit</p>
  
  <p>CAACEdEose0cBAMotx64LhZBfX7VXAgdt1zsHJCnwJRewdi55clZBUIb6FdRdBKoU4INqXPI5NekgGkPEf5FwIk3ASIZBqmJQPkomlOZAxvj2tusLPl57tUk1RZBGvNq8iQmWKuoW1KsUerxhI4vA1Nol5DvQj4oVLqVO6hwTaC9rArNSWIbr99DZApGxIA5YGxFGi8E0JotgZDZD</p>
  
  <p>--MIMEBoundary_588b3db44ce49dd52107589eea5fdcdc3d9a943eeeadcc5a</p>
  
  <p>Content-Disposition: form-data; name="source"</p>
  
  <p>Content-Type: text/plain; charset=US-ASCII</p>
  
  <p>Content-Transfer-Encoding: 8bit</p>
  
  <p>--MIMEBoundary_588b3db44ce49dd52107589eea5fdcdc3d9a943eeeadcc5a--</p>
  
  <p>0</p>