Search in sources :

Example 11 with RequestFacade

use of org.apache.catalina.connector.RequestFacade 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(jakarta.servlet.http.HttpServletRequest) ServletRequest(jakarta.servlet.ServletRequest) ServletRequestWrapper(jakarta.servlet.ServletRequestWrapper) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Request(org.apache.catalina.connector.Request) ServletRequest(jakarta.servlet.ServletRequest) RequestFacade(org.apache.catalina.connector.RequestFacade)

Example 12 with RequestFacade

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

the class WebdavStatus method determineMethodsAllowed.

/**
 * Determines the methods normally allowed for the resource.
 *
 * @param req The Servlet request
 *
 * @return The allowed HTTP methods
 */
@Override
protected String determineMethodsAllowed(HttpServletRequest req) {
    WebResource resource = resources.getResource(getRelativePath(req));
    // These methods are always allowed. They may return a 404 (not a 405)
    // if the resource does not exist.
    StringBuilder methodsAllowed = new StringBuilder("OPTIONS, GET, POST, HEAD");
    if (!readOnly) {
        methodsAllowed.append(", DELETE");
        if (!resource.isDirectory()) {
            methodsAllowed.append(", PUT");
        }
    }
    // Trace - assume disabled unless we can prove otherwise
    if (req instanceof RequestFacade && ((RequestFacade) req).getAllowTrace()) {
        methodsAllowed.append(", TRACE");
    }
    methodsAllowed.append(", LOCK, UNLOCK, PROPPATCH, COPY, MOVE");
    if (listings) {
        methodsAllowed.append(", PROPFIND");
    }
    if (!resource.exists()) {
        methodsAllowed.append(", MKCOL");
    }
    return methodsAllowed.toString();
}
Also used : WebResource(org.apache.catalina.WebResource) RequestFacade(org.apache.catalina.connector.RequestFacade)

Example 13 with RequestFacade

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

the class TestPersistentManager method testBug62175.

@Test
public void testBug62175() throws Exception {
    PersistentManager manager = new PersistentManager();
    AtomicInteger sessionExpireCounter = new AtomicInteger();
    Store mockStore = EasyMock.createNiceMock(Store.class);
    EasyMock.expect(mockStore.load(EasyMock.anyString())).andAnswer(new IAnswer<Session>() {

        @Override
        public Session answer() throws Throwable {
            return timedOutSession(manager, sessionExpireCounter);
        }
    }).anyTimes();
    EasyMock.replay(mockStore);
    manager.setStore(mockStore);
    Host host = new TesterHost();
    RequestCachingSessionListener requestCachingSessionListener = new RequestCachingSessionListener();
    Context context = new TesterContext() {

        @Override
        public Object[] getApplicationLifecycleListeners() {
            return new Object[] { requestCachingSessionListener };
        }

        @Override
        public Manager getManager() {
            return manager;
        }
    };
    context.setParent(host);
    Connector connector = EasyMock.createNiceMock(Connector.class);
    Request req = new Request(connector) {

        @Override
        public Context getContext() {
            return context;
        }
    };
    req.setRequestedSessionId("invalidSession");
    HttpServletRequest request = new RequestFacade(req);
    EasyMock.replay(connector);
    requestCachingSessionListener.request = request;
    manager.setContext(context);
    manager.start();
    Assert.assertNull(request.getSession(false));
    Assert.assertEquals(1, sessionExpireCounter.get());
}
Also used : Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) Connector(org.apache.catalina.connector.Connector) Request(org.apache.catalina.connector.Request) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Store(org.apache.catalina.Store) TesterHost(org.apache.tomcat.unittest.TesterHost) Host(org.apache.catalina.Host) RequestFacade(org.apache.catalina.connector.RequestFacade) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) IAnswer(org.easymock.IAnswer) TesterHost(org.apache.tomcat.unittest.TesterHost) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TesterContext(org.apache.tomcat.unittest.TesterContext) Test(org.junit.Test)

Aggregations

RequestFacade (org.apache.catalina.connector.RequestFacade)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Request (org.apache.catalina.connector.Request)6 ServletRequest (javax.servlet.ServletRequest)5 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)5 Context (org.apache.catalina.Context)3 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ServletException (javax.servlet.ServletException)2 Host (org.apache.catalina.Host)2 Store (org.apache.catalina.Store)2 TesterContext (org.apache.tomcat.unittest.TesterContext)2 TesterHost (org.apache.tomcat.unittest.TesterHost)2 IAnswer (org.easymock.IAnswer)2 Test (org.junit.Test)2 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)1 AppServSecurityContext (com.sun.enterprise.security.integration.AppServSecurityContext)1 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)1 WebModule (com.sun.enterprise.web.WebModule)1 ServletRequest (jakarta.servlet.ServletRequest)1