Home Spring Spring3.2 Support for ETag
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Support for ETag

Advertisement
In this section, you will learn about how to use ETag in Spring MVC.

Support for ETag

In this section, you will learn about how to use ETag in Spring MVC.

An entity tag or Etag is part of HTTP which provides web cache validation mechanism. This mechanism saves bandwidth because a full response need not send if content is not modified. HTTP/1.1 supported web server utilize Etag , which is an HTTP response header, to find out changes at provided URL.

It can be a good replacement of Last-Modified header. The client can utilize the Etag header, returned by the server with a representation, in subsequent GETs, in an If-None-Match header. If the content at given URL is not changed, the server returns 304:Not Modified.

Servlet filter ShallowEtagHeaderFilter provides ETag support and since it is a plain Servlet Filter , it can be implement with any framework. The ShallowEtagHeaderFilter cache the JSP/ content and creates an MD5 hash over that and returns MD5 hash as an ETag header in the response.

Next time the same resource is requested by a client, it utilizes that MD5 hash as the If-None-Match value. The filter notices this and view is again render by it. After rendering , it compares the two hashes for equality. If they are equal - 304 is returned. This filter ShallowEtagHeaderFilter doesn't save processing because it renders each time to compare hash. It only saves bandwidth since rendered response is not sent back on the bandwidth.

ShallowEtagHeaderFilter can be configure in the web.xml as below :

<filter>
	<filter-name>etagFilter</filter-name>
	<filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class>
</filter>

<filter-mapping>
	<filter-name>etagFilter</filter-name>
	<servlet-name>XYZ</servlet-name>
</filter-mapping>


Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 31, 2013

Ask Questions?    Discuss: Support for ETag  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com