Annotation Interface ServerRequestFilter
When used on a method, then an implementation of
ContainerRequestFilter is generated
that calls the annotated method with the proper arguments
The idea behind using this is to make it much to write a ServerRequestFilter 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 CustomContainerRequestFilter {
private final SomeBean someBean;
// SomeBean will be automatically injected by CDI as long as SomeBean is a bean itself
public CustomContainerRequestFilter(SomeBean someBean) {
this.someBean = someBean;
}
@ServerRequestFilter
public void whatever(UriInfo uriInfo, HttpHeaders httpHeaders) {
// do something
}
}
Methods annotated with ServerRequestFilter can declare any of the following parameters (in any order)
ContainerRequestContextUriInfoHttpHeadersRequestResourceInfoSimpleResourceInfo
void, Response, RestResponse,
Optional<Response>, Optional<RestResponse>,
Uni<Void>, Uni<Response> or
Uni<RestResponse>.
voidshould be used when filtering does not need to perform any blocking operations and the filter cannot abort processing.ResponseorRestResponseshould be used when filtering does not need to perform any blocking operations and the filter cannot abort processing - in this case the processing will be aborted if the response is notnull.Optional<Response>orOptional<RestResponse>should be used when filtering does not need to perform any blocking operations but the filter might abort processing - in this case processing is aborted when theOptionalcontains aResponsepayload.Uni<Void>should be used when filtering needs to perform a non-blocking operation but the filter cannot abort processing. Note thatUni<Void>can easily be produced using:Uni.createFrom().nullItem()Uni<Response>orUni<RestResponse>should be used when filtering needs to perform a non-blocking operation and the filter might abort processing - in this case processing is aborted when theUnicontains aResponsepayload.
ContainerRequestContext is used as a request parameter, calling
abortWith
is not allowed. You should use the proper response type if aborting processing is necessary.-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanNormallyContainerRequestFilterclasses are run by RESTEasy Reactive on the same thread as the Resource Method - this means than when a Resource Method is annotated withBlocking, the filters will also be run on a worker thread.booleanWhether the filter is a pre-matching filterintThe priority with which this request filter will be executedbooleanDeprecated.
-
Element Details
-
priority
int priorityThe priority with which this request filter will be executed- Default:
- 5000
-
preMatching
boolean preMatchingWhether the filter is a pre-matching filterNote that this setting and
readBody()cannot be both set to true.- Default:
- false
-
nonBlocking
boolean nonBlockingNormallyContainerRequestFilterclasses are run by RESTEasy Reactive on the same thread as the Resource Method - this means than when a Resource Method is annotated withBlocking, the filters will also be run on a worker thread. This is meant to be set totrueif a filter should be run on the event-loop even if the target Resource method is going to be run on the worker thread. For this to work, this filter must be run before any of the filters when non-blocking is not required.- Default:
- false
-
readBody
Deprecated.useWithFormReadon your filter to force reading the form values before your filter is invoked.If set totrue, the filter will be run after the body has been fully read but before any deserialization takes place.Note that this change only affects Resource Methods that do result in reading the message body. For all other Resource Methods that the filter applies to, it will be executed in normal fashion.
Also note that this setting and
preMatching()cannot be both set to true.- Default:
- false
-
WithFormReadon your filter to force reading the form values before your filter is invoked.