com.addc.server.commons.struts12.actions.GlobalExceptionHandler Maven / Gradle / Ivy
package com.addc.server.commons.struts12.actions;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.addc.commons.i18n.I18nTextFactory;
import com.addc.commons.uuid.UUIDGenerator;
import com.addc.server.commons.i18n.ServerI18n;
import com.addc.server.commons.web.i18n.HtmlLabels;
/**
* The GlobalExceptionHandler would be configured in the struts configuration
* file in the global mappings to redirect to a generic error page. For these
* errors it generates a UUID that is displayed in the error page and can be
* used to locate the stack traces in the log files.
*
*/
public class GlobalExceptionHandler extends ExceptionHandler {
private static final Logger LOGGER= LoggerFactory.getLogger(GlobalExceptionHandler.class);
@Override
public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance,
HttpServletRequest request, HttpServletResponse response) throws ServletException {
ActionForward forward= mapping.findForward(ActionConstants.UNCHECKED_ERROR);
String errorCode= UUIDGenerator.getInstance().createUUID();
LOGGER.error("An uncontrolled error has occurred. Reference: " + errorCode, ex);
request.setAttribute(Globals.ERROR_KEY, I18nTextFactory.getTranslator(ServerI18n.BASENAME, request.getLocale())
.translate(HtmlLabels.ERRORS_EXCEPTION, errorCode));
request.setAttribute(Globals.EXCEPTION_KEY, ex);
return forward;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy