I am using Jersey (v1.18.1) to provide REST Api, and I need:
- Use Spring Bean in my Api using Spring Framework (v3.2.9),
- Use Query and Response Filters to save some header values in MDC or ThreadLocal.
In this link, Mkyong has a great example with com.sun.jersey.contribs: jersey-spring jar (see jersey-spring example ).
I followed it and added the following lines in the tags <init-param>for the query filter in the web.xml file:
<webapp>
.
<servlet>
.
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>org.sample.rest.SampleRestRequestHeaderFilter</param-value>
</init-param>
.
</servlet>
.
</webapp>
and my Api class was as below:
@Component
@Path("/sample")
public class SampleApi {
@Autowired
private SomeBean someBean;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/health")
public Response getHealthy() {
String output = someBean.getStrValue();
return Response.status(Response.Status.OK)
.entity(output)
.build();
}
}
, API ; , , .
- ? ContainerRequestFilter ContainerResponseFilter Spring