/** * Redirects the execution to the HDIV error page * * @param context Request context * @param validatorErrors validation error data */ protected void forwardToErrorPage(final FacesContext context, final List<FacesValidatorError> validatorErrors) { HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); List<ValidatorError> errors = new ArrayList<ValidatorError>(); if (validatorErrors != null) { for (FacesValidatorError error : validatorErrors) { errors.add(error); } } validatorErrorHandler.handleValidatorError(HDIVUtil.getRequestContext(request), errors); }
errorHandler.handleValidatorException(ctx, e); errorHandler.handleValidatorError(ctx, errors); errorHandler.handleValidatorError(ctx, errors);
public void testPageIncorrect() { RequestContextHolder ctx = getRequestContext(); ValidatorError error = new ValidatorError(HDIVErrorCodes.INVALID_PAGE_ID); List<ValidatorError> errors = Collections.singletonList(error); validatorErrorHandler.handleValidatorError(ctx, errors); String redirectUrl = getMockResponse().getRedirectedUrl(); assertEquals(getConfig().getSessionExpiredLoginPage(), redirectUrl); }
public void testHandleValidatorError() { HttpServletRequest request = getMockRequest(); RequestContextHolder ctx = getRequestContext(); MockHttpSession session = (MockHttpSession) request.getSession(); session.setNew(false); // mark as not new sesssion clearSession(); MockHttpServletResponse response = getMockResponse(); ValidatorError error = new ValidatorError(HDIVErrorCodes.NOT_RECEIVED_ALL_REQUIRED_PARAMETERS); List<ValidatorError> errors = Collections.singletonList(error); validatorErrorHandler.handleValidatorError(ctx, errors); String redirectUrl = response.getRedirectedUrl(); assertEquals(getConfig().getErrorPage(), redirectUrl); }
public void testDefaultErrorPage() { // Remove default errorPage getConfig().setErrorPage(null); RequestContextHolder ctx = getRequestContext(); MockHttpServletResponse response = getMockResponse(); ValidatorError error = new ValidatorError(HDIVErrorCodes.NOT_RECEIVED_ALL_REQUIRED_PARAMETERS); List<ValidatorError> errors = Collections.singletonList(error); validatorErrorHandler.handleValidatorError(ctx, errors); // Default Error page is generated, so no redirect URL exist assertNull(response.getRedirectedUrl()); assertTrue(response.getBufferSize() > 0); String responseContent = null; try { responseContent = response.getContentAsString(); } catch (UnsupportedEncodingException e) { responseContent = null; } assertNotNull(responseContent); assertTrue(responseContent.contains("Unauthorized access")); }