Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
13.9. RESTEasy Interceptors
13.9.1. Intercept JAX-RS Invocations Link kopierenLink in die Zwischenablage kopiert!
RESTEasy can intercept JAX-RS invocations and route them through listener-like objects called interceptors. This topic covers descriptions of the four types of interceptors.
Example 13.3. MessageBodyReader/Writer Interceptors
@Provider
, as well as either @ServerInterceptor
or @ClientInterceptor
so that RESTEasy knows whether or not to add them to the interceptor list.
MessageBodyReader.readFrom()
or MessageBodyWriter.writeTo()
. They can be used to wrap the Output or Input streams.
MessageBodyReaderContext.proceed()
or MessageBodyWriterContext.proceed()
is called in order to go to the next interceptor or, if there are no more interceptors to invoke, the readFrom()
or writeTo()
method of the MessageBodyReader or MessageBodyWriter. This wrapping allows objects to be modified before they get to the Reader or Writer, and then cleaned up after proceed()
returns.
Example 13.4. PreProcessInterceptor
public interface PreProcessInterceptor { ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException; }
public interface PreProcessInterceptor
{
ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException;
}
preProcess()
method returns a ServerResponse then the underlying JAX-RS method will not get invoked, and the runtime will process the response and return to the client. If the preProcess()
method does not return a ServerResponse, the underlying JAX-RS method will be invoked.
Example 13.5. PostProcessInterceptors
public interface PostProcessInterceptor { void postProcess(ServerResponse response); }
public interface PostProcessInterceptor
{
void postProcess(ServerResponse response);
}
Example 13.6. ClientExecutionInterceptors
@ClientInterceptor
and @Provider
. These interceptors run after the MessageBodyWriter, and after the ClientRequest has been built on the client side.