Annotation Interface ServerResponseFilter


@Retention(RUNTIME) @Target(METHOD) public @interface ServerResponseFilter
When used on a method, then an implementation of ContainerResponseContext is generated that calls the annotated method with the proper arguments

The idea behind using this is to make it much to write a ServerResponseFilter as all the necessary information is passed as arguments to the method instead of forcing the author to use a mix of @Context and programmatic CDI look-ups.

An example filter could look like this:

 public class CustomContainerResponseFilter {

     private final SomeBean someBean;

     // SomeBean will be automatically injected by CDI as long as SomeBean is a bean itself
     public CustomContainerResponseFilter(SomeBean someBean) {
         this.someBean = someBean;
     }

     @ServerResponseFilter
     public void whatever(SimplifiedResourceInfo resourceInfo) {
         // do something
     }
 }
 
Methods annotated with ServerResponseFilter can declare any of the following parameters (in any order)
  • ContainerRequestContext
  • ContainerResponseContext
  • ResourceInfo
  • UriInfo
  • SimpleResourceInfo
  • Throwable - The thrown exception - or null if no exception was thrown
The return type of the method must be either be of type void or Uni<Void>.
  • void should be used when filtering does not need to perform any blocking operations.
  • Uni<Void> should be used when filtering needs to perform a blocking operations.
Another important thing to note is that if ContainerRequestContext is used as a request parameter, calling abortWith is prohibited by the JAX-RS specification.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether the filter can be cancelled when the client drops the connection.
    int
    The priority with which this response filter will be executed
  • Element Details

    • priority

      int priority
      The priority with which this response filter will be executed
      Default:
      5000
    • cancellable

      boolean cancellable
      Whether the filter can be cancelled when the client drops the connection. Set to false to ensure this filter runs even when the client closes the connection before the response is completed.
      Default:
      true