- Removed need to extend FacesServlet (which is actually final by default)

- Upgraded commons fileupload to 1.1.1

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3435 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-07-28 21:27:31 +00:00
parent 67395e5de8
commit cf80a2e112
4 changed files with 59 additions and 96 deletions

View File

@@ -1,59 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.web.app.servlet;
import java.io.IOException;
import javax.faces.webapp.FacesServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.web.app.Application;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Wrapper around standard faces servlet to provide error handling
*
* @author gavinc
*/
public class AlfrescoFacesServlet extends FacesServlet
{
private static Log logger = LogFactory.getLog(AlfrescoFacesServlet.class);
/**
* @see javax.servlet.Servlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
*/
public void service(ServletRequest request, ServletResponse response)
throws IOException, ServletException
{
try
{
super.service(request, response);
}
catch (Throwable error)
{
String returnPage = ((HttpServletRequest)request).getRequestURI();
Application.handleServletError(getServletConfig().getServletContext(), (HttpServletRequest)request,
(HttpServletResponse)response, error, logger, returnPage);
}
}
}

View File

@@ -58,11 +58,22 @@ public class ErrorBean
}
/**
* @param lastError The lastError to set.
* @param error The lastError to set.
*/
public void setLastError(Throwable lastError)
public void setLastError(Throwable error)
{
this.lastError = lastError;
// servlet exceptions hide the actual error within the rootCause
// variable, set the base error to that and throw away the
// ServletException wrapper
if (error instanceof ServletException &&
((ServletException)error).getRootCause() != null)
{
this.lastError = ((ServletException)error).getRootCause();
}
else
{
this.lastError = error;
}
}
/**
@@ -74,29 +85,17 @@ public class ErrorBean
if (this.lastError != null)
{
StringBuilder builder = null;
Throwable cause = null;
if (this.lastError instanceof ServletException &&
((ServletException)this.lastError).getRootCause() != null)
{
// servlet exception puts the actual error in root cause!!
Throwable actualError = ((ServletException)this.lastError).getRootCause();
builder = new StringBuilder(actualError.toString());
cause = actualError.getCause();
}
else
{
builder = new StringBuilder(this.lastError.toString());
cause = this.lastError.getCause();
}
StringBuilder builder = new StringBuilder(this.lastError.toString());;
Throwable cause = this.lastError.getCause();
// build up stack trace of all causes
while (cause != null)
{
builder.append("<br/><br/>caused by:<br/>");
builder.append("\ncaused by:\n");
builder.append(cause.toString());
if (cause instanceof ServletException &&
((ServletException)cause).getRootCause() != null)
((ServletException)cause).getRootCause() != null)
{
cause = ((ServletException)cause).getRootCause();
}
@@ -107,6 +106,11 @@ public class ErrorBean
}
message = builder.toString();
// format the message for HTML display
message = message.replaceAll("<", "&lt;");
message = message.replaceAll(">", "&gt;");
message = message.replaceAll("\n", "<br/>");
}
return message;
@@ -119,18 +123,14 @@ public class ErrorBean
{
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
this.lastError.printStackTrace(writer);
if (this.lastError instanceof ServletException &&
((ServletException)this.lastError).getRootCause() != null)
{
Throwable actualError = ((ServletException)this.lastError).getRootCause();
actualError.printStackTrace(writer);
}
else
{
this.lastError.printStackTrace(writer);
}
// format the message for HTML display
String trace = stringWriter.toString();
trace = trace.replaceAll("<", "&lt;");
trace = trace.replaceAll(">", "&gt;");
trace = trace.replaceAll("\n", "<br/>");
return stringWriter.toString().replaceAll("\r\n", "<br/>");
return trace;
}
}

View File

@@ -39,6 +39,8 @@ import org.alfresco.web.bean.ErrorBean;
*/
public class SystemErrorTag extends TagSupport
{
private static final long serialVersionUID = -7336055169875448199L;
private static final String MSG_RETURN_TO_APP = "return_to_application";
private static final String MSG_HIDE_DETAILS = "hide_details";
private static final String MSG_SHOW_DETAILS = "show_details";
@@ -126,6 +128,21 @@ public class SystemErrorTag extends TagSupport
errorMessage = errorBean.getLastErrorMessage();
errorDetails = errorBean.getStackTrace();
}
else
{
// if we reach here the error was caught by the declaration in web.xml so
// pull all the information from the request and create the error bean
Throwable error = (Throwable)pageContext.getRequest().getAttribute("javax.servlet.error.exception");
String uri = (String)pageContext.getRequest().getAttribute("javax.servlet.error.request_uri");
// create and store the ErrorBean
errorBean = new ErrorBean();
pageContext.getSession().setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean);
errorBean.setLastError(error);
errorBean.setReturnPage(uri);
errorMessage = errorBean.getLastErrorMessage();
errorDetails = errorBean.getStackTrace();
}
try
{
@@ -254,6 +271,11 @@ public class SystemErrorTag extends TagSupport
{
throw new JspException(ioe);
}
finally
{
// clear out the error bean otherwise the next error could be hidden
pageContext.getSession().removeAttribute(ErrorBean.ERROR_BEAN_NAME);
}
return SKIP_BODY;
}

View File

@@ -28,7 +28,7 @@
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
<description>This is an EXPERIMENTAL feature, so leave it off for now!</description>
</context-param>
</context-param>
<!-- TODO: Change this to false for production -->
<context-param>
@@ -187,7 +187,7 @@
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>org.alfresco.web.app.servlet.AlfrescoFacesServlet</servlet-class>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
@@ -359,9 +359,9 @@
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<error-page>
<error-code>500</error-code>
<location>/jsp/error.jsp</location>
</error-page>
</web-app>