mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- 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:
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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,25 +85,13 @@ public class ErrorBean
|
|||||||
|
|
||||||
if (this.lastError != null)
|
if (this.lastError != null)
|
||||||
{
|
{
|
||||||
StringBuilder builder = null;
|
StringBuilder builder = new StringBuilder(this.lastError.toString());;
|
||||||
Throwable cause = null;
|
Throwable cause = this.lastError.getCause();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// build up stack trace of all causes
|
||||||
while (cause != null)
|
while (cause != null)
|
||||||
{
|
{
|
||||||
builder.append("<br/><br/>caused by:<br/>");
|
builder.append("\ncaused by:\n");
|
||||||
builder.append(cause.toString());
|
builder.append(cause.toString());
|
||||||
|
|
||||||
if (cause instanceof ServletException &&
|
if (cause instanceof ServletException &&
|
||||||
@@ -107,6 +106,11 @@ public class ErrorBean
|
|||||||
}
|
}
|
||||||
|
|
||||||
message = builder.toString();
|
message = builder.toString();
|
||||||
|
|
||||||
|
// format the message for HTML display
|
||||||
|
message = message.replaceAll("<", "<");
|
||||||
|
message = message.replaceAll(">", ">");
|
||||||
|
message = message.replaceAll("\n", "<br/>");
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
@@ -119,18 +123,14 @@ public class ErrorBean
|
|||||||
{
|
{
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
PrintWriter writer = new PrintWriter(stringWriter);
|
PrintWriter writer = new PrintWriter(stringWriter);
|
||||||
|
|
||||||
if (this.lastError instanceof ServletException &&
|
|
||||||
((ServletException)this.lastError).getRootCause() != null)
|
|
||||||
{
|
|
||||||
Throwable actualError = ((ServletException)this.lastError).getRootCause();
|
|
||||||
actualError.printStackTrace(writer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.lastError.printStackTrace(writer);
|
this.lastError.printStackTrace(writer);
|
||||||
}
|
|
||||||
|
|
||||||
return stringWriter.toString().replaceAll("\r\n", "<br/>");
|
// format the message for HTML display
|
||||||
|
String trace = stringWriter.toString();
|
||||||
|
trace = trace.replaceAll("<", "<");
|
||||||
|
trace = trace.replaceAll(">", ">");
|
||||||
|
trace = trace.replaceAll("\n", "<br/>");
|
||||||
|
|
||||||
|
return trace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,8 @@ import org.alfresco.web.bean.ErrorBean;
|
|||||||
*/
|
*/
|
||||||
public class SystemErrorTag extends TagSupport
|
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_RETURN_TO_APP = "return_to_application";
|
||||||
private static final String MSG_HIDE_DETAILS = "hide_details";
|
private static final String MSG_HIDE_DETAILS = "hide_details";
|
||||||
private static final String MSG_SHOW_DETAILS = "show_details";
|
private static final String MSG_SHOW_DETAILS = "show_details";
|
||||||
@@ -126,6 +128,21 @@ public class SystemErrorTag extends TagSupport
|
|||||||
errorMessage = errorBean.getLastErrorMessage();
|
errorMessage = errorBean.getLastErrorMessage();
|
||||||
errorDetails = errorBean.getStackTrace();
|
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
|
try
|
||||||
{
|
{
|
||||||
@@ -254,6 +271,11 @@ public class SystemErrorTag extends TagSupport
|
|||||||
{
|
{
|
||||||
throw new JspException(ioe);
|
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;
|
return SKIP_BODY;
|
||||||
}
|
}
|
||||||
|
@@ -187,7 +187,7 @@
|
|||||||
<!-- Faces Servlet -->
|
<!-- Faces Servlet -->
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>Faces Servlet</servlet-name>
|
<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>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
@@ -359,9 +359,9 @@
|
|||||||
<welcome-file>index.jsp</welcome-file>
|
<welcome-file>index.jsp</welcome-file>
|
||||||
</welcome-file-list>
|
</welcome-file-list>
|
||||||
|
|
||||||
<taglib>
|
<error-page>
|
||||||
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
|
<error-code>500</error-code>
|
||||||
<taglib-location>/WEB-INF/c.tld</taglib-location>
|
<location>/jsp/error.jsp</location>
|
||||||
</taglib>
|
</error-page>
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
||||||
|
Reference in New Issue
Block a user