javax.servlet.ServletRequestWrapper Java Examples

The following examples show how to use javax.servlet.ServletRequestWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyContinuationProviderFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
public ContinuationProvider createContinuationProvider(Message inMessage,
                                                       HttpServletRequest req,
                                                       HttpServletResponse resp) {
    if (!disableJettyContinuations) {
        ServletRequest r2 = req;
        while (r2 instanceof ServletRequestWrapper) {
            r2 = ((ServletRequestWrapper)r2).getRequest();
        }
        if (!r2.getClass().getName().contains("jetty")) {
            return null;
        }

        try {
            Method m = r2.getClass().getMethod("isAsyncSupported");
            Object o = ReflectionUtil.setAccessible(m).invoke(r2);
            if (((Boolean)o).booleanValue()) {
                return new JettyContinuationProvider(req, resp, inMessage);
            }
        } catch (Throwable t) {
            //ignore - either not a proper Jetty request object or classloader issue
            //or similar.
        }
    }
    return null;
}
 
Example #2
Source File: PortletAsyncContextImpl.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
/**
 * Finds and returns the portlet servlet request wrapper that provides async functionality
 * 
 * @return
 */
@Override
public HttpServletRequestWrapper getAsyncRequestWrapper() {
   HttpServletPortletRequestWrapper wrapper = null;

   // find our wrapper in case it was wrapped again

   ServletRequest wreq = prctx.getAsyncServletRequest();
   while ((wreq instanceof ServletRequestWrapper) && !(wreq instanceof HttpServletPortletRequestWrapper)) {
      wreq = ((ServletRequestWrapper) wreq).getRequest();
   }

   if (wreq instanceof HttpServletPortletRequestWrapper) {
      wrapper = (HttpServletPortletRequestWrapper) wreq;
   }

   return wrapper;
}
 
Example #3
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException {
    final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    if (!servletContext.getDeployment().getDeploymentInfo().isAllowNonStandardWrappers()) {
        if (servletRequestContext.getOriginalRequest() != servletRequest) {
            if (!(servletRequest instanceof ServletRequestWrapper)) {
                throw UndertowServletMessages.MESSAGES.requestWasNotOriginalOrWrapper(servletRequest);
            }
        }
        if (servletRequestContext.getOriginalResponse() != servletResponse) {
            if (!(servletResponse instanceof ServletResponseWrapper)) {
                throw UndertowServletMessages.MESSAGES.responseWasNotOriginalOrWrapper(servletResponse);
            }
        }
    }
    if (!isAsyncSupported()) {
        throw UndertowServletMessages.MESSAGES.startAsyncNotAllowed();
    } else if (asyncStarted) {
        throw UndertowServletMessages.MESSAGES.asyncAlreadyStarted();
    }
    asyncStarted = true;
    servletRequestContext.setServletRequest(servletRequest);
    servletRequestContext.setServletResponse(servletResponse);
    return asyncContext = new AsyncContextImpl(exchange, servletRequest, servletResponse, servletRequestContext, true, asyncContext);
}
 
Example #4
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException {
    final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    if (!servletContext.getDeployment().getDeploymentInfo().isAllowNonStandardWrappers()) {
        if (servletRequestContext.getOriginalRequest() != servletRequest) {
            if (!(servletRequest instanceof ServletRequestWrapper)) {
                throw UndertowServletMessages.MESSAGES.requestWasNotOriginalOrWrapper(servletRequest);
            }
        }
        if (servletRequestContext.getOriginalResponse() != servletResponse) {
            if (!(servletResponse instanceof ServletResponseWrapper)) {
                throw UndertowServletMessages.MESSAGES.responseWasNotOriginalOrWrapper(servletResponse);
            }
        }
    }
    if (!isAsyncSupported()) {
        throw UndertowServletMessages.MESSAGES.startAsyncNotAllowed();
    } else if (asyncStarted) {
        throw UndertowServletMessages.MESSAGES.asyncAlreadyStarted();
    }
    asyncStarted = true;
    servletRequestContext.setServletRequest(servletRequest);
    servletRequestContext.setServletResponse(servletResponse);
    return asyncContext = new AsyncContextImpl(exchange, servletRequest, servletResponse, servletRequestContext, true, asyncContext);
}
 
