SOAP messages are not sent using wso2 ESB REST API - web-services

I'm trying to expose SOAP backend as REST API using wso2 ESB. I'm using payload factory to send the soap body message, but it doesn't work.
This is my API resource in wso2 esb code :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/akademik" name="SampleAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/students?symbol={symbol}">
<inSequence>
<log level="custom">
<property expression="$url:symbol" name="symbol"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:sem="http://semogabisa.te.net/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sem:sayHi>
<arg0>$1</arg0>
</sem:sayHi>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$url:symbol"/>
</args>
</payloadFactory>
<header scope="default">
<m:complexHeader xmlns:m="http://org.synapse.example">
<m:property key="Content-Type" value="application/xml"/>
</m:complexHeader>
</header>
<send>
<endpoint>
<address format="soap11" uri="http://localhost:8084/HelloWorld"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
Soap messages are not sent to the backend web service, it says null.
I've test the backend service with SOAPUI with same soap envelope format and it's working

I think you make some mistake on the header mediator. "HelloWorld" back end service didn't need the SOAP header based on your SOAP UI request. so remove the header mediator.
Select Synapse if you want to manipulate SOAP headers. Select Transport if you want to manipulate HTTP headers.
And it's seems back end is SOAP11, SOAP11 type is "text/xml". Your may need set this property.
<property name="messageType" value="text/xml" scope="axis2"/>
When you send message out from ESB, you need set property "messageType", then ESB will formatter the message that match back end required.
You may probably need this property, if you found ESB append some context to your back end URI when send message to back end.
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
Good Tips:
Please open your "synapse.transport.http.wire" as DEBUG, this will output every message in and out from ESB. This log will including HTTP header and body. After you got the wire log, you can compare wire log with your SOAPUI request, then find out which part is wrong.
https://docs.wso2.com/display/ESB481/Setting+Up+Logging

Related

WSO2 APIM - JSON to SOAP out sequence not works , return empty value between the SOAP parameter arguments

I tried the following codes in mediation in WSO2 server
Following code for insequence mediation
<sequence name="SOAPtoJSON" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom" separator=",">
<property name="TRACE" value="Global Mediation Extension"/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
The above insequence works fine and converts the input from SOAP to JSON and forward it to the endpoint.
The SOAP request given to the WSO2 Server via WSO2 Server API Console was,
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ecomreceipt">
<soapenv:Header/>
<soapenv:Body>
<validatepassbook xmlns="https://10.122.0.32:8243/gpp20038/1.0.0/">
<Mode>$1</Mode>
<Action>$2</Action>
<Attribute>$3</Attribute>
</validatepassbook>
</soapenv:Body>
And then, I logged the request from the WSO2 Server in the endpoint, log shows the following
{"validatepassbook":{"#encodingStyle":"http://schemas.xmlsoap.org/soap/encoding/","Mode":{"#type":"xsd:string","$":"zmzIf0CMfm5ta8lg5xc6Bj1tOEEljipbbrbX2Ph8XFxGyGl5T4vhzzmLIpNuSh6W"},"Action":{"#type":"xsd:string","$":"KGI1718SGS439-KGI14306-SGS3"},"Attribute":{"#type":"xsd:string","$":7904045393}}}
Following code for outsequence mediation
<sequence name="JSONtoSOAP" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="xml">
<format>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.cdyne.com/PhoneVerify/query">
<SOAP-ENV:Body>
<ns1:CheckPhoneNumbers>
<ns1:PhoneNumbers>
<ns1:string>$1</ns1:string>
</ns1:PhoneNumbers>
<ns1:LicenseKey>$2</ns1:LicenseKey>
</ns1:CheckPhoneNumbers>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</format>
<args>
<arg evaluator="xml" expression="//request/PhoneNumber"/>
<arg evaluator="xml" expression="//request/LicenseKey"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
And then, I logged the respond that to be sent to WSO2 Server in the endpoint, log shows the following
"{\"request\":{\"PhoneNumber\":\"18006785432\",\"LicenseKey\":\"0\"}}"
And then, I got the output in WSO2 Server API Console was,
Response Body
<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.cdyne.com/PhoneVerify/query"><SOAP-ENV:Body><ns1:CheckPhoneNumbers><ns1:PhoneNumbers><ns1:string/></ns1:PhoneNumbers><ns1:LicenseKey/></ns1:CheckPhoneNumbers></SOAP-ENV:Body></SOAP-ENV:Envelope>
The above response with empty values , but I expect like following reponse
<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.cdyne.com/PhoneVerify/query"><SOAP-ENV:Body><ns1:CheckPhoneNumbers><ns1:PhoneNumbers><ns1:string/>18006785432</ns1:PhoneNumbers><ns1:LicenseKey>0</ns1:LicenseKey></ns1:CheckPhoneNumbers></SOAP-ENV:Body></SOAP-ENV:Envelope>

ESB 4.8.1 with Data Service Hosting feature cannot use boxcarring

