28.2. PreProcessInterceptor

The org.jboss.resteasy.spi.interception.PreProcessInterceptor runs after a JAX-RS resource method is located, but before the method is invoked. They can only be used on the server, but you must still annotate them with @ServerInterceptor. They can be used to implement security features or to preempt the Java request. The RESTEasy security implementation uses these interceptors to abort requests prior to invocation if the user does not pass authorization. The RESTEasy caching framework uses them to return cached responses, to avoid invoking methods multiple times. The interceptor interface is as follows:
    public interface PreProcessInterceptor
    {
       ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException;
    }

PreProcessInterceptors run in sequence and do not wrap the actual JAX-RS invocation. To illustrate:
    for (PreProcessInterceptor interceptor : preProcessInterceptors) {
       ServerResponse response = interceptor.preProcess(request, method);
       if (response != null) return response;
    }
    executeJaxrsMethod(...);
If the preProcess() method returns a ServerResponse then the underlying JAX-RS method will not be invoked and the runtime will process the response and return to the client.