Package javax.servlet

Examples of javax.servlet.ServletRequestWrapper


    ServletRequest req = getRequest();
    while (req != null) {
      if (req instanceof CauchoRequest)
        return ((CauchoRequest) req).getRequestDepth(depth + 1);
      else if (req instanceof ServletRequestWrapper) {
        ServletRequestWrapper reqWrap = (ServletRequestWrapper) req;

        req = reqWrap.getRequest();
      }
      else
        break;
    }
View Full Code Here


  public void include(ServletRequest topRequest, ServletResponse topResponse)
    throws IOException, ServletException
  {
    HttpServletRequest parentReq;
    ServletRequestWrapper reqWrapper = null;

    if (topRequest instanceof ServletRequestWrapper) {
      ServletRequest request = topRequest;

      while (request instanceof ServletRequestWrapper) {
        reqWrapper = (ServletRequestWrapper) request;

        request = ((ServletRequestWrapper) request).getRequest();
      }

      parentReq = (HttpServletRequest) request;
    } else if (topRequest instanceof HttpServletRequest) {
      parentReq = (HttpServletRequest) topRequest;
    } else {
      throw new IllegalStateException(L.l(
        "expected instance of ServletRequestWrapper at `{0}'", topResponse));
    }

    HttpServletResponse parentRes;
    ServletResponseWrapper resWrapper = null;

    if (topResponse instanceof ServletResponseWrapper) {
      ServletResponse response = topResponse;

      while (response instanceof ServletResponseWrapper) {
        resWrapper = (ServletResponseWrapper) response;

        response = ((ServletResponseWrapper) response).getResponse();
      }

      parentRes = (HttpServletResponse) response;
    } else if (topResponse instanceof HttpServletResponse) {
      parentRes = (HttpServletResponse) topResponse;
    } else {
      throw new IllegalStateException(L.l(
        "expected instance of ServletResponse at `{0}'", topResponse));
    }

    RequestAdapter subRequest = RequestAdapter.create();
    subRequest.init(parentReq, parentRes, _webApp);

    DispatchResponse subResponse = new DispatchResponse();
    subResponse.init(parentRes);

    if (reqWrapper != null) {
      reqWrapper.setRequest(subRequest);
    } else {
      topRequest = subRequest;
    }

    if (resWrapper != null) {
      resWrapper.setResponse(subResponse);
    } else {
      topResponse = subResponse;
    }

    try {
      _includeFilterChain.doFilter(topRequest, topResponse);
    } finally {
      subResponse.finish();
      RequestAdapter.free(subRequest);

      if (reqWrapper != null)
        reqWrapper.setRequest(parentReq);

      if (resWrapper != null)
        resWrapper.setResponse(parentRes);
    }
View Full Code Here

     * Unwrapping a wrapper request should return in the request.
     */
    @Test
    public void testUnwrappingWrappedRequest() {
        final ServletRequest req = context.mock(ServletRequest.class);
        final ServletRequestWrapper wrapper = new ServletRequestWrapper(req);
       
        ServletRequest unwrapped = ExternalServletContextWrapper.
            RequestDispatcherWrapper.unwrapServletRequest(wrapper);
       
        assertEquals(req, unwrapped);
View Full Code Here

    }
   
    @Test
    public void testUnwrappingDoubleWrappedRequest() {
        final ServletRequest req = context.mock(ServletRequest.class);
        final ServletRequestWrapper wrapper = new ServletRequestWrapper(req);
        final ServletRequestWrapper wrapper2 = new ServletRequestWrapper(wrapper);
       
        ServletRequest unwrapped = ExternalServletContextWrapper.
            RequestDispatcherWrapper.unwrapServletRequest(wrapper2);
       
        assertEquals(req, unwrapped);
View Full Code Here

                throws ServletException, IOException {
            if (DispatcherType.ASYNC != req.getDispatcherType()) {
                AsyncContext asyncContext;
                if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
                    asyncContext = req.startAsync(
                            new ServletRequestWrapper(req),
                            new ServletResponseWrapper(resp));
                } else {
                    asyncContext = req.startAsync();
                }
                if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
View Full Code Here

                throws ServletException, IOException {
            if (DispatcherType.ASYNC != req.getDispatcherType()) {
                AsyncContext asyncContext;
                if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
                    asyncContext = req.startAsync(
                            new ServletRequestWrapper(req),
                            new ServletResponseWrapper(resp));
                } else {
                    asyncContext = req.startAsync();
                }
                if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
View Full Code Here

   * If the specified request was a forwarded or included request, unwrap it
   * and return the original request.
   */
  public static HttpServletRequest unwrap(HttpServletRequest req) {
    if (req instanceof ServletRequestWrapper) {
      ServletRequestWrapper wrapper = (ServletRequestWrapper) req;
      req = (HttpServletRequest) wrapper.getRequest(); // unwrap
    }
    return req;
  }
View Full Code Here

                throws ServletException, IOException {
            if (DispatcherType.ASYNC != req.getDispatcherType()) {
                AsyncContext asyncContext;
                if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
                    asyncContext = req.startAsync(
                            new ServletRequestWrapper(req),
                            new ServletResponseWrapper(resp));
                } else {
                    asyncContext = req.startAsync();
                }
                if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
View Full Code Here

                throws ServletException, IOException {
            if (DispatcherType.ASYNC != req.getDispatcherType()) {
                AsyncContext asyncContext;
                if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
                    asyncContext = req.startAsync(
                            new ServletRequestWrapper(req),
                            new ServletResponseWrapper(resp));
                } else {
                    asyncContext = req.startAsync();
                }
                if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
View Full Code Here

                throws ServletException, IOException {
            if (DispatcherType.ASYNC != req.getDispatcherType()) {
                AsyncContext asyncContext;
                if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
                    asyncContext = req.startAsync(
                            new ServletRequestWrapper(req),
                            new ServletResponseWrapper(resp));
                } else {
                    asyncContext = req.startAsync();
                }
                if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
View Full Code Here

TOP

Related Classes of javax.servlet.ServletRequestWrapper

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.