Tuesday, March 2, 2010

ESB Interceptor

I guess I am pretty late on this blog, I had this working 2 years ago, and implemented it for more than 2 clients over last two years and now probably does not value that much. I still thought to share it and it is a little bit documented in http://download.oracle.com/docs/cd/E12524_01/relnotes.1013/e12523/esb.htm as well.

Basically, implementing IEsbMessageInterceptor interface, which looks something like this (You probably have to tweak it little bit as IEsbMessageInterceptor has been changed from 10.1.3.4 to 10.1.3.5).

public class CustomESBInterceptor implements IEsbMessageInterceptor {
public CustomESBInterceptor() {
System.out.println("Initializing Custome Interceptor");
}

public void invoke(FlowId pFlowId, String pInstanceId, Element pPayload, Element pHeader, String pServiceName, String pSystemName, boolean isOutbound) {
System.out.println("----------------------------------------");
System.out.println("Custom Interceptor ");
System.out.println("FlowId: " + pFlowId + " subflowid: " + pFlowId.getSubFlowId() );
System.out.println("instanceid: " + pInstanceId);
System.out.println("Header: " + XMLHelper.toXML(pHeader));
System.out.println("payload: " + XMLHelper.toXML(pPayload));
System.out.println("Service: " + pServiceName);
System.out.println("System: " + pSystemName);
System.out.println("----------------------------------------");
}
}

Once we compile this class, we can put the class in bpel/system/classes directory and add following to $ORALCE_HOME/integration/esb/config/esb_config.ini file:

inboundMessageInterceptor = CustomESBInterceptor
outboundMessageInterceptor = CustomESBInterceptor

Just to clarify, just like any other interceptor this is extreamly dangerous point. We should keep following things in mind:
  • Call from ESB runtime to this interceptor is made in synchronous fashion, so if CustomESBInterceptor.invoke errors out, then entire ESB RT will have issues.
  • Another issue is if we are doing any heavy processing in CustomESBInterceptor.invoke, that will affect performance of entire ESB RT. The code in invoke should be absolutely error free and as quick as possible. We should use AQ or another JMS implementation to avoid real time processing if needed.
  • You can possibly change the payload and header values if you want to (it should be avoided for best practices)

1 comment:

Vinod Reddy said...

This is vinod, from past couple of days to implement the interceptor concept in esb but about the concept i never heard and tried in google but not able to find the correct exaample
Can you help me on this issue.

Thanks in Advance