You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by gv...@apache.org on 2006/05/02 19:40:47 UTC
svn commit: r398979 - in
/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay:
config/beans/ComponentConfigBean.java
config/beans/PageNotFoundException.java faces/ClayViewHandler.java
Author: gvanmatre
Date: Tue May 2 10:40:40 2006
New Revision: 398979
URL: http://svn.apache.org/viewcvs?rev=398979&view=rev
Log:
If a clay full template (XML or HTML) was not found, an incorrect HTTP status code of 500 was reported. A status code of 404 is now returned if the missing resource is the entry point of the view root.
Added:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/PageNotFoundException.java (with props)
Modified:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java?rev=398979&r1=398978&r2=398979&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java Tue May 2 10:40:40 2006
@@ -227,7 +227,7 @@
} else {
URL url = context.getResource(configFile.toString());
if (url == null) {
- throw new RuntimeException(messages.getMessage("file.notfound", new Object[] {configFile.toString()}));
+ throw new PageNotFoundException(messages.getMessage("file.notfound", new Object[] {configFile.toString()}), configFile.toString());
}
urls.add(url);
}
Added: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/PageNotFoundException.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/PageNotFoundException.java?rev=398979&view=auto
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/PageNotFoundException.java (added)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/PageNotFoundException.java Tue May 2 10:40:40 2006
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Id$
+ */
+
+package org.apache.shale.clay.config.beans;
+
+/**
+ * <p>This is an unchecked exception used to identify that
+ * a {@link org.apache.shale.clay.component.Clay} template
+ * could not be found. The exception captures the requested
+ * resource to be compared to the view root. This is done
+ * by the {@link org.apache.shale.clay.faces.ClayViewHandler}
+ * in the <code>renderView</code> method. If the missing
+ * template and the <code>viewId</code> are the same, a
+ * HTTP 404 status code is sent to the client. If the
+ * missing template resource is nested in the page composition,
+ * the standard 500 status code will be returned.
+ *</p>
+ */
+public class PageNotFoundException extends RuntimeException {
+
+ private static final long serialVersionUID = 3258689897039672375L;
+ /**
+ * <p>The requested resource.</p>
+ */
+ private String resource = null;
+
+ /**
+ * <p>Overloaded constructor requires an error message
+ * and the missing resource.</p>
+ *
+ * @param message error message
+ * @param resource missing resource
+ */
+ public PageNotFoundException(String message, String resource) {
+ super(message);
+ this.resource = resource;
+ }
+
+ /**
+ * <p>Returns the missing resource.</p>
+ */
+ public String getResource() {
+ return resource;
+ }
+
+
+}
Propchange: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/PageNotFoundException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/PageNotFoundException.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java?rev=398979&r1=398978&r2=398979&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java Tue May 2 10:40:40 2006
@@ -29,12 +29,13 @@
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shale.clay.component.Clay;
import org.apache.shale.clay.config.Globals;
+import org.apache.shale.clay.config.beans.PageNotFoundException;
import org.apache.shale.view.Constants;
import org.apache.shale.view.ViewController;
import org.apache.shale.view.ViewControllerMapper;
@@ -329,7 +330,7 @@
}
//get the response
- ServletResponse response = (ServletResponse) context.getExternalContext().getResponse();
+ HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
//set the locale
(response).setLocale(context.getViewRoot().getLocale());
@@ -342,8 +343,18 @@
//start a document
buffResponsewriter.startDocument();
- recursiveRender(view, context);
-
+ try {
+ recursiveRender(view, context);
+ } catch (PageNotFoundException e) {
+ //look to see if the page not found is a top level page
+ if (e.getResource().equals(view.getViewId())) {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, e.getResource());
+ context.responseComplete();
+ return;
+ }
+
+ throw e;
+ }
//end the document
buffResponsewriter.endDocument();