Package org.apache.tiles.request.servlet

Examples of org.apache.tiles.request.servlet.ServletRequest


     * @throws IOException If something goes wrong.
     */
    @Test
    public void testRender() throws IOException {
        VelocityView view = createMock(VelocityView.class);
        ServletRequest request = createMock(ServletRequest.class);
        HttpServletRequest httpRequest = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);
        ViewToolContext context = createMock(ViewToolContext.class);
        Template template = createMock(Template.class);
        Writer writer = createMock(Writer.class);

        expect(request.getRequest()).andReturn(httpRequest);
        expect(request.getResponse()).andReturn(response);
        expect(view.createContext(httpRequest, response)).andReturn(context);
        expect(view.getTemplate("/test.vm")).andReturn(template);
        expect(request.getWriter()).andReturn(writer);
        view.merge(template, context, writer);

        replay(view, request, httpRequest, response, context, template, writer);
        Renderer renderer = new VelocityRenderer(view);
        renderer.render("/test.vm", request);
View Full Code Here


     * @throws IOException If something goes wrong.
     */
    @Test(expected = CannotRenderException.class)
    public void testRenderException() throws IOException {
        VelocityView view = createMock(VelocityView.class);
        ServletRequest request = createMock(ServletRequest.class);

        replay(view, request);
        Renderer renderer = new VelocityRenderer(view);
        try {
            renderer.render(null, request);
View Full Code Here

    @Override
    public void render(String path, Request request) throws IOException {
        if (path == null) {
            throw new CannotRenderException("Cannot dispatch a null path");
        }
        ServletRequest servletRequest = org.apache.tiles.request.servlet.ServletUtil.getServletRequest(request);
        HttpServletRequest httpRequest = servletRequest.getRequest();
        HttpServletResponse httpResponse = servletRequest.getResponse();
        servlet.setValue(path);
        try {
            servlet.doGet(httpRequest,
                    new ExternalWriterHttpServletResponse(httpResponse,
                            request.getPrintWriter()));
View Full Code Here

            ApplicationContext applicationContext, Environment env) {
        HttpRequestHashModel requestModel = FreemarkerRequestUtil
                .getRequestHashModel(env);
        HttpServletRequest request = requestModel.getRequest();
        HttpServletResponse response = requestModel.getResponse();
        DispatchRequest enclosedRequest = new ServletRequest(
                applicationContext, request, response);
        return new FreemarkerRequest(enclosedRequest, env);
    }
View Full Code Here

        Environment env = new Environment(template, model, writer);
        Locale locale = Locale.ITALY;
        env.setLocale(locale);

        FreemarkerRequest request = FreemarkerRequest.createServletFreemarkerRequest(applicationContext, env);
        ServletRequest servletRequest = (ServletRequest) request.getWrappedRequest();
        assertEquals(httpRequest, servletRequest.getRequest());
        assertEquals(httpResponse, servletRequest.getResponse());
        verify(template, model, httpRequest, httpResponse, objectWrapper, applicationContext);
    }
View Full Code Here

                .setParameter("ContentType", "text/html")
                .setParameter("template_update_delay", "0")
                .setParameter("default_encoding", "ISO-8859-1")
                .setParameter("number_format", "0.##########").build();

        ServletRequest request = createMock(ServletRequest.class);
        HttpServletRequest httpRequest = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        HttpRequestHashModel requestModel = new HttpRequestHashModel(httpRequest, response, objectWrapper);
        HttpRequestParametersHashModel parametersModel = new HttpRequestParametersHashModel(httpRequest);

        expect(request.getRequest()).andReturn(httpRequest);
        expect(request.getResponse()).andReturn(response);
        expect(request.getPrintWriter()).andReturn(printWriter);
        expect(httpRequest.getSession(false)).andReturn(null);
        expect(httpRequest.getAttribute(ATTR_REQUEST_MODEL)).andReturn(requestModel);
        expect(httpRequest.getAttribute(ATTR_REQUEST_PARAMETERS_MODEL)).andReturn(parametersModel);
        response.setContentType("text/html; charset=ISO-8859-1");
        response.setHeader(eq("Cache-Control"), isA(String.class));
View Full Code Here

                .setParameter("ContentType", "text/html")
                .setParameter("template_update_delay", "0")
                .setParameter("default_encoding", "ISO-8859-1")
                .setParameter("number_format", "0.##########").build();

        ServletRequest request = createMock(ServletRequest.class);

        replay(request);
        try {
            renderer.render(null, request);
        } finally {
View Full Code Here

        expect(context.getRequest()).andReturn(servletRequest);
        expect(context.getResponse()).andReturn(servletResponse);

        replay(context, applicationContext, servletRequest, servletResponse);
        JspRequest request = JspRequest.createServletJspRequest(applicationContext, context);
        ServletRequest wrappedRequest = (ServletRequest) request.getWrappedRequest();
        assertEquals(servletRequest, wrappedRequest.getRequest());
        assertEquals(servletResponse, wrappedRequest.getResponse());
        verify(context, applicationContext, servletRequest, servletResponse);
    }
View Full Code Here

    public void render(String path, Request request) throws IOException {
        if (path == null) {
            throw new CannotRenderException("Cannot dispatch a null path");
        }

        ServletRequest servletRequest = ServletUtil.getServletRequest(request);
        // then get a context
        Context context = velocityView.createContext(servletRequest
                .getRequest(), servletRequest.getResponse());

        // get the template
        Template template = velocityView.getTemplate((String) path);

        // merge the template and context into the writer
View Full Code Here

     * @return The request.
     */
    public static VelocityRequest createVelocityRequest(
            ApplicationContext applicationContext, HttpServletRequest request,
            HttpServletResponse response, Context velocityContext, Writer writer) {
        DispatchRequest servletRequest = new ServletRequest(
                applicationContext, request, response);
        VelocityRequest velocityRequest = new VelocityRequest(
                servletRequest, velocityContext, writer);
        return velocityRequest;
    }
View Full Code Here

TOP

Related Classes of org.apache.tiles.request.servlet.ServletRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.