WSO2 ESB logging in proxy - wso2

I have simple proxy with send messages to some url. I would like to know when something is send through proxy, and when response is send back.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="SynchronizeService" transports="https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="simple"/>
<send>
<endpoint key="SynchronizeServiceEndpoint"/>
</send>
</inSequence>
<outSequence>
<log level="simple"/>
<send/>
</outSequence>
</target>
</proxy>
I added log mediator but the problem is, it don't log any information which allow to connect request and response. So example log looks like:
[2013-06-03 15:38:07,914] INFO - LogMediator To: http://esb-ip:9763/services/SynchronizeService, WSAction: http://test.pl/WebService/getWorkPlan, SOAPAction: http://test.pl/WebService/getWorkPlan, ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:36b60af3-dc30-4004-a239-26523774f52b, Direction: request
[2013-06-03 15:38:08,016] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:8f753934-c64a-4276-a916-dceaeda3def0, Direction: response
In logged response there is no information about SOAPAction, messageIds are different. How can I connect request with response in logs? I would like to known when response was send. How can I do this?

You did a simple log, which will log very basic info about the message. Do a log level=full, that will log the full message which is passed through the system

I didn't know that is is possible to assign variables in input Sequence and use them in output Sequence. I assign messageId from input sequence and log it in output. My proxy after changes looks like:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="SynchronizeService" transports="https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="simple"/>
<property name="requestSysDate" expression="get-property('SYSTEM_DATE')" scope="default" type="STRING"/>
<property name="requestMsgId" expression="get-property('MessageID')" scope="default" type="STRING"/>
<filter xmlns:procsyn="http://test.pl/WebService/Synchronize" xpath="//procsyn:getWorkPlanIn">
<property name="requestMethod" value="getWorkPlan" scope="default" type="STRING"/>
</filter>
<send>
<endpoint key="SynchronizeServiceEndpoint"/>
</send>
</inSequence>
<outSequence>
<log level="custom">
<property name="proxyName" value="SynchronizeService"/>
<property name="requestMethod" expression="get-property('requestMethod')"/>
<property name="requestSysDate" expression="get-property('requestSysDate')"/>
<property name="requestMsgId" expression="get-property('requestMsgId')"/>
</log>
<send/>
</outSequence>
</target>
</proxy>

Related

To read LocalEntry values in WSO2 EI

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

wso2 Return property value from insequence

I'm creating an wso2 that call an endpoint and then filter the response just to send back one field, but for some reason the esb answer with all the json
I have something like that:
<resource methods="POST" uri-template="/ESB">
<inSequence>
<call description="">
<endpoint key="CountryEP"/>
</call>
<property description="" expression="json-eval($.zones[0].countryCode)" name="uri.var.countryCode" scope="default" type="STRING"/>
<log description="">
<property expression="fn:concat('countryCode ', get-property('uri.var.countryCode')) " name="property_name"/>
</log>
<send buildmessage="true" description=""/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
And my Endpoint
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="CountryEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" trace="enable" uri-template="http://api.timezonedb.com/v2/list-time-zone?key=6HW6EJUENX9T&format=json&country={uri.var.country}"/>
</endpoint>
So as you can see above, i send a parameter to the API, and the API answers with a json, then i try to parse just one field (using the property) and i have the correct value:
INFO - LogMediator To:
http://www.w3.org/2005/08/addressing/anonymous, WSAction: ,
SOAPAction: , MessageID:
urn:uuid:97744789-8c88-41ff-9475-870761016834, Direction: request,
property_name = countryCode CA
But i can't return just that value, the esb return all json... ideas?
Thanks in advance,
EDIT: also tried with RESPONSE attribute on the property mediator
Try something like this:
<call description="">
<endpoint key="CountryEP"/>
</call>
<property description="" expression="json-eval($.zones[0].countryCode)" name="uri.var.countryCode" scope="default" type="STRING"/>
<log description="">
<property expression="fn:concat('countryCode ', get-property('uri.var.countryCode')) " name="property_name"/>
</log>
<payloadFactory media-type="json">
<format>{ "Country Code": $1}</format>
<args>
<arg expression="$.zones[0].countryCode.text" evaluator="json"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
<respond/>

call external web service from WSO2 ESB

