All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.addc.server.commons.struts12.actions.ErrorAction Maven / Gradle / Ivy

There is a newer version: 2.6.1
Show newest version
package com.addc.server.commons.struts12.actions;

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.actions.DispatchAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The ErrorAction supplies a struts action for error pages
 */
@SuppressWarnings("PMD")
public class ErrorAction extends DispatchAction {
    private static final Logger LOGGER= LoggerFactory.getLogger(ErrorAction.class);
    
    @SuppressWarnings("unused")
    public ActionForward preparePage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) {
        ActionForward forward= mapping.findForward(ActionConstants.SUCCESS_FORWARD);
        ErrorActionForm actionForm= (ErrorActionForm) form;
        try {
            actionForm.setErrorCode((String) request.getAttribute(Globals.ERROR_KEY));
            Exception exception= (Exception) request.getAttribute(Globals.EXCEPTION_KEY);
            actionForm.setException(exception.getMessage());
            LOGGER.info("{}", actionForm);
        } catch (Exception e) {
            actionForm.setErrorCode("Internal Error: " + e.getMessage());
        }
        return forward;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy