How would i transform the message Dynamically In WSO2ESB - xslt

I am using wso2esb4.8.0
I wish to transform the message using wso2esb .Actaulle need to add Complex Element to Payload
How would i achive this.
my Client request is
<?xml version="1.0" encoding="UTF-8"?>
But my Adapter endpoint will allow the request in this format.If it is for one operation i may follow payload mediator to make my request But those are bumch of requests
so Endpoint allowing request is
Just extract the Operation_Name and adding it as Complex Element But I am unable to do it I am trying in Proxy like this
Proxy is
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SamplePOC7"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property xmlns:open="http://www.openuri.org/"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:env="http://eai.mmn.mm/Envelope"
xmlns:poin="http://eai.mm.mm/gg"
name="Operation_Name"
expression="//poin:Operation_Name/text()"
scope="default"
type="STRING"/>
<property xmlns:open="http://www.openuri.org/"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:env="http://eai.mmn.xxxx/Envelope"
name="AddElement"
expression="concat('open:',get-property('Operation_Name'))"
scope="default"
type="STRING"/>
<enrich>
<source xmlns:env="http://eai.mmn.mm/Envelope"
clone="true"
xpath="//env:Payload/*"/>
<target xmlns:poin="http://eai.mm.XXX/gg"
xpath="concat('open:',//poin:Operation_Name/text())"/>
</enrich>
<log level="full">
<property name="Message" expression="get-property('AddElement')"/>
</log>
</inSequence>
<outSequence/>
</target>
<description/>
</proxy>
But its giving errors like the below my error log is
[2014-05-15 10:53:48,167] INFO - ProxyService Successfully created the Axis2 se
rvice for Proxy service : SamplePOC7
[2014-05-15 10:53:53,089] ERROR - EnrichMediator Invalid Target object to be enr
ich.
[2014-05-15 10:54:19,160] INFO - ProxyService Building Axis service for Proxy s
With which mediator i can extract this request as per my desire way please if you know paste configuration or else provide any example
Thanks in advance

You can use XSLT mediator or JavaScript
A sample proxy with javascript doing what you want :
<?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 name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<property xmlns:open="http://www.openuri.org/"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:poin="http://eai.mtn.iran/PointOfSales"
name="Operation_Name"
expression="//poin:Operation_Name/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:poin="http://eai.mtn.iran/PointOfSales"
name="PointOfSales"
expression="//poin:PointOfSales"
scope="default"
type="STRING"/>
<script language="js"><![CDATA[
mc.setPayloadXML(<open:{mc.getProperty("Operation_Name")} xmlns:open="http://www.openuri.org/">
{new XML(mc.getProperty("PointOfSales"))}
</open:{mc.getProperty("Operation_Name")}>);
]]></script>
<log level="full"/>
</inSequence>
</target>
</proxy>
A sample using XSLT :
<?xml version="1.0" encoding="UTF-8"?>
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="SOFXSL">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:open="http://openuri.org/"
xmlns:env="http://eai.mtnn.iran/Envelope"
xmlns:poin="http://eai.mtn.iran/PointOfSales"
version="2.0">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no"/>
<xsl:param name="operationname"/>
<xsl:template match="/">
<xsl:element name="open:{$operationname}">
<xsl:apply-templates select="//poin:PointOfSales"/>
</xsl:element>
</xsl:template>
<xsl:template match="#*|*|comment()">
<xsl:copy>
<xsl:apply-templates select="#*|*|text()|comment()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<description/>
</localEntry>
<?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 name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<property xmlns:open="http://www.openuri.org/"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:poin="http://eai.mtn.iran/PointOfSales"
name="Operation_Name"
expression="//poin:Operation_Name/text()"
scope="default"
type="STRING"/>
<xslt key="SOFXSL">
<property name="operationname" expression="get-property('Operation_Name')"/>
</xslt>
<log level="full"/>
</inSequence>
</target>
</proxy>

Related

WSO2 EI soap envelope missing