Example #5
Source File: HttpRequestWrapper.java    From HttpSessionReplacer with MIT License 5 votes vote down vote up
/**
 * Creates request wrapper from original requests.
 *
 * @param req
 *          original servlet request
 * @param servletContext
 */
public HttpRequestWrapper(HttpServletRequest req, ServletContext servletContext) {
  super(req);
  this.servletContext = servletContext;
  manager = (SessionManager)servletContext.getAttribute(Attributes.SESSION_MANAGER);
  ServletRequest originalRequest = req;
  while (originalRequest instanceof ServletRequestWrapper) {
    if (originalRequest instanceof HttpRequestWrapper) {
      break;
    }
    originalRequest = ((ServletRequestWrapper)originalRequest).getRequest();
  }

  embeddedRequest = (originalRequest instanceof HttpRequestWrapper) ? (HttpRequestWrapper)originalRequest : null;
}
 
Example #6
Source File: DefaultAsyncContext.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Unwrap the servlet request.
 *
 * @param <T> the type.
 * @param request the request to unwrap.
 * @return the unwrapped request.
 */
@SuppressWarnings("unchecked")
private <T extends ServletRequest> T unwrapFully(ServletRequest request) {
    ServletRequest currentRequest = request;
    while (currentRequest instanceof ServletRequestWrapper) {
        ServletRequestWrapper wrapper = (ServletRequestWrapper) currentRequest;
        currentRequest = wrapper.getRequest();
    }
    return (T) currentRequest;
}
 
Example #7
Source File: DefaultWebApplicationRequest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public HttpServletRequest unwrap(HttpServletRequest request) {
    ServletRequest currentRequest = request;
    while (currentRequest instanceof ServletRequestWrapper) {
        ServletRequestWrapper wrapper = (ServletRequestWrapper) currentRequest;
        currentRequest = wrapper.getRequest();
    }
    return (WebApplicationRequest) currentRequest;
}
 
Example #8
Source File: RemoteIpFilter.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public PushBuilder getPushBuilder() {
    ServletRequest current = getRequest();
    while (current instanceof ServletRequestWrapper) {
        current = ((ServletRequestWrapper) current).getRequest();
    }
    if (current instanceof RequestFacade) {
        return ((RequestFacade) current).newPushBuilder(this);
    } else {
        return null;
    }
}
 
Example #9
Source File: TestAsyncContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void service(ServletRequest req, ServletResponse resp)
        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))) {
            asyncContext.dispatch();
        } else {
            asyncContext.dispatch("/target");
        }
        try {
            asyncContext.dispatch("/nonExistingServlet");
            TestAsyncContextImpl.track("FAIL");
        } catch (IllegalStateException e) {
            TestAsyncContextImpl.track("OK");
        }
    } else {
        TestAsyncContextImpl.track("DispatchingGenericServletGet-");
    }
}
 
Example #10
Source File: TestAsyncContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void service(ServletRequest req, ServletResponse res)
        throws ServletException, IOException {
    if (req instanceof ServletRequestWrapper
            && res instanceof ServletResponseWrapper) {
        TestAsyncContextImpl.track("CustomGenericServletGet-");
    }
}
 
Example #11
Source File: WebUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return an appropriate request object of the specified type, if available,
 * unwrapping the given request as far as necessary.
 * @param request the servlet request to introspect
 * @param requiredType the desired type of request object
 * @return the matching request object, or {@code null} if none
 * of that type is available
 */
@SuppressWarnings("unchecked")
public static <T> T getNativeRequest(ServletRequest request, Class<T> requiredType) {
	if (requiredType != null) {
		if (requiredType.isInstance(request)) {
			return (T) request;
		}
		else if (request instanceof ServletRequestWrapper) {
			return getNativeRequest(((ServletRequestWrapper) request).getRequest(), requiredType);
		}
	}
	return null;
}
 
Example #12
Source File: ApplicationDispatcher.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Unwrap the request if we have wrapped it.
 */
