Package com.sun.faces.application

Examples of com.sun.faces.application.ViewHandlerResponseWrapper


            context.setResponseWriter(oldWriter);
        }

        // write any AFTER_VIEW_CONTENT to the response
        // side effect: AFTER_VIEW_CONTENT removed
        ViewHandlerResponseWrapper wrapper = (ViewHandlerResponseWrapper)
              RequestStateManager.remove(context, RequestStateManager.AFTER_VIEW_CONTENT);
        if (null != wrapper) {
            wrapper.flushToWriter(extContext.getResponseOutputWriter(),
                                  extContext.getResponseCharacterEncoding());
        }

        extContext.responseFlushBuffer();
View Full Code Here


        // save the original response
        Object originalResponse = extContext.getResponse();

        // replace the response with our wrapper
        ViewHandlerResponseWrapper wrapped = getWrapper(extContext);
        extContext.setResponse(wrapped);

        // build the view by executing the page
        extContext.dispatch(requestURI);

        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("After dispacthMessage to viewId " + requestURI);
        }

        // replace the original response
        extContext.setResponse(originalResponse);

        // Follow the JSTL 1.2 spec, section 7.4,
        // on handling status codes on a forward
        if (wrapped.getStatus() < 200 || wrapped.getStatus() > 299) {
            // flush the contents of the wrapper to the response
            // this is necessary as the user may be using a custom
            // error page - this content should be propagated
            wrapped.flushContentToWrappedResponse();
            return true;
        }

        // Put the AFTER_VIEW_CONTENT into request scope
        // temporarily
View Full Code Here

     */
    private static ViewHandlerResponseWrapper getWrapper(ExternalContext extContext) {

        Object response = extContext.getResponse();
        if (response instanceof HttpServletResponse) {
            return new ViewHandlerResponseWrapper((HttpServletResponse) response);
        }
        throw new IllegalArgumentException();

    }
View Full Code Here

    }


    public void testViewHandlerResponseWrapperStreamIO() throws Exception {

        ViewHandlerResponseWrapper w1 =
              new ViewHandlerResponseWrapper(getResponse());
        ServletOutputStream os = w1.getOutputStream();
        os.write('1');
        try {
            w1.getWriter();
            assertTrue(false);
        } catch (IllegalStateException ise) {
            // expected
        }
        os.flush();
        os.close();
        PrintWriter writer = null;
        try {
            writer = w1.getWriter();
        } catch (IllegalStateException ise) {
            assertTrue(false);
        }

        // we've closed the stream - and should have a fake
        // writer.  Ensure writing to it doesn't impact the result;
        writer.print("Some junk");
        StringWriter buf = new StringWriter();
        w1.flushToWriter(buf, "ISO-8859-1");
        assertTrue(!buf.toString().contains("Some junk"));

        // ensure that the content that was written to the stream is
        // present
        assertTrue("1".equals(buf.toString()));

        w1 = new ViewHandlerResponseWrapper(getResponse());
        os = w1.getOutputStream();
        // flushBuffer should commit the response so getWriter()
        // should throw no Exception
        w1.flushBuffer();
        try {
            w1.getWriter();
        } catch (IllegalStateException ise) {
            assertTrue(false);
        }

    }
View Full Code Here

    }

    public void testViewHandlerResponseWrapperCharIO() throws Exception {

        ViewHandlerResponseWrapper w1 =
              new ViewHandlerResponseWrapper(getResponse());
        PrintWriter pw = w1.getWriter();
        pw.write("some stuff");
        try {
            w1.getOutputStream();
            assertTrue(false);
        } catch (IllegalStateException ise) {
            // expected
        }
        pw.flush();
        pw.close();
        ServletOutputStream os = null;
        try {
            os = w1.getOutputStream();
        } catch (IllegalStateException ise) {
            assertTrue(false);
        }

        // we've closed the stream - and should have a fake
        // writer.  Ensure writing to it doesn't impact the result;
        os.write('1');
        StringWriter buf = new StringWriter();
        w1.flushToWriter(buf, "ISO-8859-1");
        assertTrue(!buf.toString().contains("1"));

        // ensure that the content that was written to the stream is
        // present
        assertTrue("some stuff".equals(buf.toString()));

        w1 = new ViewHandlerResponseWrapper(getResponse());
        pw = w1.getWriter();
        // flushBuffer should commit the response so getWriter()
        // should throw no Exception
        w1.flushBuffer();
        try {
            w1.getOutputStream();
        } catch (IllegalStateException ise) {
            assertTrue(false);
        }

    }
