use of org.alfresco.web.bean.ErrorBean in project acs-community-packaging by Alfresco.
the class AlfrescoFacesPortlet method handleError.
/**
* Handles errors that occur during a render request
*/
private void handleError(RenderRequest request, RenderResponse response, Throwable error) throws PortletException, IOException {
// get the error bean from the session and set the error that occurred.
PortletSession session = request.getPortletSession();
ErrorBean errorBean = (ErrorBean) session.getAttribute(ErrorBean.ERROR_BEAN_NAME, PortletSession.PORTLET_SCOPE);
if (errorBean == null) {
errorBean = new ErrorBean();
session.setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean, PortletSession.PORTLET_SCOPE);
}
errorBean.setLastError(error);
// if the faces context is available set the current view to the browse page
// so that the error page goes back to the application (rather than going back
// to the same page which just throws the error again meaning we can never leave
// the error page)
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
ViewHandler viewHandler = context.getApplication().getViewHandler();
// TODO: configure the portlet error return page
UIViewRoot view = viewHandler.createView(context, FacesHelper.BROWSE_VIEW_ID);
context.setViewRoot(view);
}
// get the error page and include that instead
String errorPage = getErrorPage();
if (logger.isDebugEnabled())
logger.debug("An error has occurred, redirecting to error page: " + errorPage);
response.setContentType("text/html");
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(errorPage);
dispatcher.include(request, response);
}
use of org.alfresco.web.bean.ErrorBean in project acs-community-packaging by Alfresco.
the class AlfrescoFacesPortlet method handleError.
/**
* Handles errors that occur during a process action request
*/
private void handleError(ActionRequest request, ActionResponse response, Throwable error) throws PortletException, IOException {
// get the error bean from the session and set the error that occurred.
PortletSession session = request.getPortletSession();
ErrorBean errorBean = (ErrorBean) session.getAttribute(ErrorBean.ERROR_BEAN_NAME, PortletSession.PORTLET_SCOPE);
if (errorBean == null) {
errorBean = new ErrorBean();
session.setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean, PortletSession.PORTLET_SCOPE);
}
errorBean.setLastError(error);
response.setRenderParameter(ERROR_OCCURRED, "true");
}
use of org.alfresco.web.bean.ErrorBean in project acs-community-packaging by Alfresco.
the class UploadFileServlet method handleUploadException.
private void handleUploadException(HttpServletRequest request, HttpServletResponse response, Throwable error, String returnPage) {
try {
HttpSession session = request.getSession(true);
ErrorBean errorBean = (ErrorBean) session.getAttribute(ErrorBean.ERROR_BEAN_NAME);
if (errorBean == null) {
errorBean = new ErrorBean();
session.setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean);
}
errorBean.setLastError(error);
errorBean.setReturnPage(returnPage);
} catch (Throwable e) {
logger.error("Error while handling upload Exception", e);
}
try {
String errorPage = Application.getErrorPage(getServletContext());
if (logger.isDebugEnabled()) {
logger.debug("An error has occurred. Sending back response for redirecting to error page: " + errorPage);
}
response.setContentType(MimetypeMap.MIMETYPE_HTML);
response.setCharacterEncoding("utf-8");
final PrintWriter out = response.getWriter();
out.println("<html><body><script type=\"text/javascript\">");
out.println("window.parent.location.replace(\" " + request.getContextPath() + errorPage + "\")");
out.println("</script></body></html> ");
out.close();
} catch (Exception e) {
logger.error("Error while handling upload Exception", e);
}
}
use of org.alfresco.web.bean.ErrorBean in project acs-community-packaging by Alfresco.
the class Application method handleServletError.
/**
* Handles errors thrown from servlets
*
* @param servletContext The servlet context
* @param request The HTTP request
* @param response The HTTP response
* @param error The exception
* @param logger The logger
*/
public static void handleServletError(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, Throwable error, Log logger, String returnPage) throws IOException, ServletException {
// get the error bean from the session and set the error that occurred.
HttpSession session = request.getSession();
ErrorBean errorBean = (ErrorBean) session.getAttribute(ErrorBean.ERROR_BEAN_NAME);
if (errorBean == null) {
errorBean = new ErrorBean();
session.setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean);
}
errorBean.setLastError(error);
errorBean.setReturnPage(returnPage);
// try and find the configured error page
boolean errorShown = false;
String errorPage = getErrorPage(servletContext);
if (errorPage != null) {
if (logger.isDebugEnabled())
logger.debug("An error has occurred, redirecting to error page: " + errorPage);
if (response.isCommitted() == false) {
errorShown = true;
response.sendRedirect(request.getContextPath() + errorPage);
} else {
if (logger.isDebugEnabled())
logger.debug("Response is already committed, re-throwing error");
}
} else {
if (logger.isDebugEnabled())
logger.debug("No error page defined, re-throwing error");
}
// if we could not show the error page for whatever reason, re-throw the error
if (!errorShown) {
if (error instanceof IOException) {
throw (IOException) error;
} else if (error instanceof ServletException) {
throw (ServletException) error;
} else {
throw new ServletException(error);
}
}
}
use of org.alfresco.web.bean.ErrorBean in project acs-community-packaging by Alfresco.
the class Application method handleSystemError.
/**
* Handles error conditions detected by servlets.
*
* @param servletContext
* The servlet context
* @param request
* The HTTP request
* @param response
* The HTTP response
* @param messageKey
* the resource bundle key for the error mesage
* @param statusCode
* the status code to set on the response
* @param logger
* The logger
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ServletException
* the servlet exception
*/
public static void handleSystemError(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, String messageKey, int statusCode, Log logger) throws IOException, ServletException {
// get the error bean from the session and set the error that occurred.
HttpSession session = request.getSession();
ErrorBean errorBean = (ErrorBean) session.getAttribute(ErrorBean.ERROR_BEAN_NAME);
if (errorBean == null) {
errorBean = new ErrorBean();
session.setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean);
}
errorBean.setErrorMessageKey(messageKey);
errorBean.setReturnPage(null);
// try and find the configured error page
boolean errorShown = false;
String errorPage = getErrorPage(servletContext);
if (errorPage != null) {
if (logger.isDebugEnabled())
logger.debug("An error has occurred, forwarding to error page: " + errorPage);
if (!response.isCommitted()) {
errorShown = true;
response.reset();
response.setStatus(statusCode);
response.setContentType(MimetypeMap.MIMETYPE_HTML);
response.setCharacterEncoding("utf-8");
servletContext.getRequestDispatcher(errorPage).include(request, response);
} else {
if (logger.isDebugEnabled())
logger.debug("Response is already committed, re-throwing error");
}
} else {
if (logger.isDebugEnabled())
logger.debug("No error page defined, re-throwing error");
}
// if we could not show the error page for whatever reason, re-throw the error
if (!errorShown) {
throw new ServletException(getMessage(session, messageKey));
}
}
Aggregations