private void unwrapRequest(State state) {

    if (state.wrapRequest == null)
        return;

    if (state.outerRequest.isAsyncStarted()) {
        if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) {
            return;
        }
    }

    ServletRequest previous = null;
    ServletRequest current = state.outerRequest;
    while (current != null) {

        // If we run into the container request we are done
        if ((current instanceof Request)
            || (current instanceof RequestFacade))
            break;

        // Remove the current request if it is our wrapper
        if (current == state.wrapRequest) {
            ServletRequest next =
              ((ServletRequestWrapper) current).getRequest();
            if (previous == null)
                state.outerRequest = next;
            else
                ((ServletRequestWrapper) previous).setRequest(next);
            break;
        }

        // Advance to the next request in the chain
        previous = current;
        current = ((ServletRequestWrapper) current).getRequest();

    }

}
 
Example #13
Source File: WebUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return an appropriate request object of the specified type, if available,
 * unwrapping the given request as far as necessary.
 * @param request the servlet request to introspect
 * @param requiredType the desired type of request object
 * @return the matching request object, or {@code null} if none
 * of that type is available
 */
@SuppressWarnings("unchecked")
public static <T> T getNativeRequest(ServletRequest request, Class<T> requiredType) {
	if (requiredType != null) {
		if (requiredType.isInstance(request)) {
			return (T) request;
		}
		else if (request instanceof ServletRequestWrapper) {
			return getNativeRequest(((ServletRequestWrapper) request).getRequest(), requiredType);
		}
	}
	return null;
}
 
Example #14
Source File: ApplicationDispatcher.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Unwrap the request if we have wrapped it.
 */
private void unwrapRequest(State state) {

    if (state.wrapRequest == null)
        return;

    if (state.outerRequest.isAsyncStarted()) {
        if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) {
            return;
        }
    }

    ServletRequest previous = null;
    ServletRequest current = state.outerRequest;
    while (current != null) {

        // If we run into the container request we are done
        if ((current instanceof Request)
            || (current instanceof RequestFacade))
            break;

        // Remove the current request if it is our wrapper
        if (current == state.wrapRequest) {
            ServletRequest next =
              ((ServletRequestWrapper) current).getRequest();
            if (previous == null)
                state.outerRequest = next;
            else
                ((ServletRequestWrapper) previous).setRequest(next);
            break;
        }

        // Advance to the next request in the chain
        previous = current;
        current = ((ServletRequestWrapper) current).getRequest();

    }

}
 
Example #15
Source File: TestAsyncContextImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void service(ServletRequest req, ServletResponse resp)
        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))) {
            asyncContext.dispatch();
        } else {
            asyncContext.dispatch("/target");
        }
        try {
            asyncContext.dispatch("/nonExistingServlet");
            TestAsyncContextImpl.track("FAIL");
        } catch (IllegalStateException e) {
            TestAsyncContextImpl.track("OK");
        }
    } else {
        TestAsyncContextImpl.track("DispatchingGenericServletGet-");
    }
}
 
Example #16
Source File: TestAsyncContextImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void service(ServletRequest req, ServletResponse res)
        throws ServletException, IOException {
    if (req instanceof ServletRequestWrapper
            && res instanceof ServletResponseWrapper) {
        TestAsyncContextImpl.track("CustomGenericServletGet-");
    }
}
 
Example #17
Source File: Jetty9Request.java    From gocd with Apache License 2.0 5 votes vote down vote up
public Jetty9Request(javax.servlet.ServletRequest request) {
    while (request instanceof ServletRequestWrapper) {
        request = ((ServletRequestWrapper) request).getRequest();
    }

    this.request = (Request) request;
}
 
Example #18
Source File: WebUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return an appropriate request object of the specified type, if available,
 * unwrapping the given request as far as necessary.
 * @param request the servlet request to introspect
 * @param requiredType the desired type of request object
 * @return the matching request object, or {@code null} if none
 * of that type is available
 */
@SuppressWarnings("unchecked")
@Nullable
public static <T> T getNativeRequest(ServletRequest request, @Nullable Class<T> requiredType) {
	if (requiredType != null) {
		if (requiredType.isInstance(request)) {
			return (T) request;
		}
		else if (request instanceof ServletRequestWrapper) {
			return getNativeRequest(((ServletRequestWrapper) request).getRequest(), requiredType);
		}
	}
	return null;
}
 
