How to set encoding of SOAP request in WSO2 ESB 4.9 - soap

I'm unable to set encoding of the request in WSO2ESB. I tried different methods:
Using encoding attribute of the address endpoint, but this attribute is ignored.
<address uri="http://we-pr-07:8080/mpi-service/service/" format="soap12" encoding="UTF-8"/>
By setting messageType and CHARACTER_SET_ENCODING, but these properties seems not working in version 4.9.
<property name="messageType" value="application/soap+xml;charset=UTF-8" scope="axis2" type="STRING"/>
<property name="CHARACTER_SET_ENCODING" value="UTF-8" scope="axis2" type="STRING"/>
What is proper way to set encoding? Is there way to set UTF-8 as default encoding?

I'm not totally sure but does not an XML declaration specify the XML version and the character encoding of the XML message.
that being the case try:
WSO2 XML Declaration

Related

How to create a Rest API from SOAP Backend with WSO2 API Manager

I am new working with wso2 api manager, and I need to pause a SOAP service and take it to a REST API, I have seen all the documentation, but none responds to my problem, I already created an input sequence
getProdRequestInSequence.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" ><!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator --><header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/><!-- We are storing the input values which the end users input for these values into these two properties --><property name="uri.var.categoria" expression="$url:categoria"/>
<!-- 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://localhost:81/soap/products.php/query/">
<soapenv:Header/>
<soapenv:Body>
<quer:getProd>
<quer:categoria>$1</quer:categoria>
</quer:getProd></soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg expression="get-property(‘uri.var.categoria’)"/>
</args>
</payloadFactory><!-- Here we are setting the content type which the web service expects --><property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</sequence>
xml_to_json_out_message.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="xml_to_json_out_message" >
<!-- Transforms the response to a JSON -->
<property description="message" name="messageType" scope="axis2" type="STRING" value="application/json"/>
</sequence>
Now, according to the documentation, these files once created, I charge in the Message Mediation Policies, and should work perfectly
but it gives me this error
Gateway Failures
Failed to Publish Environments
Production and Sandbox
Error in deploying the sequence to gateway###
Thanks in advance for the help
getProdRequestInSequence.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" ><!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator --><header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/><!-- We are storing the input values which the end users input for these values into these two properties --><property name="uri.var.categoria" expression="$url:categoria"/>
<!-- 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://localhost:81/soap/products.php/query/">
<soapenv:Header/>
<soapenv:Body>
<quer:getProd>
<quer:categoria>$1</quer:categoria>
</quer:getProd></soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg expression="get-property(‘uri.var.categoria’)"/>
</args>
</payloadFactory><!-- Here we are setting the content type which the web service expects --><property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</sequence>
and the output sequence
xml_to_json_out_message.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="xml_to_json_out_message" >
<!-- Transforms the response to a JSON -->
<property description="message" name="messageType" scope="axis2" type="STRING" value="application/json"/>
</sequence>
Now, according to the documentation, these files once created, I charge in the Message Mediation Policies, and should work perfectly
but it gives me this error
Gateway Failures
Failed to Publish Environments
Production and Sandbox
Error in deploying the sequence to gateway
Thanks in advance for the help
There is a syntax mismatch in the provided getProdRequestInSequence.xml synapse configuration file.
The uri.var.categoria has been enclosed with a special character (‘) inside the get-property() method and which is not a single-quote symbol ('). Please find the updated synapse configuration file below
getProdRequestInSequence.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" >
<!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator -->
<header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/>
<!-- We are storing the input values which the end users input for these values into these two properties -->
<property name="uri.var.categoria" expression="$url:categoria"/>
<!-- 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://localhost:81/soap/products.php/query/">
<soapenv:Header/>
<soapenv:Body>
<quer:getProd>
<quer:categoria>$1</quer:categoria>
</quer:getProd>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg expression="get-property('uri.var.categoria')"/>
</args>
</payloadFactory>
<!-- Here we are setting the content type which the web service expects -->
<property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</sequence>
Resolution for the above-mentioned issue:
At the moment Your approach has a special character "‘" which is
common if you use a mac book for the developments. Replacing the
single quotes with the correct character will resolve your current
issues.
Recommended Approach with WSo2 API Manager :
WSO2 API Manager has the capability of exposing a SOAP Service/API as a REST API Out of the box without any sequences or synapse level configurations.
To get the REST service exposed with WSO2 API Manager you just have to provide the backend URL and the WDSL file with this feature.
Please refer to the Documentation here.

WSO2 REST proxy answer back with SOAP instead of REST

Recently I had a problem with wso2 esb that I cannot resolve (maybe a bug). I will try to explain it as clear as possible.
I use the wso2 ESB with a rest proxy in order to communicate from a frontend application to a backend Rest service.
I defined a rest proxy with an endpoint like this and it worked fine:
<endpoint>
<address uri="http://127.0.0.1:8099/DummyRestServiceWSO2"/>
</endpoint>
But our goal is to integrate WSO2 esb in a container inside an openshift environment. In openshift the ip are set dynamically but accessible through system environment variable. So I tried to solve my endpoint dynamically byusing the header tag:
<endpoint>
<default/>
</endpoint>
<inSequence>
<script language="js">mc.setProperty("url",java.lang.System.getenv("HOST_IP"));</script>
<property name="service_url" expression="fn:concat(get-property(url),'/DummyRestServiceWSO2')"/>
<header name="To" expression="get-property('service_ep')"/>
<send/>
</inSequence>
Where HOST_IP is defined as: http://127.0.0.1:8099
Since I made this change my call to the backend rest service is still working fine but the response to the caller (frontend) is now formatted as soap (I tried to draw the problem, see attachment).
Thanks a lot for your help and I wish a wonderfull day to whoever read this post :)
If by "REST" you mean "JSON" format, just define this property before sending back the reponse to the client :
<property name="messageType" value="application/json" scope="axis2"/>
Use application/xml for plain xml (no SOAP envelope / body)
You also can use a default endpoint in send mediator and define the format :
<send>
<endpoint>
<default format="rest">
<timeout>
<responseAction>fault</responseAction>
</timeout>
</default>
</endpoint>
</send>

