wso2 esb change soap namespace prefix - soap

I have a proxy service on my wso2esb and a response like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
..........
</soap:Body>
</soap:Envelope>
Does wso2esb have any configurable place where I can change the soap prefix? I need a result like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
..........
</soapenv:Body>
</soapenv:Envelope>

You should'nt care about the name of the namespace, but if you really need that, you can for exemple use enrich mediator to : Save the body, change soap envelope, restore the body
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestSOF"
transports="http"
startOnLoad="true"
trace="disable">
<description/>
<target endpoint="ProductEngineServiceMock1">
<outSequence>
<enrich>
<source type="body"/>
<target type="property" property="INPUT_MESSAGE"/>
</enrich>
<enrich>
<source type="inline">
<myns:Envelope xmlns:myns="http://schemas.xmlsoap.org/soap/envelope/">
<myns:Body/>
</myns:Envelope>
</source>
<target type="envelope"/>
</enrich>
<enrich>
<source type="property" property="INPUT_MESSAGE"/>
<target type="body"/>
</enrich>
<send/>
</outSequence>
</target>
</proxy>

Related

how to update soap response namespace value with wso2 ei

I have a proxy service to expose a soap api on wso2 ei, and i need to update the namespace value of the soap response with my proxy service and return another namespace value.
I have tried with the enrich mediator as follows inside the outsequence.
<property name="namespace"
scope="default"
type="STRING"
value="http://tempuri-updated.org/"/>
<enrich>
<source clone="false" property="namespace" type="property"/>
<target xmlns:ser="http://services.samples"
xmlns:ns="http://org.apache.synapse/xsd"
xpath="namespace-uri($body/*)/text()"/>
</enrich>
I get this error.
ERROR - EnrichMediator Invalid Target object to be enrich.
my actual soap response is as follows
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AddResponse xmlns="http://tempuri.org/">
<AddResult>12</AddResult>
</AddResponse>
</soap:Body>
</soap:Envelope>
my expected output as follows
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AddResponse xmlns="http://tempuri-updated.org/">
<AddResult>12</AddResult>
</AddResponse>
</soap:Body>
</soap:Envelope>
All your feedbacks are welcome
This cannot be done with the enrich mediator. Because in the code related to enrich mediator target handling [1], the parsed result of an xpath expression should be one of SOAPHeaderImpl, OMElement, OMText or OMAttribute. Since namespace-uri() is just returning a string value, the target to be enriched is becoming invalid. As an alternative to this use case, we can do an XSLT transformation using the XSLT mediator. Following is a sample XSL style sheet I tried.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="#* | comment() | processing-instruction()">
<xsl:copy/>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}"
namespace="http://tempuri-updated.org/">
<xsl:apply-templates select="#* | node()"/>
</xsl:element>
</xsl:template>
We can refer this style sheet in the XSLT mediator before sending the response out from the EI. The new namespace will be added to the body.
Try this.
http://codertechblog.com/wso2-change-payload-soap-envelope-namespace/
<sequence name="seTestChangeNamespace" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
(...)
<enrich>
<source type="body"/>
<target type="property" property="INPUT_MESSAGE"/>
</enrich>
<enrich>
<source type="inline">
<myns:Envelope xmlns:myns="http://schemas.xmlsoap.org/soap/envelope/">
<myns:Body/>
</myns:Envelope>
</source>
<target type="envelope"/>
</enrich>
<enrich>
<source type="property" property="INPUT_MESSAGE"/>
<target type="body"/>
</enrich>
(...)
</sequence>

WSO2 ESB 5.0 How to recover value xml element into cdata section?

Hello WSO2 ESB community,
We are new in WSO2. We need help to resolve this question.
We've developed a proxy which receives a soap message like this.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:es="http://es.ata">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<es:rc>
<es:xml><![CDATA[<message date="2017-03-02" id="ATA001">.....</message>]]></es:xml>
<es:rc>
</soapenv:Body>
</soapenv:Envelope>
How can we recover the attribute value "id"??
Anyone can help us??
Thanks in advance.
Extract es:xml content in a property type OM (XML) and use XPath inside this content.
Send your payload to this sample proxy and have a look to wso2-esb-service.log, you will find "id = ATA001"
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestSOF" transports="http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence>
<property xmlns:es="http://es.ata" name="CDATAPAYLOAD" expression="$body/es:rc/es:xml" type="OM"/>
<property name="ID_VALUE" expression="get-property('CDATAPAYLOAD')/#id"/>
<log level="custom">
<property name="id" expression="get-property('ID_VALUE')"/>
</log>
</inSequence>
</target>
</proxy>

