Generating ETAG using spring boot

user873888 picture user873888 · May 20, 2015 · Viewed 8.1k times · Source

I'm new to spring boot. I want to generate ETAG whenever perform a POST from my controller class.

Below is the configuration class created:

@Configuration
public class WebConfiguration {
    @Bean
    public Filter shallowEtagHeaderFilter() {
        return new ShallowEtagHeaderFilter();
    }
}

My main class is annotated with @EnableAutoConfiguration. As per my understanding, the response object that I receive from POST should provide me the ETAG header. Please can anyone provide a spring boot sample to generate ETag during my POST/GET?PUT call.

Answer

adam p picture adam p · May 21, 2015

The ShallowEtagHeaderFilteryou are using will only generate an ETag in response to a GET request.

When you perform a GET on the resource you just created/updated, the ETag header will be present.

It is also worth nothing that if you are making use of the Spring Repository REST exporter (i.e. Spring Data Rest), then it has ETag support built in. All that is required is for your entity classes to have a Long or Timestamp field annotated with @javax.persistence.Version