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