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...
Related
I've created JMS sender in WSO2 ESB 4.9.0 as below and configured JMS sender in axis2.xml file. I'm getting the below exception when I run the proxy service. Using Websphere MQ JMS queues.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="StockQuoteProxy"
transports="http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint>
<address uri="jms:/myquue?transport.jms.ConnectionFactory=ConnectionFactory"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>
javax.naming.NameNotFoundException: Name [dynamicQueues/myqueue] is not bound in this Context. Unable to find [dynamicQueues]
In my scenario using the WSO2 MB, the correct endpoint it´s this:
<address uri="jms:/MyQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=repository/conf/jndi.properties&transport.jms.DestinationType=queue"/>
Your proxy config use:
<property name="OUT_ONLY" value="true"/>
So, no response is sent to the client.
You need to specify a WSDL in the proxy config with an operation that does not have a response message or return a status = 200 with:
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
how I can call web service inside of proxy? Proxy itself works fine, and I added call of logging web service in "in" sequence. I create call using payload factory + send.
Problem is, that proxy now returns result of this logging web service instead of
what web service should return. There is address end point defined in "out" sequence.
I am using WSO2 ESB 4.6.0.
This is the simple example of calling web service inside of the proxy. You need to up back-end service before create the proxy
<proxy xmlns="http://ws.apache.org/ns/synapse" name="customPro" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</inSequence>
<out-sequence>
<send/>
</outSequence>
</target>
<publishWSDL uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
<description></description>
</proxy>
You need to define web service url within the end-point in tag
As well as, this kind of send mediator return end-point response to outSequence
by default.
You can get good understanding of these if you go through the ESB documentation from following url
http://docs.wso2.org/display/ESB460/Samples
If you need further help, feel free to ask here
There are two ways you can achieve the logs
1. Log ESB incoming and outgoing messages through wire log.
To enable debug mode for wire logs;
- ESB console > Configure > Logging
- Set “org.apache.synapse.transport.http.wire” level to “DEBUG”.
In the log, it indicates >> incoming messages to ESB
<< outgoing messages from ESB
2. Use Logs at the appropriate place
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="test" value="incomming to ESB-----------------------"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
<log level="full">
<property name="test" value="outcomming from ESB-----------------------"/>
</log>
</inSequence>
<outSequence>
<log level="full">
<property name="test" value="incomming to ESB-----------------------"/>
</log>
<send/>
<log level="full">
<property name="test" value="outcomming from ESB-----------------------"/>
</log>
</outSequence>
</target>
<publishWSDL uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
<description/>
</proxy>
If it is resolve your problem, please flag as answered.
I'm trying to send a message through WSO2 ESB 4.6.0 using MessageProcessor:
Proxy->Proxy(Store)->Processor->Sequence->Proxy
I set a property ('transport' scope) in Proxy #1, send it to Proxy #2 where I can successfully log it, but then I pass the message to Proxy #3 through Sampling Processor and the property is getting lost.
Is this a bug? How can I send 'transport' property via Processor?
I expect value_1 to appear instead of null in Proxy_3.
<messageProcessor name="Processor_1" class="org.apache.synapse.message.processors.sampler.SamplingProcessor" messageStore="Store_1" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="interval">1000</parameter>
<parameter name="sequence">Sequence_1</parameter>
</messageProcessor>
MessageStore
Store_1 is InMemoryMessageStore
Proxy_1
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy_1" transports="jms" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="my_property_1" value="value_1" scope="transport"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
<endpoint>
<address uri="http://localhost:8280/services/Proxy_2" format="soap11" />
</endpoint>
</target>
<parameter name="transport.jms.Destination">Queue</parameter>
</proxy>
Proxy_2
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy_2" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="preserveProcessedHeaders" value="true"/>
<log level="custom" separator=",">
<property name="my_property_1" expression="get-property('transport', 'my_property_1')"/>
</log>
<store messageStore="Store_1"/>
</inSequence>
</target>
</proxy>
Sequence_1
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Sequence_1">
<send>
<endpoint>
<address uri="http://localhost:8280/services/Proxy_3" format="soap11"/>
</endpoint>
</send>
</sequence>
Proxy_3
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy_3" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="custom">
<property name="my_property_1" expression="get-property('transport', 'my_property_1')"/>
</log>
<send/>
</inSequence>
</target>
</proxy>
Transport properties are passed as HTTP headers. But when you store a message in a queue, it only stores what's available in the message payload, with a content type set to XML. There's no standard way to persist all the custom HTTP header information when saving the message to a queue. You have to enhance the existing message store/processor implementation take account of this additional headers. However, an easier solution would be before storing the message to the queue use enrich mediator to set the header value as a payload element in the message. Then from your proxy, before sending, extract it and create a custom header and send.
As chintana said you have to add it to the payload if you use ESB 4.6.0 or 4.7.0. But we have already fix this to keep the header values when we store the message in the store. It will come with next release.
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>
I've configured a proxy service to run some XSBRL validation stuff that accepts a get request amd return XML validation results. Here's proxy service configuration:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="XBRLValidationRESTService" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<property name="REST_URL_POSTFIX" value="/example.xbrl/validation/xbrl?media=xml" scope="axis2"/>
<property name="HTTP_METHOD" value="GET" scope="axis2"/>
<send>
<endpoint>
<address uri="http://localhost:10000/rest/xbrl" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</target>
<description></description>
</proxy>
In the log file I can see that the underlying service responds with expected response, however the client receives nothing back because ESB fails with NPE for some reason.
Request used from localhost:
curl -k https://localhost:9443/services/XBRLValidationRESTService
Full log: http://pastebin.com/A5jB9wMF
What is the potential reason for that and how that could be fixed.
Thanks,
Vladimir.
Do you run ESB with blocking transport? By default esb uses NIO transport and the port is 8280. your proxy service url, will be;
http://localhost:8280/services/XBRLValidationRESTService
Rather putting log full state, use descriptive logs to identify message paths,