I have a SOAP proxy service with a Data Mapper to create the output.
The created response does not have the soap envelope tag.
If I try to add the envelope with the payload factory, it strips out the envelope (but it keeps the Body element).
I'm using the WSO2 EI 6.4.0.
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="EstrattoContoEntiTributi" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
...
<send>
<endpoint key="..."/>
</send>
</inSequence>
<outSequence>
<datamapper .../>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
We need to use a property mediator as below.
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="PF2"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<payloadFactory media-type="xml">
<format>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsd="http://services.samples/xsd"
xmlns:ser="http://services.samples">
<soap:Header/>
<soap:Body>
<ser:getQuote>
<ser:request>
<xsd:symbol>IBM</xsd:symbol>
</ser:request>
</ser:getQuote>
</soap:Body>
</soap:Envelope>
</format>
<args/>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<log level="full">
<property name="ChangedEnve" value="----Changed-------"/>
</log>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
Hope this helps,
https://medium.com/#isuruuy/how-to-construct-a-payload-with-the-soap-envelope-ce8df5032dda

Runtime error on WSO2 ESB 5.0

I'm trying to use WS02 ESB 5.0 to call a web service every 15 seconds, so I have this task:
<?xml version="1.0" encoding="UTF-8"?>
<task class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz" name="UpdateName" xmlns="http://ws.apache.org/ns/synapse">
<trigger cron="0/15 * * * * ?" />
<property name="message"
xmlns:task="http://www.wso2.org/products/wso2commons/tasks">
<def:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:def="http://DefaultNamespace" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id xsi:type="xsd:string">usr</id>
<pw xsi:type="xsd:string">pwd</pw>
</def:login>
</property>
<property name="sequenceName" value="main"
xmlns:task="http://www.wso2.org/products/wso2commons/tasks" />
<property name="injectTo" value="sequence"
xmlns:task="http://www.wso2.org/products/wso2commons/tasks" />
</task>
And this sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="main" xmlns="http://ws.apache.org/ns/synapse">
<in>
<send>
<endpoint>
<wsdl port="SakaiLogin" service="SakaiLoginService" trace="disable"
uri="http://myserver/sakai-axis/SakaiLogin.jws?wsdl" />
</endpoint>
</send>
</in>
<out>
<send />
</out>
<log level="full" />
</sequence>
Both from the examples shown in the documentation:
https://docs.wso2.com/display/ESB500/Adding+and+Scheduling+Tasks (See "Injecting the message to a named sequence or proxy service").
https://docs.wso2.com/display/ESB500/Sample+56:+Using+a+WSDL+Endpoint+as+the+Target+Endpoint (See "Building the sample").
However, I'm getting this error once I start the Carbon WSO2 ESB server:
[2017-01-27 17:03:45,005] ERROR - InMediator Runtime error occurred while mediating the message
java.lang.NullPointerException
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.isTransportSwitching(Axis2SynapseEnvironment.java:783)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:545)
at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:382)
at org.apache.synapse.endpoints.WSDLEndpoint.send(WSDLEndpoint.java:75)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:121)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
at org.apache.synapse.mediators.filters.InMediator.mediate(InMediator.java:74)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.mediators.MediatorWorker.run(MediatorWorker.java:80)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
[2017-01-27 17:03:45,023] INFO - LogMediator To: ,
MessageID: urn:uuid:097fb69e-6461-428e-ac85-93cfde65d02e,
Direction: request,
MESSAGE = Executing default 'fault' sequence,
ERROR_CODE = 0,
ERROR_MESSAGE = Runtime error occurred while mediating the message, Envelope:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<def:login xmlns:def="http://DefaultNamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<id xmlns="http://ws.apache.org/ns/synapse" xsi:type="xsd:string">usr</id>
<pw xmlns="http://ws.apache.org/ns/synapse" xsi:type="xsd:string">pwd</pw>
</def:login></soapenv:Body></soapenv:Envelope>
Can anybody give me a clue of what is going on?
Much appreciated!
In the wsdl endpoint the uri value must be the WSDL address, not the service endpoint:
WSDL URI The URI of the WSDL. Click Test to test the URI.
So, the WSDL endpoint inside the send mediator extracts the service endpoint from the WSDL document using the service and port name to find it inside the wsdl document.
UPDATE 1:
My task config xml:
<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse"
name="UpdateName"
class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz">
<trigger cron="0/15 * * * * ?"/>
<property name="proxyName" value="testTask"/>
<property name="message">
<moc:QRY_SELECT_SRH_EMPLEADO xmlns:moc="http://www.example.org/mockWS/">
<INT_ID>gero et</INT_ID>
</moc:QRY_SELECT_SRH_EMPLEADO>
</property>
<property name="soapAction"
value="http://www.example.org/mockWS/QRY_SELECT_SRH_EMPLEADO"/>
<property name="injectTo" value="proxy"/>
</task>
My sequence named main1:
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="main1">
<in>
<header name="Action" scope="default" value="http://www.example.org/mockWS/QRY_SELECT_SRH_EMPLEADO"/>
<send>
<endpoint>
<wsdl service="mockWS"
port="mockWSSOAP"
uri="http://localhost:8088/mockmockWSSOAP?wsdl"/>
</endpoint>
</send>
</in>
<out>
<log level="full"/>
<drop/>
</out>
</sequence>
And finally I created a proxy with the same logic because a issue with the drop mediator inside a sequence:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="testTask"
transports="https http"
startOnLoad="true">
<target>
<inSequence>
<header name="Action" scope="default" value="http://www.example.org/mockWS/QRY_SELECT_SRH_EMPLEADO"/>
<send>
<endpoint>
<wsdl service="mockWS"
port="mockWSSOAP"
uri="http://localhost:8088/mockmockWSSOAP?wsdl"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<drop/>
</outSequence>
<faultSequence/>
</target>
</proxy>

