wso2 message soap format conversion - soap

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"/>

Related

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>

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>

How to set encoding of SOAP request in WSO2 ESB 4.9

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

How to change HTTP Status Code in WSO2 ESB REST API

I have a rest api created using WSO2 ESB.
I want to change the HTTP status code to 404 when the requested API resource does not match with the given URL.
Currently I am getting a 'HTTP/1.1 202 Accepted' response.
My esb version is 4.0.3.
Try with <property name="HTTP_SC" value="404" scope="axis2"/>
You can refer to wso2 documentation
<outSequence>
<property name="HTTP_SC" value="404" scope="axis2" />
<send/>
</outSequence>
The thing is when the URL is incorrect the request will not enter your code and will be answered by WSO2 ESB/EI itself. So in your code you don't have influence on the response in that case. Maybe it can be configured in WSO2 itself, can't find any on that yet.

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.