Reputation: 321
When i am sending json to wso2 proxy service which converts incoming request to xml using Payload Mediator. it gives me below error :
{
"Envelope": {
"Body": {
"Fault": {
"faultcode": "S:Client",
"faultstring": "Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {http://fcubs.ofss.com/service/FCUBSCcyService}RATESMASTERQUERY_IOFS_REQ"
}
}
}
}
it is my sending Request :
{
"Parameter": {
"brncode": "CHO",
"ccy1": "USD",
"ccy2": "MNT"
}
}
It is my proxy service code : Receiving Json and sending XML to endpoint
<inSequence>
<log category="DEBUG" level="full" separator="
">
<property name="Request" value="=============Request============"/>
<property expression="json-eval($)" name="Request"/>
</log>
it is Payload Mediator that converting Json to XML that will be sent to endpoint
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://fcubs.ofss.com/service/FCUBSCcyService">
<soapenv:Body>
<RATESMASTERQUERY_IOFS_REQ>
<FCUBS_HEADER>
<SOURCE>$1</SOURCE>
<UBSCOMP>$2</UBSCOMP>
<USERID>$3</USERID>
<BRANCH>$4</BRANCH>
<SERVICE>FCUBSCcyService</SERVICE>
<OPERATION>$5</OPERATION>
</FCUBS_HEADER>
<FCUBS_BODY>
<Rates-Master-IO>
<BRNCODE>$4</BRNCODE>
<CCY1>$6</CCY1>
<CCY2>$7</CCY2>
</Rates-Master-IO>
</FCUBS_BODY>
</RATESMASTERQUERY_IOFS_REQ>
</soapenv:Body>
</soapenv:Envelope>
</format>
enter code here
<args>
<arg evaluator="xml" expression="$trp:Source"/>
<arg value="FCUBS"/>
<arg evaluator="xml" expression="$trp:userid"/>
<arg evaluator="xml" expression="ctx:brncode"/>
<arg evaluator="xml" expression="$trp:function"/>
<arg evaluator="xml" expression="ctx:ccy1"/>
<arg evaluator="xml" expression="ctx:ccy2"/>
</args>
</payloadFactory>
<header name="Accept" scope="transport" value="text/xml"/>
<property name="messageType" scope="axis2" value="text/xml"/>
</inSequence>
OutSequence :
<outSequence>
<log category="DEBUG" separator="
">
<property name="Response" value="=============Response============"/>
<property expression="json-eval($)" name="Response"/>
</log>
<property name="messageType" scope="axis2" value="application/json"/>
<send/>
</outSequence>
How to work it properly ? Thanks
Upvotes: 0
Views: 1339
Reputation: 106
Other than small mistake, your configurations looks fine
Mistake 01 : ctx should be changed as $ctx
Mistake 02 : If you exposing REST API you should create an REST API [1] not a proxy. Proxy services are to expose SOAP services in WSO2 EI.
Following is working sample for your requirement:
<api xmlns="http://ws.apache.org/ns/synapse" name="API_Name" context="/APIBasePath" version="1.0.0" version-type="context">
<resource methods="POST" url-mapping="/samplePath">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://fcubs.ofss.com/service/FCUBSCcyService">
<soapenv:Body>
<RATESMASTERQUERY_IOFS_REQ>
<FCUBS_HEADER>
<SOURCE>$1</SOURCE>
<UBSCOMP>$2</UBSCOMP>
<USERID>$3</USERID>
<BRANCH>$4</BRANCH>
<SERVICE>FCUBSCcyService</SERVICE>
<OPERATION>$5</OPERATION>
</FCUBS_HEADER>
<FCUBS_BODY>
<Rates-Master-IO>
<BRNCODE>$4</BRNCODE>
<CCY1>$6</CCY1>
<CCY2>$7</CCY2>
</Rates-Master-IO>
</FCUBS_BODY>
</RATESMASTERQUERY_IOFS_REQ>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$trp:Source"/>
<arg value="FCUBS"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$trp:userid"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$ctx:brncode"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$trp:function"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$ctx:ccy1"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$ctx:ccy2"/>
</args>
</payloadFactory>
<property name="messageType" value="text/xml" scope="axis2"/>
<log level="full"/>
<send>
<endpoint>
<address uri="http://www.mocky.io/v2/5185415ba171ea3a00704eed" format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<respond/>
</outSequence>
</resource>
</api>
[1] https://docs.wso2.com/display/EI650/Working+with+APIs
Upvotes: 2
Reputation: 653
payloadFactory
operates on the soap:Body
, so you should not create a soap:Envelope
and soap:Body
inside the payloadFactory. Just set both Content-Type
and messageType
to 'text/xml', create the request using payloadFactory and send.
Upvotes: 0