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();
}
}
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();
}
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());
}
Aggregations