wso2 message soap format conversion

I use wso2 4.8.1, I have trouble with soap out messages from wso2 esb. Mesages are in soap 1.2 format 1.2 my client software expect soap messages in 1.1 format.
In my sequence file, I force soap format using the following section :
<send>
<endpoint>
<default format="soap12"/>
</endpoint>
</send>
This works fine on one of my servers, but it doesn't work on the other :
It works well on Windows XP with Java 1.6.0_13
It does not work on Windows 7 with Java 1.6.0_30
That's the only differences !
Notice that I use Axis2_pt.xml configuration file (pass through) for Axis2.
Any idea ?
Try to set messageType property :
soap1.1 : <property name="messageType" value="text/xml" scope="axis2"/>
soap1.2 : <property name="messageType" value="application/soap+xml" scope="axis2"/>
with soap1.1, you need to set the SOAP Action : use <header name="Action" value="mySoapAction"/>

How to encode ¿ to ISO-8859 with WSO2 ESB

During the evaluation of sample data I discovered the following problem. When the content in the JMS contains the "upside down question mark" <test>Inverted¿QuestionMark</test>, the proxy crashes - in fact hangs and the CPU goes up to 100%.
Here the code of the proxy to reproduce easily:
Just add <test>Inverted¿QuestionMark</test> into a queue named "test_qEncoding" and see how the CPU goes up and the proxy hangs.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="test_encoding_crash_jms" transports="jms" startOnLoad="true" trace="disable">
<parameter name="transport.jms.Destination">test_qEncoding</parameter>
<parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
<parameter name="transport.jms.DestinationType">queue</parameter>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>application/xml;charset="iso-8859-15"</default>
</rules>
</parameter>
<target>
<inSequence>
<log level="custom">
<property name="Context" value="Proxy test_encoding_crash_jms called"/>
</log>
<log level="full"/>
</inSequence>
</target>
</proxy>
When I use a vfs proxy and read as ISO-8859 it works. When I don't specify ;charset="iso-8859-15"then it works also, but the content is then not in the correct endoding for my output.
How should I get the message from the JMS when I want to send it then as ISO-8859?
Why does the above proxy hangs and blocks the whole WSO2 ESB?
This was reported sometime back [1]. Seems to be an issue existing. Please refer the JIRA for more details. Further if you can reproduce it consistently please mention that so we can raise the priority.
[1] https://wso2.org/jira/browse/ESBJAVA-1751

Wso2 ESB GET PROXY NAME

I would like to know how can I get the name of the proxy in use in a sequence:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="PROXYNAME" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property> *GET-NAME OF THIS PROXY...* </property>
</inSequence>
</target>
<publishWSDL uri="http://localhost/Test2/Service.asmx?wsdl" />
</proxy>
EDIT
In order to get the Name of the proxy (which should be contained in the header 'To' I am trying this as inSequence of a proxy:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="testsequence">
<property xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="p1" expression="$header/wsa:To" scope="default" />
<log level="custom">
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="***output" expression="get-property('p1')" />
</log>
</sequence>
does not work, any suggestion please?
This will return proxy name.
<log level="custom"> <property name="ProxyName" expression="$ctx:proxy.name"/></log>
Solved with a very simple: get-property('To')
Nuvio,
I'm just wondering what's the real requirement in doing this as the name of a particular proxy service remains static while a particular is completely served by the service. However, if you really want to do this, an easier way would be to have a static property (using property mediator) at the beginning of the sequence and have the proxy name assigned to it. Or you can probably extract the value of the "To" header by using the expression "$header/wsa:To" in which "wsa" corresponds to the relevant addressing namespace, and then write a regular expression to extract the service name.
Cheers,
Prabath