@Test public void handleRequestExceptionWithConfiguredPage() throws IOException { train_resolvePageClassNameToPageName(componentClassResolver, MyPage.class.getName(), "mypage"); Link link = mockLink(); expect(linkSource.createPageRenderLink("mypage", false, new Object[]{"accesscontrol"})).andReturn(link); expect(request.isXHR()).andReturn(false); response.sendRedirect(link); EasyMock.expectLastCall(); replay(); exceptionHandler.handleRequestException(new OperationException(new RenderQueueException( "renderqueue", new Object[0], new TapestryException("tapestryexception", new AccessControlException("No permission"))), new String[0])); }
@SuppressWarnings({"rawtypes", "unchecked"}) public void handleRequestException(Throwable exception) throws IOException { if (configuration.isEmpty()) { renderException(exception); return; } Throwable cause = exception; while (cause instanceof TapestryException) { if (cause.getCause() == null) break; cause = cause.getCause(); } Class<?> causeClass = cause.getClass(); if (!configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { renderException(exception); return; } } } Object[] exceptionContext = formExceptionContext(cause); Object value = configuration.get(causeClass); Object page = null; ExceptionHandlerAssistant assistant = null; if (value instanceof ExceptionHandlerAssistant) { assistant = (ExceptionHandlerAssistant) value; List context = Arrays.asList(exceptionContext); page = assistant.handleRequestException(exception, context); exceptionContext = context.toArray(); } else if (!(value instanceof Class)) { renderException(exception); return; } else page = value; if (page == null) return; try { if (page instanceof Class) page = componentClassResolver.resolvePageClassNameToPageName(((Class) page).getName()); Link link = page instanceof Link ? (Link) page : linkSource.createPageRenderLink(page.toString(), false, exceptionContext); if (request.isXHR()) { OutputStream os = response.getOutputStream("application/json;charset=UTF-8"); JSONObject reply = new JSONObject(); reply.in(InternalConstants.PARTIAL_KEY).put("redirectURL", link.toRedirectURI()); os.write(reply.toCompactString().getBytes("UTF-8")); os.close(); return; } response.sendRedirect(link); } catch (Exception e) { logger.warn("A new exception was thrown while trying to handle an instance of {}.", exception.getClass().getName(), e); renderException(exception); } }
DefaultRequestExceptionHandler implements RequestExceptionHandler { @SuppressWarnings({"rawtypes", "unchecked"}) public void handleRequestException(Throwable exception) throws IOException { if (configuration.isEmpty()) { renderException(exception); return; } Throwable cause = exception; while (cause instanceof TapestryException) { if (cause.getCause() == null) break; cause = cause.getCause(); } Class<?> causeClass = cause.getClass(); if (!configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { renderException(exception); return; } } } Object[] exceptionContext = formExceptionContext(cause); Object value = configuration.get(causeClass); Object page = null; ExceptionHandlerAssistant assistant = null; if (value instanceof ExceptionHandlerAssistant) { assistant = (ExceptionHandlerAssistant) value; List context = Arrays.asList(exceptionContext); page = assistant.handleRequestException(exception, context); exceptionContext = context.toArray(); } else if (!(value instanceof Class)) { renderException(exception); return; } else page = value; if (page == null) return; try { if (page instanceof Class) page = componentClassResolver.resolvePageClassNameToPageName(((Class) page).getName()); Link link = page instanceof Link ? (Link) page : linkSource.createPageRenderLink(page.toString(), false, exceptionContext); if (request.isXHR()) { OutputStream os = response.getOutputStream("application/json;charset=UTF-8"); JSONObject reply = new JSONObject(); reply.in(InternalConstants.PARTIAL_KEY).put("redirectURL", link.toRedirectURI()); os.write(reply.toCompactString().getBytes("UTF-8")); os.close(); return; } response.sendRedirect(link); } catch (Exception e) { logger.warn("A new exception was thrown while trying to handle an instance of {}.", exception.getClass().getName(), e); renderException(exception); } } }
DefaultRequestExceptionHandler implements RequestExceptionHandler { @SuppressWarnings({"rawtypes", "unchecked"}) public void handleRequestException(Throwable exception) throws IOException { if (configuration.isEmpty()) { renderException(exception); return; } Throwable cause = exception; while (cause instanceof TapestryException) { if (cause.getCause() == null) break; cause = cause.getCause(); } Class<?> causeClass = cause.getClass(); if (!configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { renderException(exception); return; } } } Object[] exceptionContext = formExceptionContext(cause); Object value = configuration.get(causeClass); Object page = null; ExceptionHandlerAssistant assistant = null; if (value instanceof ExceptionHandlerAssistant) { assistant = (ExceptionHandlerAssistant) value; List context = Arrays.asList(exceptionContext); page = assistant.handleRequestException(exception, context); exceptionContext = context.toArray(); } else if (!(value instanceof Class)) { renderException(exception); return; } else page = value; if (page == null) return; try { if (page instanceof Class) page = componentClassResolver.resolvePageClassNameToPageName(((Class) page).getName()); Link link = page instanceof Link ? (Link) page : linkSource.createPageRenderLink(page.toString(), false, exceptionContext); if (request.isXHR()) { OutputStream os = response.getOutputStream("application/json;charset=UTF-8"); JSONObject reply = new JSONObject(); reply.in(InternalConstants.PARTIAL_KEY).put("redirectURL", link.toRedirectURI()); os.write(reply.toCompactString().getBytes("UTF-8")); os.close(); return; } response.sendRedirect(link); } catch (Exception e) { logger.warn("A new exception was thrown while trying to handle an instance of {}.", exception.getClass().getName(), e); renderException(exception); } } @SuppressWarnings("rawtypes")  DefaultRequestExceptionHandler(RequestPageCache pageCache,
                                          PageResponseRenderer renderer,
                                          Logger logger,
                                          @Symbol(SymbolConstants.EXCEPTION_REPORT_PAGE)
                                          String pageName,
                                          Request request,
                                          Response response,
                                          ComponentClassResolver componentClassResolver,
                                          LinkSource linkSource,
                                          ServiceResources serviceResources,
                                          ExceptionReporter exceptionReporter,
                                          Map<Class, Object> configuration); }
