Annotation Type ServerRequestFilter
-
@Retention(RUNTIME) @Target(METHOD) public @interface ServerRequestFilter
When used on a method, then an implementation ofContainerRequestFilteris generated that calls the annotated method with the proper argumentsThe idea behind using this is to make it much to write a
ServerRequestFilteras all the necessary information is passed as arguments to the method instead of forcing the author to use a mix of@Contextand 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 withServerRequestFiltercan declare any of the following parameters (in any order)ContainerRequestContextUriInfoHttpHeadersRequestResourceInfoSimpleResourceInfo
void,Response,RestResponse,Optional<Response>,Optional<RestResponse>,Uni<Void>,Uni<Response>orUni<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.
ContainerRequestContextis used as a request parameter, callingabortWithis 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 booleannonBlockingNormallyContainerRequestFilterclasses 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.booleanpreMatchingWhether the filter is a pre-matching filter Note that this setting andreadBody()cannot be both set to true.intpriorityThe priority with which this request filter will be executedbooleanreadBodyDeprecated.useWithFormReadon your filter to force reading the form values before your filter is invoked.
-
-
-
-
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
NormallyContainerRequestFilterclasses 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 boolean 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 andpreMatching()cannot be both set to true.- Default:
- false
-
-