WSO2 API Manager convert SOAP to REST - rest

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.

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.

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.

Related

Get POST request data from filter in Enonic

Are there any ways to use one method for all post requests instead of having controllers for each post request? Can we use HTTP filters in Enonic to support POST requests? They support GET requests by default.
Yes, you can use "Mappings" in the Site descriptor to intercept e.g. a path.
<site>
<mappings>
<mapping controller="/site/foobar/api.js" order="10">
<pattern>/api/v\d+/.*</pattern>
</mapping>
</mappings>
</site>

Need configuration data for Mirth Web Service Sender

First time using Mirth. We will be communicating with an outside service. Part of the SOAP Envelope in the SOAP message is userId and passWord. In addition to that we need to basically perform a hash that creates a unique token each time we call the service. I need that part of the XML payload to come from a function. Is there a way for a piece of the data to be inserted into the SOAP Envelope that is the result of a JavaScript function call?
First of all you need to use the Web Service Sender Connector Type. In this example I have chosen an online weather web service.
Paste the WSLD URL (orange) and click the "Get Operations" button (red)
After selecting the correct service, click the "Generate Envelope" button (red) which will make a soap stub for you. Something like this, where you can use variables like this ${variableName}
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
<soapenv:Header/>
<soapenv:Body>
<web:GetCitiesByCountry>
<!--Optional:-->
<web:CountryName>${myGeneratedCountryName}</web:CountryName>
</web:GetCitiesByCountry>
</soapenv:Body>
</soapenv:Envelope>
For the variable to be populated with your calculated value you need to use, for instance, a javascript transformer.
Create a new Destination and edit the tranformer.
And then you can use javascript to calculate your value.
Last line is used to make the variable and its content available for the Web Service Sender. It works like a java Map
$co('myGeneratedCountryName',country);
However there are other methods, code templates for instance. If you are new to Mirth Connect I recommend you reading the Mirth Connect User Guide which covers this use case and many others.

How do I receive this code in php? And how do I consume it?

I'm working on a website project to consume a web service, how do I receive this in php and how do I consume it? Thank you for helping out. I need to connect to their API, send the XML file genrerated in my website and then receive the response. http://www.safaricom.co.ke/business/corporate/m-pesa-payments-services/m-pesa-api for the api
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:c2b="http://cps.huawei.com/cpsinterface/c2bpayment">
<soapenv:Header/>
<soapenv:Body>
<c2b:C2BPaymentConfirmationRequest>
<TransactionType>PayBill</TransactionType>
<TransID>1234560000007031</TransID>
<TransTime>20140227082020</TransTime>
<TransAmount>123.00</TransAmount>
<BusinessShortCode>12345</BusinessShortCode>
<BillRefNumber>TX1001</BillRefNumber>
<InvoiceNumber></InvoiceNumber>
<OrgAccountBalance>12345.00</OrgAccountBalance>
<ThirdPartyTransID></ThirdPartyTransID>
<MSISDN>254722703614</MSISDN>
<KYCInfo>
<KYCName>[Personal Details][First Name]</KYCName>
<KYCValue>Hoiyor</KYCValue>
</KYCInfo>
<KYCInfo>
<KYCName>[Personal Details][Middle Name]</KYCName>
<KYCValue>G</KYCValue>
</KYCInfo>
<KYCInfo>
<KYCName>[Personal Details][Last Name]</KYCName>
<KYCValue>Chen</KYCValue>
</KYCInfo>
</c2b:C2BPaymentConfirmationRequest>
</soapenv:Body>
</soapenv:Envelope>
My best advice is to use a WSDL to php generator such as PackageGenerator as you'll only deal with object to send the request then only deal with object when getting back the response. Using the generated SDK really eases consuming any SOAP Web Service. It uses the native SoapClient class (which is the first real starting point in this case if you wish to understand deeply the process).
Safaricom has released M-Pesa APIs as RESTful APIs accessible through their developer portal . You need not use the M-Pesa SOAP APIs.

salesforce soap api in soapui

I am trying to consume my service class of salsforce SOAP API in SOAPUI.
Getting the error
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>'false' is not a valid value for the enum 'LogCategory'</faultstring>
</soapenv:Fault>
What should be specific value in
<pay:categories>
<pay:category>false</pay:category>
<pay:level></pay:level>
</pay:categories>
<pay:debugLevel></pay:debugLevel>
from this page it looks like pay:category has to be one of
Db
Workflow
Validation
Callout
Apex_code
Apex_profiling
All

CXF Restful web service with generic payload

Is there a way in CXF to implement a Restful webservice which will accept different xml requests using one Web service method?
e.g. Can one create a Restful endpoint to accept this type of XML through one web service method?
<Data>
<Book>BN1</Book>
</Data>
& this too using same web service method?
<Data>
<Disk>DN1</Disk>
</Data>
I think this post: Apache CXF: Consume XML POST payload... shows a good example of how to declare a CXF REST service as receiving POST XML data.
For your example of handling different XML content, instead of 'Bean' in the above you'd have an #XmlRootElement that's the Data, with a child that's a #XmlAnyElement.
Ok so I am using this for generic XML.
public interface Callback {
#POST
#Path("/submit")
#Consumes("text/xml")
#Produces("application/xml")
public Response submit(String incomingXML);
}
Basically I am getting whole xml as a string in my method body, As CXF is not parsing it, it can remain generic.