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.3. Container Response 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 container response filter, which is used to intercept an outgoing response message on the server side. Container response filters can be used to populate headers automatically in a response message and, in general, can be used for any kind of generic response processing.
ContainerResponseFilter 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.container.ContainerResponseFilter
interface is defined as follows:
By implementing the
ContainerResponseFilter
, you can create a filter for the ContainerResponse
extension point on the server side, which filters the response message after the invocation has executed.
Note
The container response filter gives you access both to the request message (through the
requestContext
argument) and the response message (through the responseContext
message), but only the response can be modified at this stage.
ContainerResponseContext 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 ContainerResponseFilter
receives two arguments: an argument of type javax.ws.rs.container.ContainerRequestContext
(see the section called “ContainerRequestContext interface”); and an argument of type javax.ws.rs.container.ContainerResponseContext
, which can be used to access the outgoing response message and its related metadata.
The
ContainerResponseContext
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 container response filter for the
ContainerResponse
extension point (that is, where the filter is executed after the invocation has been executed on the server side), define a class that implements the ContainerResponseFilter
interface.
For example, the following code shows an example of a simple container response filter that gets installed in the
ContainerResponse
extension point, with a priority of 10:
Binding the server response filter Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
To bind a server response filter (that is, to install it into the Apache CXF runtime), perform the following steps:
- Add the
@Provider
annotation to the container response filter class, as shown in the following code fragment:Copy to Clipboard Copied! Toggle word wrap Toggle overflow When the container response filter implementation is loaded into the Apache CXF runtime, the REST implementation automatically scans the loaded classes to search for the classes marked with the@Provider
annotation (the scanning phase). - When defining a JAX-RS server endpoint in XML (for example, see Section 16.1, “Configuring JAX-RS Server Endpoints”), add the server response filter to the list of providers in the
jaxrs:providers
element.Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis step is a non-standard requirement of Apache CXF. Strictly speaking, according to the JAX-RS standard, the@Provider
annotation should be all that is required to bind the filter. But in practice, the standard approach is somewhat inflexible and can lead to clashing providers when many libraries are included in a large project.