Implement MessageBodyReader and MessageBodyWriter Interceptors
To implement one you implement the org.jbos.resteasy.spi.interception.MessageBodyReaderInterceptor or MessageBodyWriterInterceptor public interface MessageBodyReaderInterceptor { Object read(MessageBodyReaderContext context) throws IOException, WebApplicationException; } public interface MessageBodyWriterInterceptor { void write(MessageBodyWriterContext context) throws IOException, WebApplicationException; } Interceptors are driven by the MessageBodyWriterContext or MessageBodyReaderContext. The interceptors and the MessageBodyReader or Writer is invoked in one big Java call stack. You must call MessageBodyReaderContext.proceed() or MessageBodyWriterContext.proceed() 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 you to modify things before they get to the Reader or Writer then clean up after proceed() returns. The Context objects also have methods to modify the parameters going to the Reader or Writer. public interface MessageBodyReaderContext { Class getType(); void setType(Class type); Type getGenericType(); void setGenericType(Type genericType); Annotation[] getAnnotations(); void setAnnotations(Annotation[] annotations); MediaType getMediaType(); void setMediaType(MediaType mediaType); MultivaluedMap getHeaders(); InputStream getInputStream(); void setInputStream(InputStream is); Object proceed() throws IOException, WebApplicationException; } public interface MessageBodyWriterContext { Object getEntity(); void setEntity(Object entity); Class getType(); void setType(Class type); Type getGenericType(); void setGenericType(Type genericType); Annotation[] getAnnotations(); void setAnnotations(Annotation[] annotations); MediaType getMediaType(); void setMediaType(MediaType mediaType); MultivaluedMap getHeaders(); OutputStream getOutputStream(); public void setOutputStream(OutputStream os); void proceed() throws IOException, WebApplicationException; } MessageBodyReaderInterceptors and MessageBodyWriterInterceptors can be used on the serverside or client side. They must be annotated with @org.jboss.resteasy.annotations.interception.ServerInterceptor or @org.jboss.resteasy.annotations.interception.ClientInterceptor so that resteasy knows whether or not to add them to the interceptor list. If you do not annotate your interceptor classes with one or both of these annotations, you will receive a deployment error. They also should be annotated with @Provider.