Java Reference
In-Depth Information
response . getHeaderString ( HttpHeaders . CACHE_CONTROL ));
System . out . println ( "Max age: " + cc . getMaxAge ());
There is nothing really special about this code other than it shows you how to create a
CacheControl object from a header string.
Build and Run the Example Program
Perform the following steps:
1. Open a command prompt or shell terminal and change to the ex12_1 directory of the
workbook example code.
2. Make sure your PATH is set up to include both the JDK and Maven, as described in
Chapter 17 .
3. Perform the build and run the example by typing maven install .
Example ex12_2: Implementing a WriterInterceptor
In this example, we implement support for generating the Content-MD5 header. This header
is defined in the HTTP 1.1 specification. Its purpose is to provide an additional end-to-end
message integrity check of the HTTP message body. While not proof against malicious at-
tacks, it's a good way to detect accidental modification of the message body in transit just in
case it was transformed by a proxy, cache, or some other intermediary. Well, OK, I admit it's
a pretty lame header, but let's show how we can implement support for it using a WriterIn-
terceptor :
public class
class ContentMD5Writer
ContentMD5Writer implements
implements WriterInterceptor
public void
void aroundWriteTo ( WriterInterceptorContext context )
throws IOException , WebApplicationException
MessageDigest digest = null
null ;
digest = MessageDigest . getInstance ( "MD5" );
catch ( NoSuchAlgorithmException e )
throw new
new IllegalArgumentException ( e );
Search WWH ::

Custom Search