Example #19
Source File: ApplicationHttpRequest.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public PushBuilder newPushBuilder() {
    ServletRequest current = getRequest();
    while (current instanceof ServletRequestWrapper) {
        current = ((ServletRequestWrapper) current).getRequest();
    }
    if (current instanceof RequestFacade) {
        return ((RequestFacade) current).newPushBuilder(this);
    } else {
        return null;
    }
}
 
Example #20
Source File: ApplicationDispatcher.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Unwrap the request if we have wrapped it.
 */
private void unwrapRequest(State state) {

    if (state.wrapRequest == null)
        return;

    if (state.outerRequest.isAsyncStarted()) {
        if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) {
            return;
        }
    }

    ServletRequest previous = null;
    ServletRequest current = state.outerRequest;
    while (current != null) {

        // If we run into the container request we are done
        if ((current instanceof Request)
            || (current instanceof RequestFacade))
            break;

        // Remove the current request if it is our wrapper
        if (current == state.wrapRequest) {
            ServletRequest next =
              ((ServletRequestWrapper) current).getRequest();
            if (previous == null)
                state.outerRequest = next;
            else
                ((ServletRequestWrapper) previous).setRequest(next);
            break;
        }

        // Advance to the next request in the chain
        previous = current;
        current = ((ServletRequestWrapper) current).getRequest();

    }

}
 
Example #21
Source File: TestAsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void service(ServletRequest req, ServletResponse resp)
        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))) {
            asyncContext.dispatch();
        } else {
            asyncContext.dispatch("/target");
        }
        try {
            asyncContext.dispatch("/nonExistingServlet");
            TestAsyncContextImpl.track("FAIL");
        } catch (IllegalStateException e) {
            TestAsyncContextImpl.track("OK");
        }
    } else {
        TestAsyncContextImpl.track("DispatchingGenericServletGet-");
    }
}
 
Example #22
Source File: TestAsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void service(ServletRequest req, ServletResponse res)
        throws ServletException, IOException {
    if (req instanceof ServletRequestWrapper
            && res instanceof ServletResponseWrapper) {
        TestAsyncContextImpl.track("CustomGenericServletGet-");
    }
}
 
Example #23
Source File: DefaultServletRequestDispatcher.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private HttpServletRequest findHttpServletRequestInChain(ServletRequest request) {
    ServletRequest currentRequest = request;
    while (currentRequest instanceof ServletRequestWrapper) {
        ServletRequestWrapper wrapper = (ServletRequestWrapper) currentRequest;
        currentRequest = wrapper.getRequest();

        if (currentRequest instanceof HttpServletRequest) {
            return (HttpServletRequest) currentRequest;
        }
    }
    return null;
}
 
Example #24
Source File: WebUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return an appropriate request object of the specified type, if available,
 * unwrapping the given request as far as necessary.
 * @param request the servlet request to introspect
 * @param requiredType the desired type of request object
 * @return the matching request object, or {@code null} if none
 * of that type is available
 */
@SuppressWarnings("unchecked")
@Nullable
public static <T> T getNativeRequest(ServletRequest request, @Nullable Class<T> requiredType) {
	if (requiredType != null) {
		if (requiredType.isInstance(request)) {
			return (T) request;
		}
		else if (request instanceof ServletRequestWrapper) {
			return getNativeRequest(((ServletRequestWrapper) request).getRequest(), requiredType);
		}
	}
	return null;
}
 
Example #25
Source File: ServletUtil.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
/**
 * unWrapper
 * @param request request
 * @return ServletHttpServletRequest
 */
public static ServletHttpServletRequest unWrapper(ServletRequest request){
    if(request instanceof ServletRequestWrapper){
        return unWrapper(((ServletRequestWrapper) request).getRequest());
    }
    if(request instanceof ServletHttpServletRequest){
        return (ServletHttpServletRequest) request;
    }
    return null;
}
 
Example #26
Source File: WebLogicRequestUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static Object getNativeRequest(ServletRequest request) {
	while (request instanceof ServletRequestWrapper) {
		request = ((ServletRequestWrapper) request).getRequest();
	}
	return request;
}
 
