简体   繁体   English

WSO2 REST到SOAP传递操作参数

[英]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. 使用WSO2 ESB 4.8.1,我已经配置了要通过REST访问的WSDL代理。 the proxy points to the SOAP WSDL URI and has publish WSDL turned on. 代理指向SOAP WSDL URI,并已打开WSDL。 This seem to work fine and I can see the service and its various operations in the WSO2 admin UI. 这似乎工作正常,我可以在WSO2管理员UI中看到该服务及其各种操作。 Likewise if I go to localhost:8280/services/ 同样,如果我转到localhost:8280 / services /

The questions is how do I pass operation specific parameters when accessing over HTTP REST? 问题是在通过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? 假设我的FooService OperationX需要一个“ p1”参数,在浏览器中访问localhost:8280 / services / FooService / OperationX时可以直接传递该参数吗?

I tried for example localhost:8280/services/FooService/SomeOperation?p1=somevalue, but always get a validation error that the required parameter is missing: 我尝试例如localhost:8280 / services / FooService / SomeOperation?p1 = somevalue,但始终会收到验证错误,该错误缺少必需的参数:

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? 基本的WSDL代理可以支持吗? Or do I need to use the API? 还是我需要使用API​​?

I think the better option for your scenario is to use api to access over REST. 我认为针对您的方案的更好选择是使用api通过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. 在这里,我创建了一个api(我使用http://jsonplaceholder.typicode.com/comments作为我的REST后端),该API获取了在REST请求中发送的查询参数(postId)( http://172.22.99.96:8290 / test / comments?postId = 1 ),然后将该值分配给api中名为mypostId的属性。 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). 然后,我通过使用有效负载工厂中介程序添加mypostId属性来修改有效负载,该属性将与回显服务请求匹配(我已将回显服务用作SOAP后端)。 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. 然后,通过添加“ xmlns:echo =“ http://echo.services.core.carbon.wso2.org””命名空间,我使用丰富的介体来更改我的肥皂信封以匹配回显服务请求肥皂信封。 Finally I am sending my created request to echo service proxy. 最后,我将创建的请求发送给echo服务代理。

<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 . 希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM