--- /dev/null
+/*
+ * Copyright (C) 2022 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.filter;
+
+import java.io.IOException;
+import javax.faces.application.ResourceHandler;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * A filter for no-caching of JSF requests send from client. This class was
+ * taken from stackoverflow.com at
+ * https://stackoverflow.com/questions/3642919/javax-faces-application-viewexpiredexception-view-could-not-be-restored
+ * and was slightly expanded with "final" keyword and comments
+ * <p>
+ * @author Bauke "BalusC" Scholz<unknown@email.invalid>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@WebFilter (servletNames = {"Faces Servlet"})
+public class AddressbookNoCacheFilter implements Filter {
+
+ @Override
+ public void destroy () {
+ System.out.println("destroy!"); //NOI18N
+ }
+
+ @Override
+ public void doFilter (final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
+ // Cast parameter
+ final HttpServletRequest req = (HttpServletRequest) request;
+ final HttpServletResponse res = (HttpServletResponse) response;
+
+ // Is the request URI not starting with resource identifier?
+ if (!req.getPathInfo().startsWith(ResourceHandler.RESOURCE_IDENTIFIER)) {
+ // Set non-caching header
+ res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); //NOI18N
+ res.setHeader("Pragma", "no-cache"); // //NOI18N
+ res.setDateHeader("Expires", 0); // //NOI18N
+
+ // Is AJAX?
+ if ("true".equals(req.getParameter("javax.faces.partial.ajax"))) {
+ // Set Accept header
+ res.setHeader("Accept", "text/xml"); //NOI18N
+ }
+ }
+
+ // Continue filtering
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void init (final FilterConfig filterConfig) throws ServletException {
+ System.out.println("init!"); //NOI18N
+ }
+
+}