Example #27
Source File: WebSocketServlet.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    // Information required to send the server handshake message
    String key;
    String subProtocol = null;
    List<String> extensions = Collections.emptyList();

    if (!headerContainsToken(req, "upgrade", "websocket")) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    if (!headerContainsToken(req, "connection", "upgrade")) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    if (!headerContainsToken(req, "sec-websocket-version", "13")) {
        resp.setStatus(426);
        resp.setHeader("Sec-WebSocket-Version", "13");
        return;
    }

    key = req.getHeader("Sec-WebSocket-Key");
    if (key == null) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    String origin = req.getHeader("Origin");
    if (!verifyOrigin(origin)) {
        resp.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    List<String> subProtocols = getTokensFromHeader(req,
            "Sec-WebSocket-Protocol");
    if (!subProtocols.isEmpty()) {
        subProtocol = selectSubProtocol(subProtocols);

    }

    // TODO Read client handshake - Sec-WebSocket-Extensions

    // TODO Extensions require the ability to specify something (API TBD)
    //      that can be passed to the Tomcat internals and process extension
    //      data present when the frame is fragmented.

    // If we got this far, all is good. Accept the connection.
    resp.setHeader("Upgrade", "websocket");
    resp.setHeader("Connection", "upgrade");
    resp.setHeader("Sec-WebSocket-Accept", getWebSocketAccept(key));
    if (subProtocol != null) {
        resp.setHeader("Sec-WebSocket-Protocol", subProtocol);
    }
    if (!extensions.isEmpty()) {
        // TODO
    }

    WsHttpServletRequestWrapper wrapper = new WsHttpServletRequestWrapper(req);
    StreamInbound inbound = createWebSocketInbound(subProtocol, wrapper);
    wrapper.invalidate();

    // Small hack until the Servlet API provides a way to do this.
    ServletRequest inner = req;
    // Unwrap the request
    while (inner instanceof ServletRequestWrapper) {
        inner = ((ServletRequestWrapper) inner).getRequest();
    }
    if (inner instanceof RequestFacade) {
        ((RequestFacade) inner).doUpgrade(inbound);
    } else {
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                sm.getString("servlet.reqUpgradeFail"));
    }
}
 
Example #28
Source File: ApplicationDispatcher.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Create and return a request wrapper that has been inserted in the
 * appropriate spot in the request chain.
 */
private ServletRequest wrapRequest(State state) {

    // Locate the request we should insert in front of
    ServletRequest previous = null;
    ServletRequest current = state.outerRequest;
    while (current != null) {
        if(state.hrequest == null && (current instanceof HttpServletRequest))
            state.hrequest = (HttpServletRequest)current;
        if (!(current instanceof ServletRequestWrapper))
            break;
        if (current instanceof ApplicationHttpRequest)
            break;
        if (current instanceof ApplicationRequest)
            break;
        previous = current;
        current = ((ServletRequestWrapper) current).getRequest();
    }

    // Instantiate a new wrapper at this point and insert it in the chain
    ServletRequest wrapper = null;
    if ((current instanceof ApplicationHttpRequest) ||
        (current instanceof Request) ||
        (current instanceof HttpServletRequest)) {
        // Compute a crossContext flag
        HttpServletRequest hcurrent = (HttpServletRequest) current;
        boolean crossContext = false;
        if ((state.outerRequest instanceof ApplicationHttpRequest) ||
            (state.outerRequest instanceof Request) ||
            (state.outerRequest instanceof HttpServletRequest)) {
            HttpServletRequest houterRequest =
                (HttpServletRequest) state.outerRequest;
            Object contextPath = houterRequest.getAttribute(
                    RequestDispatcher.INCLUDE_CONTEXT_PATH);
            if (contextPath == null) {
                // Forward
                contextPath = houterRequest.getContextPath();
            }
            crossContext = !(context.getPath().equals(contextPath));
        }
        wrapper = new ApplicationHttpRequest
            (hcurrent, context, crossContext);
    } else {
        wrapper = new ApplicationRequest(current);
    }
    if (previous == null)
        state.outerRequest = wrapper;
    else
        ((ServletRequestWrapper) previous).setRequest(wrapper);
    state.wrapRequest = wrapper;
    return wrapper;

}
 