View Full Code Here

            context.setResponseWriter(oldWriter);
        }

        // write any AFTER_VIEW_CONTENT to the response
        // side effect: AFTER_VIEW_CONTENT removed
        ViewHandlerResponseWrapper wrapper = (ViewHandlerResponseWrapper)
              RequestStateManager.remove(context, RequestStateManager.AFTER_VIEW_CONTENT);
        if (null != wrapper) {
            wrapper.flushToWriter(extContext.getResponseOutputWriter(),
                                  extContext.getResponseCharacterEncoding());
        }

        extContext.responseFlushBuffer();
View Full Code Here

        // save the original response
        Object originalResponse = extContext.getResponse();

        // replace the response with our wrapper
        ViewHandlerResponseWrapper wrapped = getWrapper(extContext);
        extContext.setResponse(wrapped);

        try
        {

          // build the view by executing the page
          extContext.dispatch(requestURI);

          if (LOGGER.isLoggable(Level.FINE)) {
              LOGGER.fine("After dispacthMessage to viewId " + requestURI);
          }
        }
        finally
        {
          // replace the original response
          extContext.setResponse(originalResponse);
        }

        // Follow the JSTL 1.2 spec, section 7.4,
        // on handling status codes on a forward
        if (wrapped.getStatus() < 200 || wrapped.getStatus() > 299) {
            // flush the contents of the wrapper to the response
            // this is necessary as the user may be using a custom
            // error page - this content should be propagated
            wrapped.flushContentToWrappedResponse();
            return true;
        }

        // Put the AFTER_VIEW_CONTENT into request scope
        // temporarily
View Full Code Here

     */
    private static ViewHandlerResponseWrapper getWrapper(ExternalContext extContext) {

        Object response = extContext.getResponse();
        if (response instanceof HttpServletResponse) {
            return new ViewHandlerResponseWrapper((HttpServletResponse) response);
        }
        throw new IllegalArgumentException();

    }
View Full Code Here

            context.setResponseWriter(oldWriter);
        }

        // write any AFTER_VIEW_CONTENT to the response
        // side effect: AFTER_VIEW_CONTENT removed
        ViewHandlerResponseWrapper wrapper = (ViewHandlerResponseWrapper)
              RequestStateManager.remove(context, RequestStateManager.AFTER_VIEW_CONTENT);
        if (null != wrapper) {
            wrapper.flushToWriter(extContext.getResponseOutputWriter(),
                                  extContext.getResponseCharacterEncoding());
        }

        extContext.responseFlushBuffer();
View Full Code Here

        // save the original response
        Object originalResponse = extContext.getResponse();

        // replace the response with our wrapper
        ViewHandlerResponseWrapper wrapped = getWrapper(extContext);
        extContext.setResponse(wrapped);

        // build the view by executing the page
        extContext.dispatch(requestURI);

        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("After dispacthMessage to viewId " + requestURI);
        }

        // replace the original response
        extContext.setResponse(originalResponse);

        // Follow the JSTL 1.2 spec, section 7.4,
        // on handling status codes on a forward
        if (wrapped.getStatus() < 200 || wrapped.getStatus() > 299) {
            // flush the contents of the wrapper to the response
            // this is necessary as the user may be using a custom
            // error page - this content should be propagated
            wrapped.flushContentToWrappedResponse();
            return true;
        }

        // Put the AFTER_VIEW_CONTENT into request scope
        // temporarily
View Full Code Here

TOP

Related Classes of com.sun.faces.application.ViewHandlerResponseWrapper

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.