I'm in an internel network and I want to create a service (ESB) to call an external get service.
for example my ESB service path: uri/esb/path/param1/param2
my external path: external/path/param1/param2
here my entry
<?xml version="1.0" encoding="UTF-8"?>
<api context="/services/KRI-getIndividualVehicleFuelco2" name="KRI-getIndividualVehicleFuelco2" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<property name="renault_error_format" scope="default" type="STRING" value="json"/>
<log level="custom">
<property name="getIndividualVehicleFuelco2" value="********** begin **********"/>
<property expression="get-property('RequestID')" name="RequestID"/>
</log>
<Delegation.DelegationIn>
<Jboss-Endpoint-Key>KRI-customAddressingTransformation.xml</Jboss-Endpoint-Key>
<Custom-Sequence-Header>KRI-commonsequences-processSpecialHeadersIn</Custom-Sequence-Header>
</Delegation.DelegationIn>
<loopback/>
</inSequence>
<outSequence>
<sequence key="KRI-commonsequences-genericErrorHandling"/>
<Delegation.DelegationOut>
<Jboss-Endpoint-Key>KRI-customAddressingTransformation.xml</Jboss-Endpoint-Key>
<Custom-Sequence-Header>KRI-commonsequences-processSpecialHeadersOut</Custom-Sequence-Header>
</Delegation.DelegationOut>
<log level="custom">
<property name="getIndividualVehicleFuelco2" value="********** end **********"/>
<property expression="get-property('RequestID')" name="RequestID"/>
</log>
</outSequence>
<faultSequence>
<loopback/>
</faultSequence>
</resource>
</api>
I created an endpoint with the base uri of the external service.
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="KIS-fuelco-PPD" xmlns="http://ws.apache.org/ns/synapse">
<address uri="http://kisre701.intra.com/kis/api/v2/individual-vehicle-fuelco2/"/>
</endpoint>
how can I parse parameters and send them to endpoint?

WSO2 ESB proxy Log mediator properties

I'd like to log (and ideally correlate) incoming and outgoing messages with at minimum the following properties:
Date/Time
Client Address (IP, name optional)
Method
I can get this working for incoming messages using the following but for the outgoing message (back to the client), it returns null.
get-property('axis2', 'REMOTE_ADDR')
Incoming
[2016-01-18 13:18:46,339] INFO - LogMediator To: /services/UserService, WSAction: http://tempuri.org/UserService/Login, SOAPAction: http://tempuri.org/UserService/Login, MessageID: urn:uuid:3e4b7f91-cab0-4294-a013-3c837f6695a0, Direction: request, REMOTE_ADDR: = 172.xx.xx.xx
Outgoing
[2016-01-18 13:18:46,505] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:8de88329-3968-4edc-8617-352fbcb5480b, Direction: response, REMOTE_ADDR: = null
It's also not possible to correlate the incoming and outgoing messages as the MessageId changes (I guess predictably).
Would it be necessary to set a custom property on the inbound side to correlate this?
AFAIK, you need set a custom property on the inSequence.
I tested this localy and for the below proxy I was able to get REMOTE_ADDR: = 172.xx.xx.xx for both Incoming and outgoing messages.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="test"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="client-add" expression="get-property('axis2', 'REMOTE_ADDR')"/>
<log level="custom">
<property name="REMOTE_ADDR :" expression="get-property('client-add')"/>
</log>
<send>
<endpoint>
<address uri="http://www.mocky.io/v2/569cac78110000dc24ce7614"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
<log level="custom">
<property name="REMOTE_ADDR :" expression="get-property('client-add')"/>
</log>
</outSequence>
</target>
<description/>
</proxy>
For more information on Retriving clientIP/Host within the sequence in Synapse please refer this documentation.
For more information on How to get client IP from out going requests of WSO2 Elastic load balancer please refer this documentation
Hope this information will help you.
Thanks
Yes, you need to add a custom property mediator to the inSequence to get and save the value of IP address of the incoming request. Then by adding log mediators to both inSequence and outSequence, you will be able to see that the IP address is preserved in outgoing message as well.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="oneProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="ip" expression="get-property('axis2', 'REMOTE_ADDR')"/>
<log level="full">
<property name="REMOTE_ADDR :" expression="get-property('ip')"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:8290/services/echo"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full">
<property name="REMOTE_ADDR :" expression="get-property('ip')"/>
</log>
<send/>
</outSequence>
</target>
<description/>
</proxy>
Hope this may help you...

How to convert (JSON toXML) request and Response(XML to JSON) to call an external Soap Service

