ODE provides an extension mechanism that permits "interception" of message exchanges that enter or leave the ODE server. An incoming message exchange (my-role message exchange) can be intercepted at various points: when it first enters the system, when it is routed to a process, and when it is routed to a particular process instance. An outgoing message-exchange (partner-role message exchange) can be intercepted right before it exits the system. A message-exchange interceptor is invoked at these points in the life of a message exchange and can be used to alter the course of execution (e.g. by causing the message exchange to be failed).
This text is a quick summary of this mechanism.
A message exchange interceptor is a Java class that implements the org.apache.ode.bpel.intercept.MessageExchangeInterceptor interface. This class must provide a no-arg constructor.
For example, an interceptor that limits the number of process instances that can be created for a process to 5, would look like this:
public class ThrottlingInterceptor implements MessageExchangeInterceptor {
public void onNewInstanceInvoked(MyRoleMessageExchange mex, InterceptorContext ic)
throws FailMessageExchangeException
{
if (ic.getProcessDAO().getNumInstances() >= 5)
throw new FailMessageExchangeException("Too many instances.");
}
public void onBpelServerInvoked(MyRoleMessageExchange mex, InterceptorContext ic)
throws FailMessageExchangeException, FaultMessageExchangeException {}
public void onProcessInvoked(MyRoleMessageExchange mex, InterceptorContext ic)
throws FailMessageExchangeException, FaultMessageExchangeException {}
public void onPartnerInvoked(PartnerRoleMessageExchange mex, InterceptorContext ic)
throws FailMessageExchangeException, FaultMessageExchangeException {}
}
A more elaborate version of this interceptor can be found in the ODE distribution, in the org.apache.ode.bpel.intercept.ThrottlingInteceptor class.
Message exchange interceptors are associated with a particular process via the process's deployment descriptor. For example, a message exchange interceptor named com.myco.MyInterceptor could be associated with the HelloWorld2 example process by modifying the deploy.xml file to:
<deploy xmlns="http:
xmlns:pns="urn:/HelloWorld2.bpel"
xmlns:sns="urn:/HelloWorld2.wsdl">
<process name="pns:HelloWorld2">
<active>true</active>
<provide partnerLink="helloPartnerLink">
<service name="sns:HelloService" port="HelloPort"/>
</provide>
<mex-interceptors>
<mex-interceptor>
<class-name>com.myco.MyInterceptor</class-name>
</mex-interceptor>
</mex-interceptors>
</process>
</deploy>
Any number of interceptors may be associated with a process, by placing additional <mex-interceptor> under the <mex-interceptors> element.