How to encode ¿ to ISO-8859 with WSO2 ESB - encoding

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

Related

different Content-Types in the end point response

I have a rest API with the Content-Type = application/json, provided by a tomcat server.
This means that all the responses are supposed to be in the json format.
The rest API is called by the WSO2 ESB to pass some data.
in case that the application providing the rest API is down (but the tomcat server is still up), the tomcat server replays with the http code=404 with the Content-Type=text/html (sending the HTML page "The requested resource is not available.") what results into the ESB error "Error while building message" exception and ESB crashes and losses the message.
Can you please suggest how to handle such a scenario? I'd need to receive the msg and react on this event. Is there perhaps a way how to dynamically switch content-types?
Can you try this with your own modification:
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault_filter_based_http_status_code" trace="disable">
<filter regex="401" source="get-property('axis2', 'HTTP_SC')">
<then>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:Server"/>
<reason value="Unauthorized to access the resource"/>
<role/>
</makefault>
<send/>
</then>
<else/>
</filter>
<filter regex="500" source="get-property('axis2', 'HTTP_SC')">
<then>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:Server"/>
<reason value="Internal Server Error Occurred"/>
<role/>
</makefault>
<send/>
</then>
<else/>
</filter>
</sequence>
Take a look: http://harshcreationz.blogspot.com/2016/02/common-and-error-handling-sequences.html

WSO2 ESB - soap envelope that is automatically added is causing issues

I'm exploring WSO2 ESB and have hit an issue. I am using a simple pass through proxy to post XML data from SAP (or Postman, to test) which then gets forwarded to a REST API - should be easy!
When I POST direct to the REST API (not through ESB), it works fine.(200, OK)
But WSO2 ESB is adding a SOAP Envelope automatically, which the REST API will not accept. I've tried various approaches to remove the automatically added SOAP envelope, with no success. Tried XSLT transform, POX format, Enrich mediator etc., every suggestion I could find.
(I can remove envelope element using XSLT if it is sent as part of the body, but not the one WSO2 adds in)
I can access the body, without SOAP envelope, using :
<property name="body" expression="$body/*[1]" type="OM"/>
but am not sure how to forward this to the API.
Any ideas how to stop this envelope being added in the first place in WSO2 ESB, or on how to remove it?
I used the xslt code from this answer, which works fine when I include the SOAP tags in the body, but has no effect on the SOAP envelope that seems to get automatically added in WSO2 (except to give the error, below).
I tried different variations of the line:
<xsl:apply-templates select="soap:Envelope/soap:Body/*"/>
such as
<xsl:apply-templates select="soap:Envelope/*"/>
<xsl:apply-templates select="/*"/>
this is an error I see in the ESB log:
Unable to perform XSLT transformation using : Value {name ='null', keyValue ='discountPayment'} against source XPath : s11:Body/child::[position()=1] | s12:Body/child::[position()=1] reason : Unable to create an OMElement using XSLT result
I am pretty new to WSO2 ESB, and have not used XSLT before, so may be some very basic mistake in my approach....
here is my proxy xml, and the XSLT "removeSOAP":
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="APIServer" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="full">
<property name="FirstLog" value="APITest LOG...."/>
<property name="payload" expression="$body/*[1]" type="OM"/>
</log>
<xslt key="removeSOAP"/>
<log level="full">
<property name="SecondLog" value="after xslt...."/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
<send>
<endpoint name="endpoint_urn_uuid_xxxxxx">
<address trace="disable" uri="http://myAPIendpoint " />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="removeSOAP" xmlns="http://ws.apache.org/ns/synapse">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:m="http://www.example.org/stock">
<xsl:template match="/">
<xsl:apply-templates select="soap:Envelope/soap:Body/*"/>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</localEntry>
A colleague figured this out today, I post the answer here incase it helps someone in the future:
in the proxy service, before send, add the line
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
then it works.
No need for the XSLT transform that is shown above, just this line fixes it.
if your backend it´s an API better you can use the http endpoint https://docs.wso2.com/display/ESB500/HTTP+Endpoint:
<send>
<endpoint>
<http method="POST"
uri-template="http://your.backend.endpoint.org/"/>
</endpoint>
</send>

The endpoint reference (EPR) for the Operation not found using glassfish n wso2esb

