Constraining an Interceptors Placement in a Phase

Placing an interceptor into a phase may not provide fine enough control over its placement to ensure that the interceptor works properly. For example, if an interceptor needed to inspect the SOAP headers of a message using the SAAJ APIs, it would need to run after the interceptor that converts the message into a SAAJ object. There may also be cases where one interceptor consumes a part of the message needed by another interceptor. In these cases, a developer can supply a list of interceptors that must be executed before their interceptor and another list of interceptors that must be executed after their interceptor.

One issue that arises when developing an interceptor is that the data required by the interceptor is not always present. This can occur when one interceptor in the chain consumes message data required by a later interceptor. Developers can control what a custom interceptor consumes and possibly fix the problem by modifying their interceptors. However, this is not always possible because a number of interceptors are used by FUSE Services Framework and a developer cannot modify them.

An alternative solution is to ensure that a custom interceptor is placed before any interceptors that will consume the message data the custom interceptor requires. The easiest way to do that would be to place it in an earlier phase, but that is not always possible. For cases where an interceptor needs to be placed before one or more other interceptors the FUSE Services Framework's AbstractPhaseInterceptor class provides two addBefore() methods.

As shown in Example 3.2, “Methods for Adding an Interceptor Before Other Interceptors”, one takes a single interceptor id and the other takes a collection of interceptor ids. You can make multiple calls to continue adding interceptors to the list.


As shown in Example 3.3, “Specifying a List of Interceptors that Must Run After the Current Interceptor”, a developer calls the addBefore() method in the constuctor of a custom interceptor.


Tip

Most interceptors in the FUSE Services Framework runtime use their class name for an interceptor id.

Another reason that the data required by the interceptor is not present is because the data has not been placed in the message object. For example an interceptor may want to work with the message data as a SOAP message, but if it is placed in the chain before the message is turned into a SOAP message it will not work. Developers can control what a custom interceptor consumes and possibly fix the problem by modifying their interceptors. However, this is not always possible because a number of interceptors are used by FUSE Services Framework and a developer cannot modify them.

An alternative solution is to ensure that a custom interceptor is placed after the interceptor, or interceptors, that generate the message data the custom interceptor requires. The easiest way to do that would be to place it in a later phase, but that is not always possible. For cases where an interceptor needs to be placed after one or more other interceptors the FUSE Services Framework's AbstractPhaseInterceptor class provides two addAfter() methods.

As shown in Example 3.4, “Methods for Adding an Interceptor After Other Interceptors”, one takes a single interceptor id and the other takes a collection of interceptor ids. You can make multiple calls to continue adding interceptors to the list.


As shown in Example 3.5, “Specifying a List of Interceptors that Must Run Before the Current Interceptor”, a developer calls the addAfter() method in the constuctor of a custom interceptor.


Tip

Most interceptors in the FUSE Services Framework runtime use their class name for an interceptor id.