Question

hello I have the following class mediator created through Carbon Studio:

 package my.mediation;

    import org.apache.synapse.MessageContext; 
    import org.apache.synapse.mediators.AbstractMediator;

    public class Auth extends AbstractMediator { 


        public boolean mediate(MessageContext context) { 
            // TODO Implement your mediation logic here 

            context.setProperty("message","hello world!" );

            return true;
        }

}

And the sequence is like:

<inSequence xmlns="http://ws.apache.org/ns/synapse">
   <property name="message" value="nothing" scope="default" />
   <class name="my.mediation.Auth" />
   <log>
      <property name="Message******" expression="get-property('message')" />
   </log>
</inSequence

> The problem is that instead of printing Message: "HelloWorld" it always print the text "nothing"...Any suggestion?

Was it helpful?

Solution

Your scenario is perfectly valid one and your configuration also seems to be fine.

I have tied your scenario and it works fine for me.

Following are my configurations.

Class Mediator:

package org.wso2.mediator;

import org.apache.synapse.MessageContext; 
import org.apache.synapse.mediators.AbstractMediator;

public class SampleMediator extends AbstractMediator { 

    public boolean mediate(MessageContext context) { 
        context.setProperty("Message", "HelloWorld!");
        return true;
    }
}

My proxy service:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="SimpleProxy"
    statistics="disable" trace="disable" transports="http,https">
    <target>
        <inSequence>
            <log category="INFO" level="simple" separator=","/>
            <property action="set" name="Message" scope="default"
                type="STRING" value="DefaultMessage"/>
            <class name="org.wso2.mediator.SampleMediator"/>
            <log category="INFO" level="simple" separator=",">
                <property expression="get-property('Message')" name="===========Message Value=========="/>
            </log>
            <drop/>
        </inSequence>
    </target>
</proxy>

When I invoke the proxy service without the class mediator, it prints

INFO - LogMediator To: /services/SimpleProxy.SimpleProxyHttpSoap12Endpoint,WSAction: urn:mediate,SOAPAction: urn:mediate,MessageID: urn:uuid:81150094-cbc4-44f7-83eb-251e28149564,Direction: request,===========Message Value========== = DefaultMessage

and when I invoke the proxy service with the class mediator it prints,

INFO - LogMediator To: /services/SimpleProxy.SimpleProxyHttpSoap12Endpoint,WSAction: urn:mediate,SOAPAction: urn:mediate,MessageID: urn:uuid:e3a04341-907c-40fe-9f58-5a10d2ce346a,Direction: request,===========Message Value========== = HelloWorld!

Hope this helps!

Harshana

OTHER TIPS

The problem is based in the log4j.properties. Your class is in the package my.mediation; which does not exist in the log4j.properties. You need to go to the YOUR_WSO2/lib/log4j.properties and add the level of the log for your namespace/package:

...
log4j.logger.org.wso2=INFO
log4j.logger.my.mediation=DEBUG

Here you see also why the example from Harashana worked - he just changed the package to org.wso2 - which you should not do for your own custom mediators.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top