@Retention(value=RUNTIME) @Target(value=METHOD) public @interface ServerRequestFilter
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)
ContainerRequestContext
UriInfo
HttpHeaders
Request
ResourceInfo
SimpleResourceInfo
void
, Response
, Optional<Response>
,
Uni<Void>
or
Uni<Response>
.
void
should be used when filtering does not need to perform any blocking operations and the filter cannot abort
processing.
Response
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 not null
.
Optional<Response>
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 the Optional
contains a Response
payload.
Uni<Void>
should be used when filtering needs to perform a blocking operations but the filter cannot abort
processing.
Note that Uni<Void>
can easily be produced using: Uni.createFrom().nullItem()
Uni<Response>
should be used when filtering needs to perform a blocking operations and the filter
might abort processing - in this case processing is aborted when the Uni
contains a Response
payload.
ContainerRequestContext
is used as a request parameter, calling
abortWith
is not allowed. You should use the proper response type if aborting processing is necessary.Modifier and Type | Optional Element and Description |
---|---|
boolean |
preMatching
Whether or not the filter is a pre-matching filter
|
int |
priority
The priority with which this request filter will be executed
|
Copyright © 2021 JBoss by Red Hat. All rights reserved.