i am new to wso2.. My requirement is
1) I want to transform incoming JSON request into XML format
2) Send that XML request to an external SOAP service
3) Response will get as XML and need to convert it into JSON format
Did somebody ever did that? If so, could you please share how you did?
I have the below configuration for a PROXY service
`<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="CelsiusToFahrenheitService"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="messageType" value="text/xml" scope="axis2"/>
<property name="Proxy-Authorization"
expression="fn:concat('Basic', base64Encode('INDIA\username:pwd'))"
scope="transport"/>
<property name="POST_TO_URI" value="true" scope="axis2"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
<header name="Action"
value="http://www.w3schools.com/webservices/CelsiusToFahrenheit"/>
<send>
<endpoint>
<address uri="http://www.w3schools.com/webservices/tempconvert.asmx"
format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="messageType" value="text/xml" scope="axis2"/>
<send/>
</outSequence>
</target>
<description/>
</proxy>`
XML Request
<CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
<Celsius>20</Celsius>
</CelsiusToFahrenheit>
XMl Response
<CelsiusToFahrenheitResponse xmlns="http://www.w3schools.com/webservices/">
<CelsiusToFahrenheitResult>68</CelsiusToFahrenheitResult>
</CelsiusToFahrenheitResponse>
Need to send REQUEST as JSON and RESPOSNE also get as JSON
Can anyone please help me the scenario
How to use ScriptMediator to do the above proxy service. I have got sample from here (https://docs.wso2.org/display/ESB481/Sample+441%3A+Converting+JSON+to+XML+Using+JavaScript)
I have did my configuration like this (Don't know is it correct or not)
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JsonToXMLProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<script language="js">var cel= mc.getPayloadJSON().CelsiusToFahrenheit.Celsius.toString();
mc.setPayloadXML(
<CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
<Celsius>{cel}</Celsius>
</CelsiusToFahrenheit>);</script>
<property name="messageType" value="text/xml" scope="axis2"/>
<log level="full"/>
</inSequence>
<outSequence>
<log level="full"/>
<property name="messageType" value="text/xml" scope="axis2"/>
<send/>
</outSequence>
<endpoint>
<address uri="http://www.w3schools.com/webservices/tempconvert.asmx"
format="soap11"/>
</endpoint>
</target>
<description/>
</proxy>
But i am getting the exception like this
`[2014-03-20 18:19:02,391] INFO - LogMediator To: /services/JsonToXMLProxy.JsonToXMLProxyHttpEndpoint, MessageID: urn:uuid:a2eeeb26-94e1-4ed1-a3f9-79f1d1461821, Direction: request, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/"><Celsius>20</Celsius></CelsiusToFahrenheit></soapenv:Body></soapenv:Envelope>
[2014-03-20 18:19:03,130] WARN - ClientHandler Received an unexpected response - of content type : text/html and status code : 411 with reason : Length Required For : 172.26.40.214:8080 For Request : Axis2Request [Message ID : urn:uuid:39d47344-f74c-4ec5-855b-5eb90e178b6d] [Status Completed : true] [Status SendingCompleted : true]
[2014-03-20 18:19:04,133] INFO - BuilderUtil OMException in getSOAPBuilder
org.apache.axiom.om.OMException: SOAP message MUST NOT contain a Document Type Declaration(DTD)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createDTD(StAXSOAPModelBuilder.java:462)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:282)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:140)
at org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:659)
at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:198)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:146)
at org.apache.synapse.transport.nhttp.ClientWorker.run(ClientWorker.java:253)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
[2014-03-20 18:19:04,137] INFO - BuilderUtil Remaining input stream :[]
[2014-03-20 18:19:04,137] WARN - ClientWorker Unexpected response received. HTTP response code : 411 HTTP status : Length Required exception : SOAP message MUST NOT contain a Document Type Declaration(DTD)
[2014-03-20 18:19:04,153] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:39d47344-f74c-4ec5-855b-5eb90e178b6d, Direction: response, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>411</faultcode><faultstring>Unexpected response received. HTTP response code : 411 HTTP status : Length Required exception : SOAP message MUST NOT contain a Document Type Declaration(DTD)</faultstring><detail>Unexpected response received. HTTP response code : 411 HTTP status : Length Required exception : SOAP message MUST NOT contain a Document Type Declaration(DTD)</detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>`
Please help me for this issue
Thanks in advance.
you could use this example using de payloadfactory mediator to build the messages, it work for me in your scenario:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JsonToXMLProxy"
transports="https http local"
startOnLoad="true"
trace="disable">
<description/>
<target>
<endpoint>
<address uri="http://www.w3schools.com/webservices/tempconvert.asmx" format="soap11"/>
</endpoint>
<inSequence>
<log>
<property name="TEMPERATURA_ENTRADA" expression="json-eval($.celsius)"/>
</log>
<payloadFactory media-type="xml">
<format>
<web:CelsiusToFahrenheit xmlns:web="http://www.w3schools.com/webservices/">
<web:Celsius>$1</web:Celsius>
</web:CelsiusToFahrenheit>
</format>
<args>
<arg evaluator="json" expression="$.celsius"/>
</args>
</payloadFactory>
<header name="Action"
value="http://www.w3schools.com/webservices/CelsiusToFahrenheit"/>
</inSequence>
<outSequence>
<log>
<property xmlns:p="http://www.w3schools.com/webservices/"
name="TEMPERATURA_SALIDA"
expression="//p:CelsiusToFahrenheitResponse/p:CelsiusToFahrenheitResult"/>
</log>
<payloadFactory media-type="json">
<format>
"Temperatura" : {
"EnFahrenheit" : $1
}
</format>
<args>
<arg xmlns:p="http://www.w3schools.com/webservices/"
evaluator="xml"
expression="//p:CelsiusToFahrenheitResponse/p:CelsiusToFahrenheitResult"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
</target>
</proxy>