VelocityRequest extends AbstractViewRequest { @Override protected void doInclude(String path) throws IOException { ServletRequest servletRequest = org.apache.tiles.request.servlet.ServletUtil.getServletRequest(this); HttpServletRequest request = servletRequest.getRequest(); HttpServletResponse response = servletRequest.getResponse(); RequestDispatcher rd = request.getRequestDispatcher(path); if (rd == null) { throw new IOException("No request dispatcher returned for path '" + path + "'"); } PrintWriter printWriter = getPrintWriter(); try { rd.include(request, new ExternalWriterHttpServletResponse(response, printWriter)); } catch (ServletException ex) { throw ServletUtil.wrapServletException(ex, "ServletException including path '" + path + "'."); } } VelocityRequest(
            DispatchRequest enclosedRequest, Context ctx, Writer writer); static VelocityRequest createVelocityRequest(
            ApplicationContext applicationContext, HttpServletRequest request,
            HttpServletResponse response, Context velocityContext, Writer writer); @Override List<String> getAvailableScopes(); @Override PrintWriter getPrintWriter(); @Override Writer getWriter(); Map<String, Object> getPageScope(); @Override Map<String, Object> getContext(String scope);  }
@Test public void testDoInclude() throws IOException, ServletException { String path = "this way"; ServletRequest enclosedRequest = createMock(ServletRequest.class); HttpServletRequest servletRequest = createMock(HttpServletRequest.class); HttpServletResponse response = createMock(HttpServletResponse.class); RequestDispatcher dispatcher = createMock(RequestDispatcher.class); expect(servletRequest.getRequestDispatcher("this way")).andReturn(dispatcher); dispatcher.include(eq(servletRequest), isA(ExternalWriterHttpServletResponse.class)); replay(servletRequest, response, dispatcher); expect(enclosedRequest.getRequest()).andReturn(servletRequest); expect(enclosedRequest.getResponse()).andReturn(response); expect(enclosedRequest.getAvailableScopes()).andReturn(Collections.singletonList("parent")); replay(velocityContext, enclosedRequest); context = new VelocityRequest(enclosedRequest, velocityContext, writer); context.doInclude(path); verify(velocityContext, enclosedRequest, servletRequest, response, dispatcher); }