Access Sequence using a Java Class mediator in WSO2 MI/EI

Isuru Liyanage
CodeBlog
Published in
2 min readOct 24, 2023

In the article, I'm going to show you how to invoke a sequence that is deployed in the WSO2 MI server via a custom class mediator.

We are going to use org.apache.synapse.Mediator to invoke the sequence that is deployed in the MI server.

First, we are going to create a mediator project via WSO2 Integration Studio

After that, we are going to import the org.apache.synapse.Mediator to the java class so we can create an object of org.apache.synapse.Mediator to get and invoke the sequence from the custom Java class.

 Mediator sequenceMediator = context.getSequence("WorkflowCallbackService");

In the above code, we have created an object named “sequenceMediator” and from the context we are getting the sequence named “WorkflowCallbackService” which is deployed in the MI server.

After that, we are going to invoke this sequence using the mediate method as below.

    sequenceMediator.mediate(context);

From this method, the custom Java class will invoke the sequenceMediator which is deployed in the MI server.

Below is the full code snippet for this example :

package LdapProject;

import org.apache.synapse.MessageContext;


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


public class Ldap extends AbstractMediator {

public boolean mediate(MessageContext context) {
System.out.println("Mediation Start");


try {
// get the sequence from message context
Mediator sequenceMediator = context.getSequence("WorkflowCallbackService");
if (sequenceMediator != null) {
// Mediate the sequence
sequenceMediator.mediate(context);
} else {
log.error("Sequence not found");
// You can handle this case as needed
}
} catch (Exception e) {
log.error("Error while invoking sequence: " + e);
// You can handle the exception as needed
}

return true;
}
}

Note :

  • If there are Call mediators used inside the sequence, this approach is not recommended

--

--