You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2017/06/01 15:15:41 UTC

svn commit: r1797232 - in /myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main: java/org/apache/myfaces/tobago/example/demo/ webapp/WEB-INF/

Author: lofwyr
Date: Thu Jun  1 15:15:41 2017
New Revision: 1797232

URL: http://svn.apache.org/viewvc?rev=1797232&view=rev
Log:
TOBAGO-1745: Demo: Fix status code for error pages

Added:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DeltaSpikeClientWindowConfig.java
Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TestExceptionHandler.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml

Added: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DeltaSpikeClientWindowConfig.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DeltaSpikeClientWindowConfig.java?rev=1797232&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DeltaSpikeClientWindowConfig.java (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DeltaSpikeClientWindowConfig.java Thu Jun  1 15:15:41 2017
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.example.demo;
+
+import org.apache.deltaspike.jsf.spi.scope.window.DefaultClientWindowConfig;
+
+import javax.enterprise.inject.Specializes;
+import javax.faces.context.FacesContext;
+
+@Specializes
+public class DeltaSpikeClientWindowConfig extends DefaultClientWindowConfig {
+
+  @Override
+  public ClientWindowRenderMode getClientWindowRenderMode(FacesContext facesContext) {
+    String path = facesContext.getExternalContext().getRequestPathInfo();
+    if (path == null) {
+        path = facesContext.getExternalContext().getRequestServletPath();
+    }
+
+    ClientWindowRenderMode mode;
+
+    if (path.startsWith("/error/")) {
+        mode = ClientWindowRenderMode.NONE;
+    } else {
+        mode = ClientWindowRenderMode.CLIENTWINDOW;
+    }
+
+    return mode;
+  }
+}

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TestExceptionHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TestExceptionHandler.java?rev=1797232&r1=1797231&r2=1797232&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TestExceptionHandler.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TestExceptionHandler.java Thu Jun  1 15:15:41 2017
@@ -28,6 +28,8 @@ import javax.faces.context.ExceptionHand
 import javax.faces.context.FacesContext;
 import javax.faces.event.ExceptionQueuedEvent;
 import javax.faces.event.ExceptionQueuedEventContext;
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileNotFoundException;
 import java.util.Iterator;
 
 public class TestExceptionHandler extends ExceptionHandlerWrapper {
@@ -66,6 +68,17 @@ public class TestExceptionHandler extend
           facesContext.renderResponse();
         } finally {
           iterator.remove();
+        }
+      } else if (cause instanceof FileNotFoundException
+              || cause != null && cause.getCause() instanceof FileNotFoundException) {
+        try {
+          final FacesContext facesContext = FacesContext.getCurrentInstance();
+          final NavigationHandler nav = facesContext.getApplication().getNavigationHandler();
+          nav.handleNavigation(facesContext, null, "/faces/error/404.xhtml");
+          facesContext.getExternalContext().setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
+          facesContext.renderResponse();
+        } finally {
+          iterator.remove();
         }
       }
     }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml?rev=1797232&r1=1797231&r2=1797232&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml Thu Jun  1 15:15:41 2017
@@ -132,7 +132,10 @@
     <url-pattern>/faces/*</url-pattern>
   </servlet-mapping>
 
-  <!-- Error Page -->
+  <!-- Error handling, see also these classes:
+       org.apache.myfaces.tobago.example.demo.TestExceptionHandler
+       org.apache.myfaces.tobago.example.demo.DeltaSpikeClientWindowConfig
+   -->
 
   <error-page>
     <error-code>404</error-code>
@@ -144,12 +147,6 @@
     <location>/faces/error/exception.xhtml</location>
   </error-page>
 
-
-  <error-page>
-    <exception-type>java.io.FileNotFoundException</exception-type>
-    <location>/faces/error/404.xhtml</location>
-  </error-page>
-
   <error-page>
     <exception-type>java.lang.Exception</exception-type>
     <location>/faces/error/exception.xhtml</location>