]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 25 Sep 2022 20:43:26 +0000 (22:43 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 25 Sep 2022 20:47:36 +0000 (22:47 +0200)
- no need for local variable "isAjax"

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/pizzaapplication/filter/PizzaApplicationNoCacheFilter.java [new file with mode: 0644]

diff --git a/src/java/org/mxchange/pizzaapplication/filter/PizzaApplicationNoCacheFilter.java b/src/java/org/mxchange/pizzaapplication/filter/PizzaApplicationNoCacheFilter.java
new file mode 100644 (file)
index 0000000..ed48dc2
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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.pizzaapplication.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 PizzaApplicationNoCacheFilter 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
+       }
+
+}