WSO2 ESB 4.8.0 Proxy service transcoding iso to utf-8

Context:
I use wso2esb 4.8.0.
I have proxy service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="eProxy"
transports="https"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
</inSequence>
<outSequence>
<send/>
</outSequence>
<endpoint>
<address uri="http://10.24.74.53:8088/xxxService?WSDL"/>
</endpoint>
</target>
<publishWSDL uri="file://wso2esb-4.8.0/repository/mcc/resources/xxx.wsdl"/>
<description/>
</proxy>
Problem:
xxxService response is encoding in iso-8859 and I want to transform this response to utf-8
My first approch:
I use xslt mediator :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" />
<xsl:template match="/">
<result>
<xsl:value-of select="." />
</result>
</xsl:template>
</xsl:stylesheet>
but I have error
ERROR NativeWorkerPool uncaught exception java.lang.stackoverflowerror com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanName(XMLEntityScanner.java:726)
My second approch:
I set property in out Sequence:
<property name='CHARACTER_SET_ENCODING' scope='Axis2' value='UTF-8'/>
but I have error
ERROR NativeWorkerPool uncaught exception java.lang.stackoverflowerror com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanName(XMLEntityScanner.java:726)
My last approch:
I write custom mediator but I dont know how chang SoapEnvelope or SoapBody encoding
thinks for your Help.
To change encoding and content type, look at ContentType and messageType properties : http://docs.wso2.org/display/ESB480/Generic+Properties
Sample value : text/xml; charset=ISO-8859-1

WSO2 ESB adding prefix to header

I try to use the WSO2 ESB with the SAP Solution Manager Webservice as an endpoint.
For sending a message to the Webservice I need to modify the SOAP Header.
While searching with google I found out that I could use the Enrich Mediator for this. But I couldn't find an example how to add the prefix to the header.
What I have is this:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<urn:ReadCompleteIncident>
<IncidentGuid>xxxxx</IncidentGuid>
<SystemGuid>xxx</SystemGuid>
</urn:ReadCompleteIncident>
</soapenv:Body>
</soapenv:Envelope>
But I get an error because the ESB doesn't know the prefix "urn:". So I have to add "xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style"" to the Header for getting this:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soapenv:Body>
<urn:ReadCompleteIncident>
<IncidentGuid>xxxxx</IncidentGuid>
<SystemGuid>xxx</SystemGuid>
</urn:ReadCompleteIncident>
</soapenv:Body>
</soapenv:Envelope>
How can I do this with the Enrich Mediator? Or is there another solution?
Thank you :)
You can use the Header mediator of WSO2 ESB to achieve your requirement.
<header name="Action" value="urn:ReadCompleteIncident"/>
You can refer this link to find more information.
http://docs.wso2.org/wiki/display/ESB460/Header+Mediator
I solved this problem with Enrich Mediator. For example, here is my proxy.
Input message to ESB:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<content>Message content</content>
</soap:Body>
</soap:Envelope>
Required Input message to SAP PI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:xxxx">
<soapenv:Header/>
<soapenv:Body>
<urn:xxxx>
<content>Message content</content>
</urn:xxxx>
</soapenv:Body>
</soapenv:Envelope>
Solution:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="WSO2toSAP"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<property name="FORCE_SC_ACCEPTED"
value="true"
scope="axis2"
type="STRING"/>
<log level="full"/>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="INPUT_MESSAGE"/>
</enrich>
<enrich>
<source type="inline" clone="true">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body/>
</soapenv:Envelope>
</source>
<target type="envelope"/>
</enrich>
<enrich>
<source type="inline" clone="true">
<urn:xxxx xmlns:urn="urn:xxxx"/>
</source>
<target type="body"/>
</enrich>
<enrich>
<source type="property" clone="true" property="INPUT_MESSAGE"/>
<target type="body" action="child"/>
</enrich>
<log level="full"/>
<send>
<endpoint key="WSO2toSAP_endpoint"/>
</send>
</inSequence>
</target>
<description/>
</proxy>
I hope, that I help you :)
I think there are multiple ways you can solve this problem -
payloadFactory mediator to manipulate the request or response.
using script mediator - check this page http://abeykoon.blogspot.com/2013/03/encoding-and-decoding-xml-using-wso2-esb.html#comment-form for more details on how to use the script. As you can see, the blogger is generating the request using payloadFactory and then manipulate it using the scripts to get the desired effect.
If I find time, I will try to build a quick solution for you using the scripts.
All the best..

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