Reading Local Entry (XML,URL) in WSO2 ESB

I have configured below two local entry in WSO2 WSB4.9.0 how can I read the node values in proxy or sequence.
In-Line XML Local Entry
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="test" xmlns="http://ws.apache.org/ns/synapse">
<list>
<flag>a</flag>
<path>b</path>
</list>
</localEntry>
and
Source URL Entry
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="sample" src="file:/C:/Apache24/bin/ApacheMonitor" xmlns="http://ws.apache.org/ns/synapse"/>
Please help.
If the entry is in the filesystem, you can use:
<property name="testProp" expression="get-property('test')" scope="default" type="STRING"/>
and
<property name="sampleProp" expression="get-property('sample')" scope="default" type="STRING"/>
If you want to get access to the values inside XML set OM type:
<property name="testProp" expression="get-property('test')" scope="default" type="OM"/>
<log level="custom">
<property expression="$ctx:testProp" name="FullValue" />
<property expression="$ctx:testProp//tt:flag" name="flagValue" xmlns:tt="http://ws.apache.org/ns/synapse"/>
<property expression="$ctx:testProp//tt:path" name="pathValue" xmlns:tt="http://ws.apache.org/ns/synapse"/>
</log>
My full proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="testProxy6"
transports="https http"
startOnLoad="true"
trace="disable">
<target>
<inSequence>
<property name="testProp" expression="get-property('test')" scope="default" type="OM"/>
<log level="custom">
<property expression="$ctx:testProp" name="FullValue" />
<property expression="$ctx:testProp//tt:flag" name="flagValue" xmlns:tt="http://ws.apache.org/ns/synapse"/>
<property expression="$ctx:testProp//tt:path" name="pathValue" xmlns:tt="http://ws.apache.org/ns/synapse"/>
</log>
<respond/>
</inSequence>
<outSequence>
<log level="full">
<property value="SEQUENCE: " name="OUT"/>
</log>
<send/>
</outSequence>
</target>
</proxy>
My local entry in file test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="test" xmlns="http://ws.apache.org/ns/synapse">
<list>
<flag>a</flag>
<path>b</path>
</list>
</localEntry>
My log output:
[2016-05-11 12:21:30,999] INFO - LogMediator FullValue = <list xmlns="http://ws.apache.org/ns/synapse">
<flag>a</flag>
<path>b</path>
</list>, flagValue = a, pathValue = b
If you need to obtain values from an xml in a local entry, first of all you should have to get the xml content into a property and set its type to OM as below.
<property expression="get-property('xmlLocalEntrySample')" name="xmlTest" scope="default" type="OM"/>
Now from the message context you can read the property values like this. Here $ctx is the prefix for Synapse Message-Context properties and gets a property at the default scope using this. If you log the values of testFlagA and testPath you can see a and b print in the console respectively.
<property expression="$ctx:xmlTest//*[local-name()='flag']" name="testFlagA"/>
<property expression="$ctx:xmlTest//*[local-name()='path']" name="testPath"/>
For me get-property does not work for local entries, while xslt mediator works well . ie6.4

