package eu.lsem.bakalarka.webfrontend.extensions;
import eu.lsem.bakalarka.webfrontend.action.secure.ThesisFormActionBean;
import eu.lsem.bakalarka.webfrontend.customresolution.CustomErrorResolution;
import net.sourceforge.stripes.action.ErrorResolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.controller.FileUploadLimitExceededException;
import net.sourceforge.stripes.exception.ActionBeanNotFoundException;
import net.sourceforge.stripes.exception.DefaultExceptionHandler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.dao.DataAccessException;
import org.apache.log4j.Logger;
public class CustomExceptionHandler extends DefaultExceptionHandler{
private static Logger log = Logger.getLogger(CustomExceptionHandler.class);
/**
* Tohle resi vyjimku pri prekroceni velikosti uploadu.
* @param e
* @param request
* @param response
* @return
*/
public Resolution handleFileUploadLimitExceededException(FileUploadLimitExceededException e, HttpServletRequest request, HttpServletResponse response) {
return new RedirectResolution(ThesisFormActionBean.class, "recoverFromExceededLimit").addParameter("maxSize", e.getMaximum()).addParameter("postedSize", e.getPosted());
}
/**
* Tohle resi chybu, kdy neni mozny najit ActionBean
* @param e
* @param request
* @param response
* @return
*/
public Resolution handleActionBeanNotFoundException(ActionBeanNotFoundException e, HttpServletRequest request, HttpServletResponse response) {
return new CustomErrorResolution(404);
}
public Resolution handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
log.error("Chyba zachycena ve Stripes exception handleru", e);
return new CustomErrorResolution(500, e.getMessage());
}
}