Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Request Interceptors

 

Request interceptors provide a way to intercept, stop, or modify a request at runtime. They are not configured via Annotations but added via configuration instead. They can be added or removed at runtime without restart.

There are two different kinds of interceptors: client and server side. The interfaces looks like:

Code Block
public interface ClientSideRequestInterceptor {
 /**
 * Called before anything is happening in the stub. Effectively this interceptor is called before routing or failing took place.
 * @return
 */
 InterceptorResponse beforeClientProcessing(ClientSideCallContext context);
 /**
 * Called after client side processing but before the actual call is performed.
 * @return
 */
 InterceptorResponse beforeServiceCall(ClientSideCallContext context);
 /**
 * Called immediately after service call, but before anything is returned to the caller. This interceptor can be used to inspect or modify the answer from server.
 * @param context
 * @param returnValue
 * @return
 */
 InterceptorResponse afterServiceCall(ClientSideCallContext context, Object returnValue);
 
 }

Code Block
public interface ServerSideRequestInterceptor {
 /**
 * Called before any real processing happens on the server side. 
 * @param context
 * @return
 */
 InterceptorResponse beforeServiceCall(ServerSideCallContext context);
 /**
 * Called after the service actually processed the request. Allows to inspect or modify the answer.
 * @param context
 * @return
 */
 InterceptorResponse afterServiceCall(ServerSideCallContext context, Object returnValue);
 }


 

The InterceptorResponse itself looks like:

Code Block
 public class InterceptorResponse {
 public static enum InterceptorCommand{
 /**
 * Proceed with request.
 */
 CONTINUE, 
 /**
 * Abort the request, an exception should be attached to this response and thrown by the DiMe code. 
 */
 ABORT,
 /**
 * Don't further process the call and return a preset value instead. 
 */
 RETURN;
 };
  .... more code follows 
 }


 

Interceptors are re/configured via ConfigureMe in distributeme.json. They get two additional fields, clientSideInterceptors and serverSideInterceptors. There is no built-in targeting of interceptors per service, instead the interceptors can decide by themselves if they want to intercepts requests based on service ids. Further targeting can be achieved by supplying a more specific ConfigureMe environment  for each service.

 

One Phase Interceptors

For easier implementation of OnePhase Interceptors (Interceptors which are only interested in one of the possible phase) a special, simplified interface will be added later.