DefaultRequestExceptionHandler implements RequestExceptionHandler { @SuppressWarnings({"rawtypes", "unchecked"}) public void handleRequestException(Throwable exception) throws IOException { if (configuration.isEmpty()) { renderException(exception); return; } Throwable cause = exception; while (cause instanceof TapestryException) { if (cause.getCause() == null) break; cause = cause.getCause(); } Class<?> causeClass = cause.getClass(); if (!configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { renderException(exception); return; } } } Object[] exceptionContext = formExceptionContext(cause); Object value = configuration.get(causeClass); Object page = null; ExceptionHandlerAssistant assistant = null; if (value instanceof ExceptionHandlerAssistant) { assistant = (ExceptionHandlerAssistant) value; List context = Arrays.asList(exceptionContext); page = assistant.handleRequestException(exception, context); exceptionContext = context.toArray(); } else if (!(value instanceof Class)) { renderException(exception); return; } else page = value; if (page == null) return; try { if (page instanceof Class) page = componentClassResolver.resolvePageClassNameToPageName(((Class) page).getName()); Link link = page instanceof Link ? (Link) page : linkSource.createPageRenderLink(page.toString(), false, exceptionContext); if (request.isXHR()) { OutputStream os = response.getOutputStream("application/json;charset=UTF-8"); JSONObject reply = new JSONObject(); reply.in(InternalConstants.PARTIAL_KEY).put("redirectURL", link.toRedirectURI()); os.write(reply.toCompactString().getBytes("UTF-8")); os.close(); return; } response.sendRedirect(link); } catch (Exception e) { logger.warn("A new exception was thrown while trying to handle an instance of {}.", exception.getClass().getName(), e); renderException(exception); } } @SuppressWarnings("rawtypes")  DefaultRequestExceptionHandler(RequestPageCache pageCache,
                                          PageResponseRenderer renderer,
                                          Logger logger,
                                          @Symbol(SymbolConstants.EXCEPTION_REPORT_PAGE)
                                          String pageName,
                                          Request request,
                                          Response response,
                                          ComponentClassResolver componentClassResolver,
                                          LinkSource linkSource,
                                          ServiceResources serviceResources,
                                          ExceptionReporter exceptionReporter,
                                          Map<Class, Object> configuration); @SuppressWarnings({"rawtypes", "unchecked"}) void handleRequestException(Throwable exception); }
DefaultRequestExceptionHandler implements RequestExceptionHandler { @SuppressWarnings({"rawtypes", "unchecked"}) public void handleRequestException(Throwable exception) throws IOException { if (configuration.isEmpty()) { renderException(exception); return; } Throwable cause = exception; while (cause instanceof TapestryException) { if (cause.getCause() == null) break; cause = cause.getCause(); } Class<?> causeClass = cause.getClass(); if (!configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { causeClass = causeClass.getSuperclass(); if (causeClass == null || !configuration.containsKey(causeClass)) { renderException(exception); return; } } } Object[] exceptionContext = formExceptionContext(cause); Object value = configuration.get(causeClass); Object page = null; ExceptionHandlerAssistant assistant = null; if (value instanceof ExceptionHandlerAssistant) { assistant = (ExceptionHandlerAssistant) value; List context = Arrays.asList(exceptionContext); page = assistant.handleRequestException(exception, context); exceptionContext = context.toArray(); } else if (!(value instanceof Class)) { renderException(exception); return; } else page = value; if (page == null) return; try { if (page instanceof Class) page = componentClassResolver.resolvePageClassNameToPageName(((Class) page).getName()); Link link = page instanceof Link ? (Link) page : linkSource.createPageRenderLink(page.toString(), false, exceptionContext); if (request.isXHR()) { OutputStream os = response.getOutputStream("application/json;charset=UTF-8"); JSONObject reply = new JSONObject(); reply.in(InternalConstants.PARTIAL_KEY).put("redirectURL", link.toRedirectURI()); os.write(reply.toCompactString().getBytes("UTF-8")); os.close(); return; } response.sendRedirect(link); } catch (Exception e) { logger.warn("A new exception was thrown while trying to handle an instance of {}.", exception.getClass().getName(), e); renderException(exception); } } @SuppressWarnings("rawtypes")  DefaultRequestExceptionHandler(RequestPageCache pageCache,
                                          PageResponseRenderer renderer,
                                          Logger logger,
                                          @Symbol(SymbolConstants.EXCEPTION_REPORT_PAGE)
                                          String pageName,
                                          Request request,
                                          Response response,
                                          ComponentClassResolver componentClassResolver,
                                          LinkSource linkSource,
                                          ServiceResources serviceResources,
                                          ExceptionReporter exceptionReporter,
                                          Map<Class, Object> configuration); @SuppressWarnings({"rawtypes", "unchecked"}) void handleRequestException(Throwable exception);  }