I am completely new to wso2 and I need to change my given input request xml to json and hit this to an adapter and get the response back in json and then in xml. How is this possible??
I am using wso2 integration studio for the development.
<Request>
<requestId><![CDATA[11111111111111111]]></requestId>
<timeStamp><![CDATA[2019/12/25 12:12:12]]> </timeStamp>
<msisdn> <![CDATA[888]]></msisdn>
<keyWord><![CDATA[TEST_API]]></keyWord>
<dataSet>
<param>
<id><![CDATA[first_id]]></id>
<value><![CDATA[12310209842396]]></value>
</param>
<param>
<id><![CDATA[second_id]]></id>
<value><![CDATA[1]]></value>
</param>
</dataSet>
</Request>
In the mediation sequence, you can use the messageType property to indicate that the message should be converted to JSON when sending it to your adapter. And in the return phase, you can use the messageType property again to convert the message to XML.
<property name="messageType" value="application/json" scope="axis2"/>
Example:
<?xml version="1.0" encoding="UTF-8"?>
<api name="toJson" context="/tojson" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="messageType" value="application/json" scope="axis2" />
<send>
<endpoint key="adapter"/>
</send>
</inSequence>
<outSequence>
<property name="messageType" value="application/xml" scope="axis2" />
<send />
</outSequence>
</resource>
</api>
Related
I am trying to read local Entry values based on dynamic user input(if Feed is user Input, then values inside Feed (host,user,password etc) should be fetched. but values not getting fetched for me. can anyone suggest me to achueve this?
LocalEntry:
<?xml version="1.0" encoding="UTF-8"?>
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="MailTo_Details">
<MAIL_Details xmlns="http://mail.com/localentry">
<Lead>
<credentials>
<host>smtp.gmail.com</host>
<port>587</port>
<starttls.enable>true</starttls.enable>
<auth>false</auth>
<user>Demouser</user>
<password>email1pws</password>
<from>email1#gmail.com</from>
</credentials>
</Lead>
<Feed>
<credentials>
<host>smtp.gmail.com</host>
<port>587</port>
<starttls.enable>true</starttls.enable>
<auth>false</auth>
<user>Testuser</user>
<password>email2pws</password>
<from>email2#gmail.com</from>
</credentials>
</Feed>
</MAIL_Details>
<description/>
</localEntry>
I have loaded localentry and setting values as OM type.But i don't know way to retrieving values by dynamically.
<property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:ns3="http://org.apache.synapse/xsd"
name="mailConfig"
expression="get-property('MailTo_Details')"
scope="default"
type="OM"/>
Try this proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="loadPayloadfromLocalEntry" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property expression="get-property('MailTo_Details')" name="mailConfig" scope="default" type="OM" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>
<property name="getinput" scope="default" type="STRING" expression="$body/getdata/mailinput"/>
<property name="apos" scope="default" type="STRING" value="'"/>
<log>
<property name="printValueEmail" expression="$ctx:mailConfig"/>
<property name="getinput" scope="default" type="STRING" expression="$body/getdata/mailinput"/>
<property name="HOST" expression="evaluate(fn:concat('$ctx:mailConfig//ns:',get-property('getinput'),'/ns:credentials/ns:host'))" xmlns:ns="http://mail.com/localentry"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
</proxy>
With payload as body:
<body>
<getdata>
<mailinput>Feed</mailinput>
</getdata>
</body>
My log message:
[2020-07-27 11:39:32,487] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /services/loadPayloadfromLocalEntry.loadPayloadfromLocalEntryHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:bc74622a-3843-4813-ab35-769138d5f8e6, Direction: request, printValueEmail = <MAIL_Details xmlns="http://mail.com/localentry">
<Lead>
<credentials>
<host>smtp.gmail.com</host>
<port>587</port>
<starttls.enable>true</starttls.enable>
<auth>false</auth>
<user>Demouser</user>
<password>email1pws</password>
<from>email1#gmail.com</from>
</credentials>
</Lead>
<Feed>
<credentials>
<host>smtp.gmail.com</host>
<port>587</port>
<starttls.enable>true</starttls.enable>
<auth>false</auth>
<user>Testuser</user>
<password>email2pws</password>
<from>email2#gmail.com</from>
</credentials>
</Feed>
</MAIL_Details>, getinput = Feed, HOST = smtp.gmail.com
I am trying to use data mapper in wso2 and translating the json to xml but it doesn't showing any result instead it showing page not found in POSTMAN.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/TEST" name="TEST" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<datamapper config="gov:datamapper/NewConfig.dmc" inputSchema="gov:datamapper/NewConfig_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/NewConfig_outputSchema.json" outputType="XML"/>
<property description="" name="ContentType" scope="axis2" type="STRING" value="application/xml"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Can anyone help me in this?
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
I have a instance where I need to implement a proxy service that takes a SOAP message, forwards it to an internal system (SOAP) and returns a HTTP 200 response to the original server.
Basically the response should be completely void of any soap detail (there's technically no output message in the WSDL that I have to implement).
Here's what I have so far (which simply takes the request & echos it back as the response):
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="ExampleHttp200Return"
transports="http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full" separator=", - inSequence: received - "/>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="SC_ACCEPTED" value="false" scope="axis2"/>
<property name="HTTP_SC" value="200" scope="axis2"/>
<send/>
</inSequence>
</target>
<description/>
</proxy>
If you want to send back an empty response, you can add that before send mediator :
<property name="messageType" scope="axis2" value="text/plain"/>
<enrich>
<source type="inline">
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header/>
<soapenv:Body>
<text xmlns="http://ws.apache.org/commons/ns/payload"/>
</soapenv:Body>
</soapenv:Envelope>
</source>
<target type="envelope"/>
</enrich>
I am using WSO2 ESB to send a JMS message (XML payload) to an endpoint and then to read a return JMS message (on another queue) from the same endpoint (which also sends an XML payload). The problem I am facing is that the return JMS message from the endpoint, even though it is an XML payload, comes in as a text message.
Here is what I see in WSO2 for the JMS message (with XML payload) sent back by the endpoint:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<axis2ns2:text xmlns:axis2ns2="http://ws.apache.org/commons/ns/payload">
<?xml version="1.0" encoding="UTF-8"?>
<Sys1Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Sys1-ack-nack.xsd">
<security>
<statusInfo>
<ARMStatus>ARM_ACK</ARMStatus>
<Sys1Status>Sys1_ACK</Sys1Status>
<FinalStatus>ACK</FinalStatus>
</statusInfo>
<upstreamIdentifier>
<tradeId>459609</tradeId>
<messageId>12345678</messageId>
<assetId>6M2</assetId>
<issueDescription>IRS RTP 3.12 19MAY11 JP</issueDescription>
<productType>SWAPTION</productType>
</upstreamIdentifier>
</security>
</Sys1Response>
</axis2ns2:text>
</soapenv:Body>
</soapenv:Envelope>
This is the WSO2 proxy definition.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
<registry provider="org.wso2.carbon.mediation.registry.ESBRegistry">
<parameter name="localRegistry">/</parameter>
<parameter name="cachableDuration">15000</parameter>
</registry>
<proxy name="ToWSO2"
transports="jms"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="transport.jms.ContentTypeProperty"
value="Content-Type"
scope="axis2"/>
<log level="full"/>
<call>
<endpoint>
<address uri="jms:/ToSys1?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue&transport.jms.ReplyDestinationType=queue&transport.jms.ReplyDestination=FromSys1&transport.jms.ContentType=application/xml"/>
</endpoint>
</call>
<log level="full"/>
</inSequence>
<outSequence>
<log level="full"/>
<drop/>
</outSequence>
</target>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>application/xml</default>
</rules>
</parameter>
<parameter name="transport.jms.Destination">ToWSO2</parameter>
</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>
Would appreciate help in resolving this. Many thanks in advance!