Search in sources :

Example 21 with Request

use of org.apache.catalina.connector.Request in project tomcat by apache.

the class ApplicationDispatcher method unwrapRequest.

/**
     * 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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.catalina.connector.Request) ServletRequest(javax.servlet.ServletRequest) RequestFacade(org.apache.catalina.connector.RequestFacade)

Example 22 with Request

use of org.apache.catalina.connector.Request in project tomcat by apache.

the class TestAsyncContextImpl method testAsyncListenerSupplyRequestResponse.

@Test
public void testAsyncListenerSupplyRequestResponse() {
    final ServletRequest servletRequest = EasyMock.createMock(ServletRequest.class);
    final ServletResponse servletResponse = EasyMock.createMock(ServletResponse.class);
    final AsyncListener listener = new AsyncListener() {

        @Override
        public void onTimeout(AsyncEvent event) throws IOException {
            checkRequestResponse(event);
        }

        @Override
        public void onStartAsync(AsyncEvent event) throws IOException {
            checkRequestResponse(event);
        }

        @Override
        public void onError(AsyncEvent event) throws IOException {
            checkRequestResponse(event);
        }

        @Override
        public void onComplete(AsyncEvent event) throws IOException {
            checkRequestResponse(event);
        }

        private void checkRequestResponse(AsyncEvent event) {
            assertEquals(servletRequest, event.getSuppliedRequest());
            assertEquals(servletResponse, event.getSuppliedResponse());
        }
    };
    final Context context = new TesterContext();
    final Response response = new Response();
    final Request request = new Request(null);
    request.setCoyoteRequest(new org.apache.coyote.Request());
    request.getMappingData().context = context;
    final AsyncContextImpl ac = new AsyncContextImpl(request);
    ac.addListener(listener, servletRequest, servletResponse);
    ac.setStarted(context, request, response, true);
    ac.addListener(listener, servletRequest, servletResponse);
    ac.setErrorState(new Exception(), true);
    ac.fireOnComplete();
}
Also used : AsyncContext(javax.servlet.AsyncContext) Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.catalina.connector.Request) ServletRequest(javax.servlet.ServletRequest) AsyncEvent(javax.servlet.AsyncEvent) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.catalina.connector.Response) ServletResponse(javax.servlet.ServletResponse) AsyncListener(javax.servlet.AsyncListener) TesterContext(org.apache.tomcat.unittest.TesterContext) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 23 with Request

use of org.apache.catalina.connector.Request in project tomee by apache.

the class ServletContextHandler method invoke.

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    // ITE are handled by Proxys
    final Request request = OpenEJBSecurityListener.requests.get();
    if (request != null) {
        return method.invoke(request.getServletContext(), args);
    }
    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    final ServletContext c = contexts.get(contextClassLoader);
    if (c != null) {
        return method.invoke(c, args);
    }
    // can be a not container thread so clean it up
    OpenEJBSecurityListener.requests.remove();
    for (final AppContext a : SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts()) {
        for (final WebContext w : a.getWebContexts()) {
            if (w.getClassLoader() == contextClassLoader) {
                // not in CXF so == should be fine
                return method.invoke(w.getServletContext(), args);
            }
        }
    }
    throw new IllegalStateException("Didnt find a web context for " + contextClassLoader);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) Request(org.apache.catalina.connector.Request) ServletContext(javax.servlet.ServletContext)

Example 24 with Request

use of org.apache.catalina.connector.Request in project tomee by apache.

the class TomcatSecurityService method onLogout.

public void onLogout(final HttpServletRequest request) {
    final Request state = OpenEJBSecurityListener.requests.get();
    final Object webappState = state == null ? null : state.getNote(TomEERealm.SECURITY_NOTE);
    if (webappState != null) {
        exitWebApp(webappState);
    } else {
        super.onLogout(request);
    }
}
Also used : Request(org.apache.catalina.connector.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Aggregations

Request (org.apache.catalina.connector.Request)24 Test (org.junit.Test)15 ServletRequest (javax.servlet.ServletRequest)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Context (org.apache.catalina.Context)3 Response (org.apache.catalina.connector.Response)3 TesterContext (org.apache.tomcat.unittest.TesterContext)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)2 RequestFacade (org.apache.catalina.connector.RequestFacade)2 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)2 TesterRequest (org.apache.tomcat.unittest.TesterRequest)2 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)2 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 AsyncContext (javax.servlet.AsyncContext)1 AsyncEvent (javax.servlet.AsyncEvent)1 AsyncListener (javax.servlet.AsyncListener)1 DispatcherType (javax.servlet.DispatcherType)1