I run the following code in a WSO2 ESB 4.8.1 server with Data service Hosting feature 4.2.4 installed. I did some research on web, the normal response of "begin_boxcar" request should return a session cookie, however it doesn't. I also tried to send the same request to a standalone DSS 3.2.2 server. I did return a session cookie. Anyone can help?
<header name="Action" value="urn:begin_boxcar"></header>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<dat:begin_boxcar></dat:begin_boxcar>
</soapenv:Body>
</soapenv:Envelope>
</format>
</payloadFactory>
<call>
<endpoint key="GS1OrderDS"></endpoint>
</call>
<log level="full">
<property name="==============Set-Cookie===============" expression="get-property('transport','Set-Cookie')"></property>
</log>
You can get the Cookie value from
<property name="setCookieHeader" expression="$trp:Set-Cookie"/>
For the subsequent calls the Cookie can be set by
<property name="Cookie" expression="get-property('setCookieHeader')"
scope="transport"/>
Hope this helps!

Wso2 esb: Edit the response of one rest API and send that response to another rest api

We have 2 rest APIs and have to edit and send the one rest API response as a request message to the another rest API.
Ex: First api response is
<?xml version="1.0"?>
<api>
<attribute_set_id>4</attribute_set_id>
<type_id>simple</type_id>
<sku>test_dress</sku>
</api>
Now we have to edit that response as
<?xml version="1.0"?>
<api>
<id>4</id>
<product_id>simple</product_id>
<sku>test_dress</sku>
</api>
and send that response as a request message to the another rest api.
Is it possible through WSO2 ESB and please provide any sample to work for above scenario.
Please let me know if I need to give more details.
Thanks,
Geetha Gupta
Little sample you must customize to meet your needs :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="MyProxy"
transports="http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<!-- send current message to rest api 1 (sample with a dynamic value inside rest url) -->
<property name="uri.var.MyPath" value="mypath"/>
<call>
<endpoint>
<http method="POST" uri-template="http://myhost/{uri.var.MyPath}/restapi1"/>
</endpoint>
</call>
<!-- here come the response from rest api 1 : transform this response -->
<payloadFactory media-type="xml">
<format>
<api>
<id>$1</id>
<product_id>$2</product_id>
<sku>$3</sku>
</api>
</format>
<args>
<arg evaluator="xml" expression="//api/attribute_set_id/text()"/>
<arg evaluator="xml" expression="//api/type_id/text()"/>
<arg evaluator="xml" expression="//api/sku/text()"/>
</args>
</payloadFactory>
<!-- call rest api 2 -->
<call>
<endpoint>
<http method="POST" uri-template="http://myhost/{uri.var.MyPath}/restapi2"/>
</endpoint>
</call>
<!-- send back response from restapi2 -->
<send/>
</inSequence>
<outSequence/>
</target>
</proxy>
What you need is the XSLT mediator (https://docs.wso2.com/display/ESB460/XSLT+Mediator).
Refer http://architects.dzone.com/articles/xslt-mediator-tutorial for an example for this.
You can do it through following steps
Read response and assign the response parameters to some variables by using <proprty>
Set dynamic payload with these parameters by using <payloadFactory>
After you can call another rest using <send> mediator

WSO2 ESB - How to get and set cookies in WSDL calls in

I use WSO2 ESB and want to connect 2 web services together - on a timer pull data from one service and push it to another.
The problem is that one of the services authenticates callers with cookies. You first need to call a GetSession method with the username and password. The response to this call sets a cookie. Then with this cookie you make other calls.
I couldn't find anywhere in the documentation, how can I get a cookie from the result of one call and set it for a subsequent call. Is it at all achievable? If so - how?
Here is my sequence code:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="SampleName" trace="enable">
<payloadFactory media-type="xml">
<format>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetSessionWithCredentials xmlns="blabla">
<User>bla</User>
<Password>bla</Password>
</GetSessionWithCredentials>
</Body>
</Envelope>
</format>
</payloadFactory>
<call>
<endpoint key="conf:/Tracker"></endpoint>
</call>
<payloadFactory media-type="xml">
<format>
<GetTrackingList xmlns="blabla"></GetTrackingList>
</format>
</payloadFactory>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Cookie" expression="$trp:Cookie"></property>
<call>
<endpoint key="conf:/Tracker"></endpoint>
</call>
<log level="full"></log>
</sequence>
Thanks a lot
get Cookie header : <property name="Cookie" expression="$trp:Cookie"/>
If you want to get one cookie and it's value, use xpath expression with 'substring' for exemple
set cookie header with value JSESSIONID=1 : <property name="Cookie" value="JSESSIONID=1" scope="transport"/>

wso2 esb service endpoint in request

I am getting service endpoint as input SOAP request to WSO2 esb, based
on that need to send payload data to that endpoint and response to
client. Please advise how to send payload to that endpoint. I tried
Header mediator but no luck. Following is the SOAP XML request coming
to ESB which has service endpoint reference, under property element.
<soapenv:Envelope
xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body> <resources> <resource>
<properties>
<property name="location" value="http://localhost:8280/services/echo.echoHttpSoap11Endpoint"/>
</properties> </resource> </resources> </soapenv:Body> </soapenv:Envelope>
First retrieve the address value using the expression "//properties/property/#value". Then set the To address of the header mediator and send the message.
<property name="address" expression="//properties/property/#value"/>
<header name="To" expression="get-property('address')"/>
<payloadFactory>
<format>
<p:echoInt xmlns:p="http://echo.services.core.carbon.wso2.org">
<in xmlns="">$1</in>
</p:echoInt>
</format>
<args>
<arg value="1"/>
</args>
</payloadFactory>
<send/>