@Test public void shouldNotForwardToMethodsDefaultViewWhenResponseIsCommited() throws Exception { givenDispatcherWillBeReturnedWhenRequested(); when(response.isCommitted()).thenReturn(true); logicResult.forwardTo(MyComponent.class).base(); verify(dispatcher, never()).forward(request, response); }
public <T> T forwardTo(final Class<T> type) { return proxifier.proxify(type, new MethodInvocation<T>() { public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { try { logger.debug("Executing {}", Stringnifier.simpleNameFor(method)); ResourceMethod old = methodInfo.getResourceMethod(); methodInfo.setResourceMethod(DefaultResourceMethod.instanceFor(type, method)); Object result = method.invoke(container.instanceFor(type), args); methodInfo.setResourceMethod(old); Type returnType = method.getGenericReturnType(); if (!(returnType == void.class)) { request.setAttribute(extractor.nameFor(returnType), result); } if (!response.isCommitted()) { String path = resolver.pathFor(DefaultResourceMethod.instanceFor(type, method)); logger.debug("Forwarding to {}", path); request.getRequestDispatcher(path).forward(request, response); } return null; } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } throw new ProxyInvocationException(e); } catch (Exception e) { throw new ProxyInvocationException(e); } } }); }
DefaultLogicResult implements LogicResult { public <T> T forwardTo(final Class<T> type) { return proxifier.proxify(type, new MethodInvocation<T>() { public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { try { logger.debug("Executing {}", Stringnifier.simpleNameFor(method)); ResourceMethod old = methodInfo.getResourceMethod(); methodInfo.setResourceMethod(DefaultResourceMethod.instanceFor(type, method)); Object result = method.invoke(container.instanceFor(type), args); methodInfo.setResourceMethod(old); Type returnType = method.getGenericReturnType(); if (!(returnType == void.class)) { request.setAttribute(extractor.nameFor(returnType), result); } if (!response.isCommitted()) { String path = resolver.pathFor(DefaultResourceMethod.instanceFor(type, method)); logger.debug("Forwarding to {}", path); request.getRequestDispatcher(path).forward(request, response); } return null; } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } throw new ProxyInvocationException(e); } catch (Exception e) { throw new ProxyInvocationException(e); } } }); } }
DefaultLogicResult implements LogicResult { public <T> T forwardTo(final Class<T> type) { return proxifier.proxify(type, new MethodInvocation<T>() { public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { try { logger.debug("Executing {}", Stringnifier.simpleNameFor(method)); ResourceMethod old = methodInfo.getResourceMethod(); methodInfo.setResourceMethod(DefaultResourceMethod.instanceFor(type, method)); Object result = method.invoke(container.instanceFor(type), args); methodInfo.setResourceMethod(old); Type returnType = method.getGenericReturnType(); if (!(returnType == void.class)) { request.setAttribute(extractor.nameFor(returnType), result); } if (!response.isCommitted()) { String path = resolver.pathFor(DefaultResourceMethod.instanceFor(type, method)); logger.debug("Forwarding to {}", path); request.getRequestDispatcher(path).forward(request, response); } return null; } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } throw new ProxyInvocationException(e); } catch (Exception e) { throw new ProxyInvocationException(e); } } }); } @Inject  DefaultLogicResult(Proxifier proxifier, Router router, MutableRequest request, MutableResponse response,
			Container container, PathResolver resolver, TypeNameExtractor extractor, FlashScope flash, MethodInfo methodInfo); }
DefaultLogicResult implements LogicResult { public <T> T forwardTo(final Class<T> type) { return proxifier.proxify(type, new MethodInvocation<T>() { public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { try { logger.debug("Executing {}", Stringnifier.simpleNameFor(method)); ResourceMethod old = methodInfo.getResourceMethod(); methodInfo.setResourceMethod(DefaultResourceMethod.instanceFor(type, method)); Object result = method.invoke(container.instanceFor(type), args); methodInfo.setResourceMethod(old); Type returnType = method.getGenericReturnType(); if (!(returnType == void.class)) { request.setAttribute(extractor.nameFor(returnType), result); } if (!response.isCommitted()) { String path = resolver.pathFor(DefaultResourceMethod.instanceFor(type, method)); logger.debug("Forwarding to {}", path); request.getRequestDispatcher(path).forward(request, response); } return null; } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } throw new ProxyInvocationException(e); } catch (Exception e) { throw new ProxyInvocationException(e); } } }); } @Inject  DefaultLogicResult(Proxifier proxifier, Router router, MutableRequest request, MutableResponse response,
			Container container, PathResolver resolver, TypeNameExtractor extractor, FlashScope flash, MethodInfo methodInfo); T forwardTo(final Class<T> type); T redirectTo(final Class<T> type); }
DefaultLogicResult implements LogicResult { public <T> T forwardTo(final Class<T> type) { return proxifier.proxify(type, new MethodInvocation<T>() { public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { try { logger.debug("Executing {}", Stringnifier.simpleNameFor(method)); ResourceMethod old = methodInfo.getResourceMethod(); methodInfo.setResourceMethod(DefaultResourceMethod.instanceFor(type, method)); Object result = method.invoke(container.instanceFor(type), args); methodInfo.setResourceMethod(old); Type returnType = method.getGenericReturnType(); if (!(returnType == void.class)) { request.setAttribute(extractor.nameFor(returnType), result); } if (!response.isCommitted()) { String path = resolver.pathFor(DefaultResourceMethod.instanceFor(type, method)); logger.debug("Forwarding to {}", path); request.getRequestDispatcher(path).forward(request, response); } return null; } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } throw new ProxyInvocationException(e); } catch (Exception e) { throw new ProxyInvocationException(e); } } }); } @Inject  DefaultLogicResult(Proxifier proxifier, Router router, MutableRequest request, MutableResponse response,
			Container container, PathResolver resolver, TypeNameExtractor extractor, FlashScope flash, MethodInfo methodInfo); T forwardTo(final Class<T> type); T redirectTo(final Class<T> type);  }