use of org.apache.catalina.connector.Response in project tomcat by apache.
the class ApplicationDispatcher method wrapResponse.
/**
* Create and return a response wrapper that has been inserted in the
* appropriate spot in the response chain.
*/
private ServletResponse wrapResponse(State state) {
// Locate the response we should insert in front of
ServletResponse previous = null;
ServletResponse current = state.outerResponse;
while (current != null) {
if (state.hresponse == null && (current instanceof HttpServletResponse)) {
state.hresponse = (HttpServletResponse) current;
if (// Forward only needs hresponse
!state.including)
return null;
}
if (!(current instanceof ServletResponseWrapper))
break;
if (current instanceof ApplicationHttpResponse)
break;
if (current instanceof ApplicationResponse)
break;
previous = current;
current = ((ServletResponseWrapper) current).getResponse();
}
// Instantiate a new wrapper at this point and insert it in the chain
ServletResponse wrapper = null;
if ((current instanceof ApplicationHttpResponse) || (current instanceof Response) || (current instanceof HttpServletResponse))
wrapper = new ApplicationHttpResponse((HttpServletResponse) current, state.including);
else
wrapper = new ApplicationResponse(current, state.including);
if (previous == null)
state.outerResponse = wrapper;
else
((ServletResponseWrapper) previous).setResponse(wrapper);
state.wrapResponse = wrapper;
return (wrapper);
}
use of org.apache.catalina.connector.Response in project tomcat by apache.
the class ApplicationDispatcher method unwrapResponse.
/**
* Unwrap the response if we have wrapped it.
*/
private void unwrapResponse(State state) {
if (state.wrapResponse == null)
return;
if (state.outerRequest.isAsyncStarted()) {
if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) {
return;
}
}
ServletResponse previous = null;
ServletResponse current = state.outerResponse;
while (current != null) {
// If we run into the container response we are done
if ((current instanceof Response) || (current instanceof ResponseFacade))
break;
// Remove the current response if it is our wrapper
if (current == state.wrapResponse) {
ServletResponse next = ((ServletResponseWrapper) current).getResponse();
if (previous == null)
state.outerResponse = next;
else
((ServletResponseWrapper) previous).setResponse(next);
break;
}
// Advance to the next response in the chain
previous = current;
current = ((ServletResponseWrapper) current).getResponse();
}
}
use of org.apache.catalina.connector.Response 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();
}
Aggregations