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/>
Related
I'm send soap reqest to microservice and in respond I get this.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">SOAP-ENV:Client</faultcode>
<faultstring>An error was detected in the Web Service request. (10894)</faultstring>
<detail>
<ns1:FaultDetail xmlns:ns1="urn:soap-fault:details">
<errorMessage>Error in SOAP Envelope: Content length must be specified. (10913)</errorMessage>
<requestID>----</requestID>
</ns1:FaultDetail>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
I create my soap envelope in payloadFactory.
<payloadFactory description="Set ARGS for CALL" media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:xyz:zyz">
<soapenv:Header/>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
...
</args>
</payloadFactory>
Next I send this to microservice. Micro service work on SOAP 1.1. I'm don't attach content lenght because I do not know how.
After the PL factory and before sending the request try setting the following properties.
<property name="DISABLE_CHUNKING" value="true" scope="axis2" />
<property name="messageType" value="text/xml" scope="axis2" type="STRING"/>
I need to create Soap Operation GetFile to respond with file content and additional tags using MTOM (reponse Content-Type multipart/related):
<Response>
<file>
<id>1</id>
<name>Filename.pdf</name>
<content>
<xop:Include href="cid:test" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</content>
</file>
</Response>
I have proxy which calls external service to get file content and then I generate payload using PayloadFactory mediator ($body/* in this case is file binary content from external service, id and name are hardcoded for simplicity):
<payloadFactory media-type="xml">
<format>
<Response>
<file>
<id>$1</id>
<name>$2</name>
<content>$3</content>
</file>
</Response>
</format>
<args>
<arg value="1"/>
<arg value="fileName.pdf"/>
<arg evaluator="xml"
expression="$body/*"/>
</args>
</payloadFactory>
<property name="enableMTOM" scope="axis2" type="STRING" value="true"/>
<respond/>
In response I get:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Response xmlns="http://ws.apache.org/ns/synapse">
<file>
<id>1</id>
<name>fileName.pdf</name>
<content>base64content</content>
</file>
</Response>
</soapenv:Body>
</soapenv:Envelope>
If I remove that payloadFactory then I get correct multipart/related response, so enableMTOM property works (but I need additional custom tags):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">
<xop:Include href="cid:1" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</ns:binary>
</soapenv:Body>
</soapenv:Envelope>
Is custom mediator with messageContext.addAttachment only solution in this case? And whats best practice in such case - save received file content locally on server and then use it as attachment?
If you are constructing the message payload using a Payload factory mediator, and expecting to send the response as "multipart/form-data", you need to set the message type of the response after the Payload factory mediator. You can use the following property to set the message type of the response.
<property name="messageType" value="multipart/form-data" scope="axis2"/>
Furthermore, when we manipulate the file content using the Payload factory mediator, the message context gets built inside the Payload factory mediator and returned as a base64 encoded value. In order to decode the content, you need to add the following property to your proxy configuration.
<property name="DECODE_MULTIPART_DATA" value="true" scope="axis2" action="set" type="BOOLEAN"/>
Please refer to the latest WSO2 documentation on MTOM and SwA Optimizations and Request/Response Correlation for more details on this.
In a content-aware mediation scenario (where the message gets built), you can use the following property to decode the multipart message that is being sent to the backend. Otherwise, the outgoing message will be in encoded form.
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>
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
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!