org.apache.catalina.connector.ResponseFacade Java Examples

The following examples show how to use org.apache.catalina.connector.ResponseFacade. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplicationDispatcher.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * 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();

    }

}
 
Example #2
Source File: TomcatHttpHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static HttpHeaders createTomcatHttpHeaders(HttpServletResponse response) {
	ResponseFacade responseFacade = getResponseFacade(response);
	org.apache.catalina.connector.Response connectorResponse = (org.apache.catalina.connector.Response)
			ReflectionUtils.getField(COYOTE_RESPONSE_FIELD, responseFacade);
	Assert.state(connectorResponse != null, "No Tomcat connector response");
	Response tomcatResponse = connectorResponse.getCoyoteResponse();
	TomcatHeadersAdapter headers = new TomcatHeadersAdapter(tomcatResponse.getMimeHeaders());
	return new HttpHeaders(headers);
}
 
Example #3
Source File: TomcatHttpHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static ResponseFacade getResponseFacade(HttpServletResponse response) {
	if (response instanceof ResponseFacade) {
		return (ResponseFacade) response;
	}
	else if (response instanceof HttpServletResponseWrapper) {
		HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper) response;
		HttpServletResponse wrappedResponse = (HttpServletResponse) wrapper.getResponse();
		return getResponseFacade(wrappedResponse);
	}
	else {
		throw new IllegalArgumentException("Cannot convert [" + response.getClass() +
				"] to org.apache.catalina.connector.ResponseFacade");
	}
}
 
Example #4
Source File: TomcatHttpHandlerAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static HttpHeaders createTomcatHttpHeaders(HttpServletResponse response) {
	ResponseFacade responseFacade = getResponseFacade(response);
	org.apache.catalina.connector.Response connectorResponse = (org.apache.catalina.connector.Response)
			ReflectionUtils.getField(COYOTE_RESPONSE_FIELD, responseFacade);
	Assert.state(connectorResponse != null, "No Tomcat connector response");
	Response tomcatResponse = connectorResponse.getCoyoteResponse();
	TomcatHeadersAdapter headers = new TomcatHeadersAdapter(tomcatResponse.getMimeHeaders());
	return new HttpHeaders(headers);
}
 
Example #5
Source File: TomcatHttpHandlerAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static ResponseFacade getResponseFacade(HttpServletResponse response) {
	if (response instanceof ResponseFacade) {
		return (ResponseFacade) response;
	}
	else if (response instanceof HttpServletResponseWrapper) {
		HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper) response;
		HttpServletResponse wrappedResponse = (HttpServletResponse) wrapper.getResponse();
		return getResponseFacade(wrappedResponse);
	}
	else {
		throw new IllegalArgumentException("Cannot convert [" + response.getClass() +
				"] to org.apache.catalina.connector.ResponseFacade");
	}
}
 
Example #6
Source File: ApplicationDispatcher.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * 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();

    }

}
 
Example #7
Source File: ApplicationDispatcher.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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();

    }

}