Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Este conteúdo não está disponível no idioma selecionado.
58.4. Client Request Filter
Overview Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
This section explains how to implement and register a client request filter, which is used to intercept an outgoing request message on the client side. Client request filters are often used to process headers and can be used for any kind of generic request processing.
ClientRequestFilter interface Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
The
javax.ws.rs.client.ClientRequestFilter
interface is defined as follows:
By implementing the
ClientRequestFilter
, you can create a filter for the ClientRequest
extension point on the client side, which filters the request message before sending the message to the server.
ClientRequestContext interface Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
The
filter
method of ClientRequestFilter
receives a single argument of type javax.ws.rs.client.ClientRequestContext
, which can be used to access the outgoing request message and its related metadata. The ClientRequestContext
interface is defined as follows:
Sample implementation Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
To implement a client request filter for the
ClientRequest
extension point (that is, where the filter is executed prior to sending the request message), define a class that implements the ClientRequestFilter
interface.
For example, the following code shows an example of a simple client request filter that gets installed in the
ClientRequest
extension point, with a priority of 20:
Aborting the invocation Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
It is possible to abort a client-side invocation by implementing a suitable client request filter. For example, you might implement a client-side filter to check whether a request is correctly formatted and, if necessary, abort the request.
The following test code always aborts the request, returning the
BAD_REQUEST
HTTP status to the client calling code:
Registering the client request filter Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
Using the JAX-RS 2.0 client API, you can register a client request filter directly on a
javax.ws.rs.client.Client
object or on a javax.ws.rs.client.WebTarget
object. Effectively, this means that the client request filter can optionally be applied to different scopes, so that only certain URI paths are affected by the filter.
For example, the following code shows how to register the
SampleClientRequestFilter
filter so that it applies to all invocations made using the client
object; and how to register the TestAbortClientRequestFilter
filter, so that it applies only to sub-paths of rest/TestAbortClientRequest
.