wso2 esb mediator is singleton

I configure two proxies in ESB, and these 2 proxies are bridged to one instance mediator. And I have different property set for mediator in proxy configuration.
I expect that the two mediators instances are running in ESB with different properties.
But in fact, seems only mediator instance is in ESB.
Any idea on this?
I made a mistake here. In java code, spring bean is used to contain mediator property configured in xml file. But spring bean is singleton and causes different configuration cannot be applied in different proxy.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="abc"
transports="http"
startOnLoad="true"
trace="enable"
statistics="enable">
<description/>
<target>
<inSequence>
<log level="full"/>
<property name="address"
scope="transport"
expression="fn:substring-after(get-property('To'),'/services/crownperth')"/>
<class name="com.abc.customerintegration.mediator.CustomerInfoMediator">
<property name="pmServerAddress" value="http://192.168.112.243:3509/MobileConnectService"></property>
<property name="property" value="P"/>
<property name="languageCode" value="en-US"></property>
</class>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="def"
transports="http"
startOnLoad="true"
trace="enable"
statistics="enable">
<description/>
<target>
<inSequence>
<log level="full"/>
<property name="address"
scope="transport"
expression="fn:substring-after(get-property('To'),'/services/crownperth')"/>
<class name="com.abc.customerintegration.mediator.CustomerInfoMediator">
<property name="pmServerAddress" value="http://192.168.112.243:3509/MobileConnectService"></property>
<property name="property" value="P"/>
<property name="languageCode" value="en-US"></property>
</class>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>

WSO2 ESB XSLT Mediator creates temp files (never cleaned)

I use WSO2 ESB 4.5.1 on Windows.
My problem is that the temp folder WSO2_HOME/tmp is growing up and never cleaned.
I found out that the problem comes from the xslt mediator, everytime it transform a big xml file (~15kb) a new temp file is created.
Does anyone have an idea why these tmp files are not cleaned up?
Proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="input" transports="vfs" startOnLoad="true" trace="disable">
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.FileURI">vfs:file://C:/WSO2/Test/From</parameter>
<parameter name="transport.vfs.FileNamePattern">.*[.].*</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<target faultSequence="errorSequence">
<inSequence>
<log level="full"/>
<property name="ClientApiNonBlocking" scope="axis2" action="remove"/>
<property name="OUT_ONLY" value="true"/>
<xslt key="avintis_xml_indent"/>
<property name="transport.vfs.ReplyFileName" expression="fn:concat('out_', $trp:FILE_NAME, '.xml')" scope="transport"/>
<send>
<endpoint>
<address uri="vfs:file://C:/WSO2/Test/To"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy>
XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:avintis="http://www.avintis.com/esb"
xmlns:urn="urn:hl7-org:v2xml" version="2.0"
xmlns:payload="http://ws.apache.org/commons/ns/payload">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="*|text()|#*">
<xsl:copy>
<xsl:apply-templates select="*|text()|#*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
inputfile:
any xml file bigger than ~15kb
Seems temp files do not get cleaned up by the HouseKeeping Task. To clean them using the housekeeping task you can configure it in the Carbon.xml as shown below.
<WorkDirectory>${carbon.home}/tmp/work</WorkDirectory>
<HouseKeeping>
<AutoStart>true</AutoStart>
<Interval>10</Interval>
<MaxTempFileLifetime>30</MaxTempFileLifetime>
</HouseKeeping>