2 * Copyright (C) 2022 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.filter;
19 import java.io.IOException;
20 import javax.faces.application.ResourceHandler;
21 import javax.servlet.Filter;
22 import javax.servlet.FilterChain;
23 import javax.servlet.FilterConfig;
24 import javax.servlet.ServletException;
25 import javax.servlet.ServletRequest;
26 import javax.servlet.ServletResponse;
27 import javax.servlet.annotation.WebFilter;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
32 * A filter for no-caching of JSF requests send from client. This class was
33 * taken from stackoverflow.com at
34 * https://stackoverflow.com/questions/3642919/javax-faces-application-viewexpiredexception-view-could-not-be-restored
35 * and was slightly expanded with "final" keyword and comments
37 * @author Bauke "BalusC" Scholz<unknown@email.invalid>
38 * @author Roland Häder<roland@mxchange.org>
40 @WebFilter (servletNames = {"Faces Servlet"})
41 public class PizzaApplicationNoCacheFilter implements Filter {
44 public void destroy () {
45 System.out.println("destroy!"); //NOI18N
49 public void doFilter (final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
51 final HttpServletRequest req = (HttpServletRequest) request;
52 final HttpServletResponse res = (HttpServletResponse) response;
54 // Is the request URI not starting with resource identifier?
55 if (!req.getPathInfo().startsWith(ResourceHandler.RESOURCE_IDENTIFIER)) {
56 // Set non-caching header
57 res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); //NOI18N
58 res.setHeader("Pragma", "no-cache"); // //NOI18N
59 res.setDateHeader("Expires", 0); // //NOI18N
62 if ("true".equals(req.getParameter("javax.faces.partial.ajax"))) {
64 res.setHeader("Accept", "text/xml"); //NOI18N
69 chain.doFilter(request, response);
73 public void init (final FilterConfig filterConfig) throws ServletException {
74 System.out.println("init!"); //NOI18N