Annotation Type ServerRequestFilter
-
@Retention(RUNTIME) @Target(METHOD) public @interface ServerRequestFilter
When used on a method, then an implementation ofContainerRequestFilter
is generated that calls the annotated method with the proper argumentsThe 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 withServerRequestFilter
can declare any of the following parameters (in any order)ContainerRequestContext
UriInfo
HttpHeaders
Request
ResourceInfo
SimpleResourceInfo
void
,Response
,RestResponse
,Optional<Response>
,Optional<RestResponse>
,Uni<Void>
,Uni<Response>
orUni<RestResponse>
.void
should be used when filtering does not need to perform any blocking operations and the filter cannot abort processing.Response
orRestResponse
should 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 theOptional
contains aResponse
payload.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 theUni
contains aResponse
payload.
ContainerRequestContext
is used as a request parameter, callingabortWith
is not allowed. You should use the proper response type if aborting processing is necessary.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description boolean
nonBlocking
NormallyContainerRequestFilter
classes 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.boolean
preMatching
Whether the filter is a pre-matching filter Note that this setting andreadBody()
cannot be both set to true.int
priority
The priority with which this request filter will be executedboolean
readBody
If set totrue
, the filter will be run after the body has been fully read but before any deserialization takes place.
-
-
-
-
preMatching
boolean preMatching
Whether the filter is a pre-matching filter Note that this setting andreadBody()
cannot be both set to true.- Default:
- false
-
-
-
nonBlocking
boolean nonBlocking
NormallyContainerRequestFilter
classes 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 totrue
if 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
boolean readBody
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 andpreMatching()
cannot be both set to true.- Default:
- false
-
-