4

I have a soap service that I want to turn around and post a message to an external server.

I was able to do this via curl like so:

curl  --data-urlencode "filename=data.txt" --data-urlencode "filedir=/home/myfile/in" 
      --data-urlencode "busproc=MyBP" --data-urlencode "serverip=192.168.1.4" 
      --data-urlencode"uid=myuserid" --data-urlencode "pwd=mypwd"
      http://somelocation.com:8833/webservice/inbound/here

But I can't quite get it working correctly. Here's my proxy service:

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="ExampleHTTPPostWithFormData"
       transports="http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log/>
         <property name="messageType"
                   value="application/x-www-form-urlencoded"
                   scope="axis2"
                   type="STRING"/>
         <property name="HTTP_METHOD" value="post" scope="axis2" type="STRING"/>
         <send>
            <endpoint>
               <address uri="http://somelocation.com:8833/webservice/inbound/here"
                        format="pox"/>
               <property name="uid" value="user"/>
               <property name="pwd" value="password"/>
               <property name="filedir" value="/home/myfile/in"/>
               <property name="busproc" value="myBP"/>
               <property name="serverip" value="192.168.1.4"/>
               <property name="filename" value="data.txt"/>
            </endpoint>
         </send>
         <log level="full"/>
      </inSequence>
   </target>
   <description/>
</proxy>

The end service seems to only see me posting to the URL (but not the passed in data properties).

user2836244
  • 43
  • 1
  • 4

2 Answers2

3

Properties are not the way to build the message content. The best way I've found to do it is with a payloadFactory. The message you need to build has a root XML element with one child per form field, and then it seems that Axis2 handles the messageType of application/x-www-form-urlencoded by serialising in the appropriate format. So a minimal change to your proxy would be:

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="ExampleHTTPPostWithFormData"
       transports="http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log/>
         <property name="messageType"
                   value="application/x-www-form-urlencoded"
                   scope="axis2"
                   type="STRING"/>
         <payloadFactory media-type="xml">
           <format>
             <params xmlns="">
               <uid>user</uid>
               <pwd>password</pwd>
               <filedir>/home/myfile/in</filedir>
               <busproc>myBP</busproc>
               <serverip>192.168.1.4</serverip>
               <filename>data.txt</filename>
             </params>
           </format>
         </payloadFactory>
         <send>
            <endpoint>
               <address uri="http://somelocation.com:8833/webservice/inbound/here"
                        format="rest"/>
            </endpoint>
         </send>
         <log level="full"/>
      </inSequence>
   </target>
   <description/>
</proxy>

It may also be convenient to add <property name="FORCE_HTTP_1.0" value="true" scope="axis2" type="STRING"/> depending on whether your REST service handles HTTP/1.1.

If you need parameters then you can pass in arguments to the payloadFactory, using the XPath extensions. E.g.

         <payloadFactory media-type="xml">
           <format>
             <params xmlns="">
               <uid>user</uid>
               <pwd>password</pwd>
               <filedir>/home/myfile/in</filedir>
               <busproc>myBP</busproc>
               <serverip>192.168.1.4</serverip>
               <filename>$1</filename>
             </params>
           </format>
           <args>
             <arg evaluator="xml" expression="$ctx:filename"/>
           </args>
         </payloadFactory>
Peter Taylor
  • 4,918
  • 1
  • 34
  • 59
0

If your sending the SOAP payload in a file you would need to use the VFS transport. Please refer to the following sample on how to use the VFS transport to solve your issue

http://docs.wso2.org/pages/viewpage.action?pageId=26838852

Alternatively you can use SOAPUI or any SOAP client to send the payload directly to the ESB proxy endpoint

Nadeesha
  • 825
  • 2
  • 9
  • 12
  • why would I use VFS to post to a website? While the above has file information in it, that's not the goal. The goal is to do a HTTP post with form data. – user2836244 Oct 07 '13 at 13:13