Example #29
Source File: ApplicationDispatcher.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private void checkSameObjects(ServletRequest appRequest,
        ServletResponse appResponse) throws ServletException {
    ServletRequest originalRequest =
        ApplicationFilterChain.getLastServicedRequest();
    ServletResponse originalResponse =
        ApplicationFilterChain.getLastServicedResponse();

    // Some forwards, eg from valves will not set original values
    if (originalRequest == null || originalResponse == null) {
        return;
    }

    boolean same = false;
    ServletRequest dispatchedRequest = appRequest;

    //find the request that was passed into the service method
    while (originalRequest instanceof ServletRequestWrapper &&
            ((ServletRequestWrapper) originalRequest).getRequest()!=null ) {
        originalRequest =
            ((ServletRequestWrapper) originalRequest).getRequest();
    }
    //compare with the dispatched request
    while (!same) {
        if (originalRequest.equals(dispatchedRequest)) {
            same = true;
        }
        if (!same && dispatchedRequest instanceof ServletRequestWrapper) {
            dispatchedRequest =
                ((ServletRequestWrapper) dispatchedRequest).getRequest();
        } else {
            break;
        }
    }
    if (!same) {
        throw new ServletException(sm.getString(
                "applicationDispatcher.specViolation.request"));
    }

    same = false;
    ServletResponse dispatchedResponse = appResponse;

    //find the response that was passed into the service method
    while (originalResponse instanceof ServletResponseWrapper &&
            ((ServletResponseWrapper) originalResponse).getResponse() !=
                null ) {
        originalResponse =
            ((ServletResponseWrapper) originalResponse).getResponse();
    }
    //compare with the dispatched response
    while (!same) {
        if (originalResponse.equals(dispatchedResponse)) {
            same = true;
        }

        if (!same && dispatchedResponse instanceof ServletResponseWrapper) {
            dispatchedResponse =
                ((ServletResponseWrapper) dispatchedResponse).getResponse();
        } else {
            break;
        }
    }

    if (!same) {
        throw new ServletException(sm.getString(
                "applicationDispatcher.specViolation.response"));
    }
}
 
Example #30
Source File: ApplicationDispatcher.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void checkSameObjects(ServletRequest appRequest,
        ServletResponse appResponse) throws ServletException {
    ServletRequest originalRequest =
        ApplicationFilterChain.getLastServicedRequest();
    ServletResponse originalResponse =
        ApplicationFilterChain.getLastServicedResponse();
    
    // Some forwards, eg from valves will not set original values 
    if (originalRequest == null || originalResponse == null) {
        return;
    }
    
    boolean same = false;
    ServletRequest dispatchedRequest = appRequest;
    
    //find the request that was passed into the service method
    while (originalRequest instanceof ServletRequestWrapper &&
            ((ServletRequestWrapper) originalRequest).getRequest()!=null ) {
        originalRequest =
            ((ServletRequestWrapper) originalRequest).getRequest();
    }
    //compare with the dispatched request
    while (!same) {
        if (originalRequest.equals(dispatchedRequest)) {
            same = true;
        }
        if (!same && dispatchedRequest instanceof ServletRequestWrapper) {
            dispatchedRequest =
                ((ServletRequestWrapper) dispatchedRequest).getRequest();
        } else {
            break;
        }
    }
    if (!same) {
        throw new ServletException(sm.getString(
                "applicationDispatcher.specViolation.request"));
    }
    
    same = false;
    ServletResponse dispatchedResponse = appResponse;
    
    //find the response that was passed into the service method
    while (originalResponse instanceof ServletResponseWrapper &&
            ((ServletResponseWrapper) originalResponse).getResponse() != 
                null ) {
        originalResponse =
            ((ServletResponseWrapper) originalResponse).getResponse();
    }
    //compare with the dispatched response
    while (!same) {
        if (originalResponse.equals(dispatchedResponse)) {
            same = true;
        }
        
        if (!same && dispatchedResponse instanceof ServletResponseWrapper) {
            dispatchedResponse =
                ((ServletResponseWrapper) dispatchedResponse).getResponse();
        } else {
            break;
        }
    }

    if (!same) {
        throw new ServletException(sm.getString(
                "applicationDispatcher.specViolation.response"));
    }
}