Project

General

Profile

Revision 30acb146

ID30acb14610a8a4b98b3d21aca16ca1f6c0cea039
Parent 046b8cfb
Child 47c1bab5

Added by Andreas Kohlbecker 7 months ago

ref #8706 DateHeaderFilter to add Date headers to all servelet responses

View differences:

cdmlib-remote-webapp/src/main/java/eu/etaxonomy/cdm/remote/DateHeaderFilter.java
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.remote;
10

  
11
import java.io.IOException;
12
import java.time.OffsetDateTime;
13
import java.time.format.DateTimeFormatter;
14

  
15
import javax.servlet.Filter;
16
import javax.servlet.FilterChain;
17
import javax.servlet.FilterConfig;
18
import javax.servlet.ServletException;
19
import javax.servlet.ServletRequest;
20
import javax.servlet.ServletResponse;
21
import javax.servlet.http.HttpServletResponse;
22

  
23
/**
24
 * Adds a "Date" Header to the http response formatted as RFC_1123_DATE_TIME.
25
 *
26
 * https://tools.ietf.org/html/rfc2616#section-14.18
27
 *
28
 * @author a.kohlbecker
29
 * @since Jan 17, 2020
30
 *
31
 */
32
public class DateHeaderFilter implements Filter {
33

  
34
    /**
35
     * {@inheritDoc}
36
     */
37
    @Override
38
    public void init(FilterConfig filterConfig) throws ServletException {
39
        // Nothing to do
40
    }
41

  
42
    /**
43
     * {@inheritDoc}
44
     */
45
    @Override
46
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
47
            throws IOException, ServletException {
48

  
49
        OffsetDateTime dateTime = OffsetDateTime.now();
50
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
51
        httpServletResponse.setHeader("Date", dateTime.format(DateTimeFormatter.RFC_1123_DATE_TIME));
52
        chain.doFilter(request, response);
53

  
54
    }
55

  
56
    /**
57
     * {@inheritDoc}
58
     */
59
    @Override
60
    public void destroy() {
61
        // Nothing to do
62
    }
63

  
64
}
cdmlib-remote-webapp/src/main/webapp/WEB-INF/web.xml
58 58
    <url-pattern>/*</url-pattern>
59 59
  </filter-mapping>
60 60

  
61
  <filter>
62
       <filter-name>dateHeaderFilter</filter-name>
63
       <filter-class>eu.etaxonomy.cdm.remote.DateHeaderFilter</filter-class>
64
  </filter>
65
    <filter-mapping>
66
    <filter-name>dateHeaderFilter</filter-name>
67
    <url-pattern>/*</url-pattern>
68
  </filter-mapping>
69

  
61 70
  <!-- Remoting Security -->
62 71

  
63 72
  <filter>
......
68 77
    <filter-name>springSecurityFilterChain</filter-name>
69 78
    <url-pattern>/*</url-pattern>
70 79
  </filter-mapping>
71

  
80
  
81
  
72 82
</web-app>

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)