I am new to wso2 esb.
I am trying a simple web service program.
package testmart;
import javax.jws.WebService;
#WebService
public class testone {
public String testMethod()
{
return "success";
}
}
I am using glassfish server, created a proxy on wso2 esb by giving following details:
web service url: http://localhost:8080/testmart/testoneService
wsdl url :http://localhost:8080/testmart/testoneService?wsdl
After creating its showing "success" msg. But when I test it, the following error comes up:
<soapenv:Fault xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:axis2ns7="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Code>
<soapenv:Value>axis2ns7:Client</soapenv:Value>
</soapenv:Code>
<soapenv:Reason>
<soapenv:Text xml:lang="en-US" xmlns:xml="http://www.w3.org/XML/1998/namespace">
The endpoint reference (EPR) for the Operation not found is /services/testmart1.testmart1HttpSoap12Endpoint and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.
</soapenv:Text>
</soapenv:Reason>
<soapenv:Detail/>
</soapenv:Fault>
Below is my esb source view code:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
<registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
<parameter name="cachableDuration">15000</parameter>
</registry>
<proxy name="testmart1"
transports="https http local"
startOnLoad="true"
trace="disable">
<description/>
<target>
<endpoint>
<address uri="http://localhost:8080/testmart/testoneService"/>
</endpoint>
<outSequence>
<send/>
</outSequence>
</target>
<publishWSDL uri="http://localhost:8080/testmart/testoneService?wsdl"/>
</proxy>
<sequence name="fault">
<log level="full">
<property name="MESSAGE" value="Executing default 'fault' sequence"/>
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
</log>
<drop/>
</sequence>
<sequence name="main">
<in>
<log level="full"/>
<filter source="get-property('To')" regex="http://localhost:9000.*">
<send/>
</filter>
</in>
<out>
<send/>
</out>
<description>The main sequence for the message mediation</description>
</sequence>
</definitions>
I read all post about this error but could not solve this problem.
Any sort of help would be highly appreciated as this was the first example I tried and stuck from hours.
Thanks in advance.
When you send the request check if the SOAPAction is set. If not, you can specify it in two ways:
ESB level
Set the property before the send mediator
<property name="SOAPAction" value="urn:SOAPAction" scope="transport"/>
Client level
You can specify the SOAPAction in the client side code. Specify it in the options as shown below.
options.setAction("urn:SOAPAction");
in web interface from WSO2 ESB click "Source View" for your proxy and put this lines:
...
<parameter name="serviceType">proxy</parameter>
<parameter name="disableOperationValidation">true</parameter>
...
before the tag:<description/>
On Websphere Application Server, in the same situation, it helped deleting the Temp folders while the server was stopped.
You are using Wso2ESB, so you must need to specify like this:
#WebMethod(action = "testMethod", operationName = "testMethod")
public String testMethod()
The above annotation has to be used in the Web service implementation class.

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

WSO2 ESB mediate SOAP services

I am struggling to make work my message flow in the wso2 esb so I would need some help to implement a basic communication:
Service1 wants to receive an integer number
Service2 Generates random numbers
Service1 has InSequence: log, send (to addresspoint specified). OutSequence: log, send
this looks like:
<proxy name="ClientAskNumber" transports="https http" startOnLoad="true"
trace="disable">
<target faultSequence="fault">
<inSequence>
<log level="full">
<property name="Insequence" value="***" />
</log>
<send>
<endpoint>
<address uri="http://localhost:8280/services/RandomNumbers" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full">
<property name="Outsequence" value="***" />
</log>
<send />
</outSequence>
</target>
</proxy>
I have this response: <faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: urn:mediate. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()....etc
What it means? Am I missing something else? Please help. Thank you
EDIT:
I am studying the Wso2 ESB and I just need to understand how to make work a message communication, after it I will try to add different kind of mediation. I am just breaking down the problem, because I am new to this technology and as you can see I am really struggling to make it work...
EDIT2:*
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ClientAskNumber" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target endpoint="RandomNumbers">
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
<outSequence>
<log>
<property name="CLIENTRECEIVES" value="*******C_RECEIVES" />
</log>
</outSequence>
</target>
</proxy>
In the case this helps someone else: the problem with "Server did not recognize the value of HTTP Header SOAPAction: urn:mediate..." is that I needed to add an Header mediator in order to call my webservice method "getNumbers", into my InSequence as follows:
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<header name="Action" value="http://tempuri.org/getNumbers" />
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
and send this request via soapUI:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Numbers xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
I hope this can be useful to other persons who are using .Net Solutions with WSO2ESB (unfortunately there are not many examples out there...)
P.S. thanks to Ratha for his help
This is the flow i can tell you..
You have to point your 2nd service as the endpoint of your fist service..In the above configuration
http://localhost:8280/services/RandomNumbers --->2nd service url
ClientAskNumber -->1st service..
Now you can send the request which is needed to execute the 2nd service(ie:to retrive the random number)
So the proxy will forwrad to that endpoint and return the response to the outsequence..You should see that in the console/log since you used a log mediator.
In the error response you are getting i hope you are getting that from your second service. Check whether you are sending correct request to your endpoint