Search code examples
restsoapwsdlwso2wso2-esb

WSO2 REST to SOAP passing operation parameters


Using WSO2 ESB 4.8.1, I have configured a WSDL proxy that I want to access over REST. the proxy points to the SOAP WSDL URI and has publish WSDL turned on. This seem to work fine and I can see the service and its various operations in the WSO2 admin UI. Likewise if I go to localhost:8280/services/

The questions is how do I pass operation specific parameters when accessing over HTTP REST?

Let's say my FooService OperationX expects a "p1" parameter, can I pass this directly when accessing localhost:8280/services/FooService/OperationX in a browser?

I tried for example localhost:8280/services/FooService/SomeOperation?p1=somevalue, but always get a validation error that the required parameter is missing:

cvc-complex-type.2.4.b: The content of element 'axis2ns15:OperationXRequest' is not complete. One of '{"somenamespace":p1}' is expected.

Can this be supported by a basic WSDL proxy? Or do I need to use the API?


Solution

  • I think the better option for your scenario is to use api to access over REST. Here I have created an api (I used http://jsonplaceholder.typicode.com/comments as my REST back end) which gets the query parameter(postId) which was sent in REST request (http://172.22.99.96:8290/test/comments?postId=1) and assign that value to a property called mypostId inside the api. Then I am modifying the payload by adding the mypostId property using payload factory mediator which will match to the echo service request(I have used echo service as the SOAP backend). Then I use enrich mediator to change my soap envelope to match the echo service request soap envelope by adding "xmlns:echo="http://echo.services.core.carbon.wso2.org"" name space. Finally I am sending my created request to echo service proxy.

    <api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
       <resource methods="GET" uri-template="/comments?postId={postId}">
          <inSequence>
             <log level="custom">
                <property name="Message Flow" value="--- Order GET ---"></property>
             </log>
             <log level="custom">
                <property name="postId" expression="$url:postId"></property>
             </log>
             <property name="mypostId" expression="$url:postId"></property>
             <call>
                <endpoint>
                   <http method="GET" uri-template="http://jsonplaceholder.typicode.com/comments?postId={uri.var.postId}"></http>
                </endpoint>
             </call>
             <payloadFactory media-type="xml">
                <format>
                   <echo:echoInt xmlns:echo="http://echo.services.core.carbon.wso2.org">
                      <in>$1</in>
                   </echo:echoInt>
                </format>
                <args>
                   <arg evaluator="xml" expression="get-property('mypostId')"></arg>
                </args>
             </payloadFactory>
             <log level="full"></log>
             <log level="custom">
                <property name="Message Flow" value="--- After Palyload factory---"></property>
             </log>
             <property name="extarctedBody" expression="$body"></property>
             <log level="custom">
                <property name="MyextarctedBody" expression="get-property('extarctedBody')"></property>
             </log>
             <log level="full"></log>
             <enrich>
                <source type="inline" clone="true">
                   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org"></soapenv:Envelope>
                </source>
                <target type="envelope"></target>
             </enrich>
             <log level="custom">
                <property name="Message Flow" value="--- Order GET2 ---"></property>
             </log>
             <log level="full"></log>
             <enrich>
                <source type="property" clone="true" property="extarctedBody"></source>
                <target xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org" action="child" xpath="//soapenv:Envelope"></target>
             </enrich>
             <log level="full"></log>
             <send>
                <endpoint>
                   <address uri="http://localhost:8290/services/echo"></address>
                </endpoint>
             </send>
          </inSequence>
          <outSequence>
             <send></send>
          </outSequence>
       </resource>
    </api>
    

    Hope this may help you .