WSO2 API Manager convert SOAP to REST

浪尽此生 提交于 2020-01-02 07:48:46

问题


Is it possible to publish a SOAP service as a REST API directly in the API manager? Is it possible to convert the call and expose REST to end user while calling the SOAP?

If possible, how?
Thanks.


回答1:


This might be what you are looking for. This has can be done as mentioned below.

If you want to expose multiple operations using the same API in a RESTful manner you can modify the sequence in the post using the following guidelines.

1) Create a request URI to map to each operation in your backend SOAP service when designing the REST API in API Manager.

2) Using the filter mediator (which acts as a conditional statement in programming) you can filter out from the request URI(operation) and construct the required payload accordingly.

The below block would be repeated corresponding to your various operations mapping your backend web service.

The logic here would be if the request URI of the API is X route to operation Y of the SOAP service.

<!-- this filters out the operations of your API -->

<property expression="json-eval($.operation)" name="operation" />
<filter regex="menu" source="$ctx:operation">

   <header description="SOAPAction" name="SOAPAction" scope="transport" value="http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber"/>

<!-- We are storing the input values which the end users input for these values into properties -->

<property name="uri.var.phoneNumber" expression="$url:PhoneNumber"/>
<property name="uri.var.licenseKey" expression="$url:LicenseKey"/>

<!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it -->

<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>

<!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator -->

<payloadFactory description="transform" media-type="xml">
  <format>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://ws.cdyne.com/PhoneVerify/query">
  <soapenv:Header/>
  <soapenv:Body>
  <quer:CheckPhoneNumber>
    <quer:PhoneNumber>$1</quer:PhoneNumber>
    <quer:LicenseKey>$2</quer:LicenseKey>
  </quer:CheckPhoneNumber></soapenv:Body>
  </soapenv:Envelope>
  </format>
  <args>
    <arg expression="get-property(‘uri.var.phoneNumber’)"/>
    <arg expression="get-property(‘uri.var.licenseKey’)"/>
  </args>
</payloadFactory>

For further information on the above use case you can you can refer this post as reference on how such a custom extension sequence has been used to map a backend SOAP web service operations. With this you would be able to directly expose it as a REST API

Or you can simply create an SOAP based API in the WSO2 API Cloud or WSO2 API Manager and then pass the request payload along with the SOAP operation sent in the SOAP Action header so that you can call the different operations of your backend web service. You can see how this is used in the image below.

Managing WSDL operations using a single API

Hope this helps.

Regards.




回答2:


yes. You can refer this blog post as reference. please note that there may be some differences as this was written for API manager Alpha version. Yet it is a good entry point.



来源:https://stackoverflow.com/questions/14505070/wso2-api-manager-convert-soap-to-rest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!