0
votes

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?

2

2 Answers

1
votes

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

0
votes

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...