In Chapter 12, you learned how filters and interceptors can be used to augment your JAX-RS service classes. In this chapter, we through how to build and run some of the examples shown in that chapter. Specifically, we’ll go write a
DynamicFeature, and an implementation of a
WriterInterceptor. If you want to see examples of a
ClientRequestFilter and a
ContainerRequestFilter bound via a
@NameBinding, check out Chapter 29.
Example ex12_1 : ContainerResponseFilter and DynamicFeature
ex12_1 implements the
CacheControlFilter example in the section DynamicFeature.
The Server Code
MaxAgeFeature classes were explained pretty well in DynamicFeature, so I’m not going to go into them again here. We applied the
@MaxAge annotation to the
Applying this annotation to this method will cause the
CacheControlFilter to be bound to this method when it is executed. The filter will cause a
Cache-Control header to be added to the HTTP response with a max age of 500 seconds. Let’s also take a look at how these classes are registered: