Question

I make a custom mediator that simply print "Hello World" my custom mediator look like this :

public class HelloWorld extends AbstractMediator implements ManagedLifecycle{

public static void helloWorld() {
    System.out.println("Hello World");  
}

public void init(SynapseEnvironment synapseEnvironment) {
    // initializing  surcharges map with some symbols
    helloWorld();
}

public void destroy() {
    // clearing the surcharges contents

}

@Override
public boolean mediate(MessageContext arg0) {
    // TODO Auto-generated method stub
    return false;
}

}

i call this class in sequence called "Hello" :

   <sequence name="Hello">
  <class name="com.exec.HelloWorld">
  </class>

and i use this sequence in proxy like this :

<proxy xmlns="http://ws.apache.org/ns/synapse" name="FileProxy" transports="vfs" startOnLoad="true" trace="disable">
<target>
    <inSequence>
        <log level="full"/>
            <target sequence="Hello"/>
    </inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">15</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///Users/Source</parameter>
<parameter name="transport.vfs.FileURI">file:///Users/Target/</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>

I expect that everytime i put a file (*.txt) in the Source folder than my sequence will be called. But the problem is the sequence is only called once (when the wso2 esb Startup). How can i make my sequence to be called every time I put a file in the Source folder?

Thanks,

Was it helpful?

Solution

I think it is working as expected, but I think you missunderstood how it works your custom mediator. The message you see is the one showed by the init method, this is when the meditor is created.

This mediator is running everytime you left a file in the folder but the method launched when it happens is "mediator" methos, which implementation does nothing (retrun false). So you should implement mediator method as

public boolean mediate(MessageContext arg0) {
    hellowWorld();
    return false;
}

and it will show the message as you expect.

Hope it works!

OTHER TIPS

You should call your logic inside mediate method(). And make the return value as true. If you make that as false, mediation engine will return false in the mediation process, and it makes issue in the message flow. You can check this sample

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