@Override public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { try { request.getRequestDispatcher( resolver.pathFor(DefaultControllerMethod.instanceFor(controllerType, method))).forward( request, response); return null; } catch (Exception e) { throw new ProxyInvocationException(e); } } });
@Override public void defaultView() { String to = resolver.pathFor(methodInfo.getControllerMethod()); logger.debug("forwarding to {}", to); try { request.getRequestDispatcher(to).forward(request, response); } catch (ServletException e) { throw new ApplicationLogicException(to + " raised an exception", e); } catch (IOException e) { throw new ResultException(e); } }
@Override public void include() { try { String to = resolver.pathFor(methodInfo.getControllerMethod()); logger.debug("including {}", to); request.getRequestDispatcher(to).include(request, response); } catch (ServletException e) { throw new ResultException(e); } catch (IOException e) { throw new ResultException(e); } }
private MyComponent givenDispatcherWillBeReturnedWhenRequested() { final MyComponent component = new MyComponent(); when(container.instanceFor(MyComponent.class)).thenReturn(component); when(resolver.pathFor(any(ControllerMethod.class))).thenReturn("Abc123"); when(request.getRequestDispatcher("Abc123")).thenReturn(dispatcher); return component; }
@Override public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { try { logger.debug("Executing {}", method); ControllerMethod old = methodInfo.getControllerMethod(); methodInfo.setControllerMethod(DefaultControllerMethod.instanceFor(type, method)); Object methodResult = method.invoke(container.instanceFor(type), args); methodInfo.setControllerMethod(old); Type returnType = method.getGenericReturnType(); if (!(returnType == void.class)) { request.setAttribute(extractor.nameFor(returnType), methodResult); } if (response.isCommitted()) { logger.debug("Response already commited, not forwarding."); return null; } String path = resolver.pathFor(DefaultControllerMethod.instanceFor(type, method)); logger.debug("Forwarding to {}", path); request.getRequestDispatcher(path).forward(request, response); return null; } catch (InvocationTargetException e) { propagateIfPossible(e.getCause()); throw new ProxyInvocationException(e); } catch (Exception e) { throw new ProxyInvocationException(e); } } });