javax.servlet.http.HttpServletResponseWrapper Java Examples

The following examples show how to use javax.servlet.http.HttpServletResponseWrapper. 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: FrameworkServlet.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Delegate OPTIONS requests to {@link #processRequest}, if desired.
 * <p>Applies HttpServlet's standard OPTIONS processing otherwise,
 * and also if there is still no 'Allow' header set after dispatching.
 * @see #doService
 */
@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) {
		processRequest(request, response);
		if (response.containsHeader("Allow")) {
			// Proper OPTIONS response coming from a handler - we're done.
			return;
		}
	}

	// Use response wrapper in order to always add PATCH to the allowed methods
	super.doOptions(request, new HttpServletResponseWrapper(response) {
		@Override
		public void setHeader(String name, String value) {
			if ("Allow".equals(name)) {
				value = (StringUtils.hasLength(value) ? value + ", " : "") + HttpMethod.PATCH.name();
			}
			super.setHeader(name, value);
		}
	});
}
 
Example #2
Source File: WingsResource.java    From wings with Apache License 2.0 6 votes vote down vote up
private String getPage(String page) {
  HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response) {
    private final StringWriter sw = new StringWriter();
    @Override
    public PrintWriter getWriter() throws IOException {
        return new PrintWriter(sw);
    }
    @Override
    public String toString() {
        return sw.toString();
    }
  };
  try {
    request.getRequestDispatcher(page).include(request, responseWrapper);
    return responseWrapper.toString();
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}
 
Example #3
Source File: ServletRuntime.java    From brave with Apache License 2.0 6 votes vote down vote up
@Override public void onComplete(AsyncEvent e) {
  HttpServletRequest req = (HttpServletRequest) e.getSuppliedRequest();
  // Use package-private attribute to check if this hook was called redundantly
  Object sendHandled = req.getAttribute("brave.servlet.TracingFilter$SendHandled");
  if (sendHandled instanceof AtomicBoolean
      && ((AtomicBoolean) sendHandled).compareAndSet(false, true)) {
    HttpServletResponse res = (HttpServletResponse) e.getSuppliedResponse();

    HttpServerResponse response =
        brave.servlet.HttpServletResponseWrapper.create(req, res, e.getThrowable());
    handler.handleSend(response, span);
  } else {
    // TODO: None of our tests reach this condition. Make a concrete case that re-enters the
    // onComplete hook or remove the special case
  }
}
 
Example #4
Source File: FilterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void doFilterInternal(HttpServletRequest request,
		HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {

	filterChain.doFilter(new HttpServletRequestWrapper(request) {
		@Override
		public Principal getUserPrincipal() {
			return new Principal() {
				@Override
				public String getName() {
					return PRINCIPAL_NAME;
				}
			};
		}
	}, new HttpServletResponseWrapper(response));
}
 
Example #5
Source File: ServletWebRequestTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void decoratedNativeRequest() {
	HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
	HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
	ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(decoratedRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(decoratedResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #6
Source File: FrameworkServlet.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Delegate OPTIONS requests to {@link #processRequest}, if desired.
 * <p>Applies HttpServlet's standard OPTIONS processing otherwise,
 * and also if there is still no 'Allow' header set after dispatching.
 * @see #doService
 */
@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) {
		processRequest(request, response);
		if (response.containsHeader("Allow")) {
			// Proper OPTIONS response coming from a handler - we're done.
			return;
		}
	}

	// Use response wrapper for Servlet 2.5 compatibility where
	// the getHeader() method does not exist
	super.doOptions(request, new HttpServletResponseWrapper(response) {
		@Override
		public void setHeader(String name, String value) {
			if ("Allow".equals(name)) {
				value = (StringUtils.hasLength(value) ? value + ", " : "") + RequestMethod.PATCH.name();
			}
			super.setHeader(name, value);
		}
	});
}
 
Example #7
Source File: TransformWrapperUtil.java    From uavstack with Apache License 2.0 6 votes vote down vote up
public static HttpServletResponse moveWrapper(String resWrapperName, HttpServletResponse response) {

        while (HttpServletResponseWrapper.class.isAssignableFrom(response.getClass())) {

            if (!resWrapperName.equals(response.getClass().getName())) {

                HttpServletResponse innerResponse = (HttpServletResponse) ReflectionHelper.getField(response.getClass(), response, "response");
                if (innerResponse == null) {
                    return response;
                }
                else {
                 response = innerResponse;
                }  
            }
            else {
                return response;
            }
        }
        return response;
    }
 
Example #8
Source File: FrameworkServlet.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Delegate OPTIONS requests to {@link #processRequest}, if desired.
 * <p>Applies HttpServlet's standard OPTIONS processing otherwise,
 * and also if there is still no 'Allow' header set after dispatching.
 * @see #doService
 */
@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) {
		processRequest(request, response);
		if (response.containsHeader("Allow")) {
			// Proper OPTIONS response coming from a handler - we're done.
			return;
		}
	}

	// Use response wrapper for Servlet 2.5 compatibility where
	// the getHeader() method does not exist
	super.doOptions(request, new HttpServletResponseWrapper(response) {
		@Override
		public void setHeader(String name, String value) {
			if ("Allow".equals(name)) {
				value = (StringUtils.hasLength(value) ? value + ", " : "") + HttpMethod.PATCH.name();
			}
			super.setHeader(name, value);
		}
	});
}
 
Example #9
Source File: RequestPerformanceFilter.java    From Taroco with Apache License 2.0 6 votes vote down vote up
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    HttpServletResponseWrapper httpResponse = new HttpServletResponseWrapper(response);
    Throwable failed = null;
    long start = System.currentTimeMillis();
    try {
        filterChain.doFilter(request, httpResponse);
    } catch (Throwable e) {
        failed = e;
        log.error("request failed...", e);
    } finally {
        String requestString = dumpRequest(request);
        long duration = System.currentTimeMillis() - start;
        if (failed != null) {
            log.error("[" + requestString + ",F," + duration + "ms," + httpResponse.getStatus() + "]");
        } else if (duration > threshold) {
            log.warn("[" + requestString + ",Y," + duration + "ms," + httpResponse.getStatus() + "]");
        } else {
            log.info("[" + requestString + ",Y," + duration + "ms," + httpResponse.getStatus() + "]");
        }
    }
}
 
Example #10
Source File: FilterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
		FilterChain filterChain) throws ServletException, IOException {

	filterChain.doFilter(new HttpServletRequestWrapper(request) {

		@Override
		public Principal getUserPrincipal() {
			return () -> PRINCIPAL_NAME;
		}

		// Like Spring Security does in HttpServlet3RequestFactory..

		@Override
		public AsyncContext getAsyncContext() {
			return super.getAsyncContext() != null ?
					new AsyncContextWrapper(super.getAsyncContext()) : null;
		}

	}, new HttpServletResponseWrapper(response));
}
 
Example #11
Source File: ServletWebRequestTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void decoratedNativeRequest() {
	HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
	HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
	ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(decoratedRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(decoratedResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #12
Source File: FrameworkServlet.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Delegate OPTIONS requests to {@link #processRequest}, if desired.
 * <p>Applies HttpServlet's standard OPTIONS processing otherwise,
 * and also if there is still no 'Allow' header set after dispatching.
 * @see #doService
 */
@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) {
		processRequest(request, response);
		if (response.containsHeader("Allow")) {
			// Proper OPTIONS response coming from a handler - we're done.
			return;
		}
	}

	// Use response wrapper in order to always add PATCH to the allowed methods
	super.doOptions(request, new HttpServletResponseWrapper(response) {
		@Override
		public void setHeader(String name, String value) {
			if ("Allow".equals(name)) {
				value = (StringUtils.hasLength(value) ? value + ", " : "") + HttpMethod.PATCH.name();
			}
			super.setHeader(name, value);
		}
	});
}
 
Example #13
Source File: FilterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
		FilterChain filterChain) throws ServletException, IOException {

	filterChain.doFilter(new HttpServletRequestWrapper(request) {

		@Override
		public Principal getUserPrincipal() {
			return () -> PRINCIPAL_NAME;
		}

		// Like Spring Security does in HttpServlet3RequestFactory..

		@Override
		public AsyncContext getAsyncContext() {
			return super.getAsyncContext() != null ?
					new AsyncContextWrapper(super.getAsyncContext()) : null;
		}

	}, new HttpServletResponseWrapper(response));
}
 
Example #14
Source File: ServletWebRequestTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void decoratedNativeRequest() {
	HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
	HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
	ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(decoratedRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(decoratedResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #15
Source File: ResponseSplittingServlet.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    Cookie cookie = new Cookie("name", unknown());
    cookie.setValue(req.getParameter("p") + "x");
    resp.setHeader("header", req.getParameter("h1"));
    resp.addHeader("header", unknown());
    callCookieSink(req.getParameter("h2"));
    String encoded = ESAPI.encoder().encodeForURL(req.getParameter("h3"));
    resp.addHeader("header", ESAPI.encoder().decodeFromURL(encoded));
    
    // false positives
    String safe = "x".concat("y");
    Cookie safeCookie = new Cookie("name", safe);
    safeCookie.setValue(safe + "x");
    resp.setHeader("header", safe);
    resp.addHeader("header", encoded.concat(safe));


    HttpServletResponseWrapper resWrapper = new HttpServletResponseWrapper(resp);
    resWrapper.setHeader("header2",req.getParameter("a"));
    resWrapper.addHeader("header3",req.getParameter("b"));
}
 
Example #16
Source File: Response.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Set a wrapped HttpServletResponse to pass to the application. Components
 * wishing to wrap the response should obtain the response via
 * {@link #getResponse()}, wrap it and then call this method with the
 * wrapped response.
 *
 * @param applicationResponse The wrapped response to pass to the
 *        application
 */
public void setResponse(HttpServletResponse applicationResponse) {
    // Check the wrapper wraps this request
    ServletResponse r = applicationResponse;
    while (r instanceof HttpServletResponseWrapper) {
        r = ((HttpServletResponseWrapper) r).getResponse();
    }
    if (r != facade) {
        throw new IllegalArgumentException(sm.getString("response.illegalWrap"));
    }
    this.applicationResponse = applicationResponse;
}
 
Example #17
Source File: MockRequestDispatcher.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Obtain the underlying {@link MockHttpServletResponse}, unwrapping
 * {@link HttpServletResponseWrapper} decorators if necessary.
 */
protected MockHttpServletResponse getMockHttpServletResponse(ServletResponse response) {
	if (response instanceof MockHttpServletResponse) {
		return (MockHttpServletResponse) response;
	}
	if (response instanceof HttpServletResponseWrapper) {
		return getMockHttpServletResponse(((HttpServletResponseWrapper) response).getResponse());
	}
	throw new IllegalArgumentException("MockRequestDispatcher requires MockHttpServletResponse");
}
 
Example #18
Source File: MockRequestDispatcher.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Obtain the underlying {@link MockHttpServletResponse}, unwrapping
 * {@link HttpServletResponseWrapper} decorators if necessary.
 */
protected MockHttpServletResponse getMockHttpServletResponse(ServletResponse response) {
	if (response instanceof MockHttpServletResponse) {
		return (MockHttpServletResponse) response;
	}
	if (response instanceof HttpServletResponseWrapper) {
		return getMockHttpServletResponse(((HttpServletResponseWrapper) response).getResponse());
	}
	throw new IllegalArgumentException("MockRequestDispatcher requires MockHttpServletResponse");
}
 
Example #19
Source File: MockRequestDispatcher.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the underlying {@link MockHttpServletResponse}, unwrapping
 * {@link HttpServletResponseWrapper} decorators if necessary.
 */
protected MockHttpServletResponse getMockHttpServletResponse(ServletResponse response) {
	if (response instanceof MockHttpServletResponse) {
		return (MockHttpServletResponse) response;
	}
	if (response instanceof HttpServletResponseWrapper) {
		return getMockHttpServletResponse(((HttpServletResponseWrapper) response).getResponse());
	}
	throw new IllegalArgumentException("MockRequestDispatcher requires MockHttpServletResponse");
}
 
Example #20
Source File: MockRequestDispatcher.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the underlying {@link MockHttpServletResponse}, unwrapping
 * {@link HttpServletResponseWrapper} decorators if necessary.
 */
protected MockHttpServletResponse getMockHttpServletResponse(ServletResponse response) {
	if (response instanceof MockHttpServletResponse) {
		return (MockHttpServletResponse) response;
	}
	if (response instanceof HttpServletResponseWrapper) {
		return getMockHttpServletResponse(((HttpServletResponseWrapper) response).getResponse());
	}
	throw new IllegalArgumentException("MockRequestDispatcher requires MockHttpServletResponse");
}
 
Example #21
Source File: MockRequestDispatcher.java    From live-chat-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the underlying MockHttpServletResponse,
 * unwrapping {@link HttpServletResponseWrapper} decorators if necessary.
 */
protected MockHttpServletResponse getMockHttpServletResponse(ServletResponse response) {
	if (response instanceof MockHttpServletResponse) {
		return (MockHttpServletResponse) response;
	}
	if (response instanceof HttpServletResponseWrapper) {
		return getMockHttpServletResponse(((HttpServletResponseWrapper) response).getResponse());
	}
	throw new IllegalArgumentException("MockRequestDispatcher requires MockHttpServletResponse");
}
 
Example #22
Source File: EntityHttpServletRequest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected EntityHttpServletResponse getEntityHttpServletResponse(ServletResponse response) {
    if (response instanceof EntityHttpServletResponse) {
        return (EntityHttpServletResponse) response;
    }
    if (response instanceof HttpServletResponseWrapper) {
        return getEntityHttpServletResponse(((HttpServletResponseWrapper) response).getResponse());
    }
    throw new IllegalArgumentException("EntityRequestDispatcher requires EntityHttpServletResponse");
}
 
Example #23
Source File: PortletRequestDispatcherImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
private static HttpServletPortletResponseWrapper getWrappedResponse(ServletResponse response) {
   HttpServletPortletResponseWrapper res = null;

   do {
      if (response instanceof HttpServletPortletResponseWrapper) {
         res = (HttpServletPortletResponseWrapper) response;
      } else if (response instanceof HttpServletResponseWrapper) {
         response = ((HttpServletResponseWrapper) response).getResponse();
      } else {
         response = null;
      }
   } while (response != null && res == null);
   return res;
}
 
Example #24
Source File: EntityHttpServletRequest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected EntityHttpServletResponse getEntityHttpServletResponse(ServletResponse response) {
    if (response instanceof EntityHttpServletResponse) {
        return (EntityHttpServletResponse) response;
    }
    if (response instanceof HttpServletResponseWrapper) {
        return getEntityHttpServletResponse(((HttpServletResponseWrapper) response).getResponse());
    }
    throw new IllegalArgumentException("EntityRequestDispatcher requires EntityHttpServletResponse");
}
 
Example #25
Source File: RemoveHeaderFilter.java    From odo with Apache License 2.0 5 votes vote down vote up
/**
 * This looks at the servlet attributes to get the list of response headers to remove while the response object gets created by the servlet
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    final ServletRequest r1 = request;
    chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response) {
        @SuppressWarnings("unchecked")
        public void setHeader(String name, String value) {
            ArrayList<String> headersToRemove = new ArrayList<String>();
            
            if (r1.getAttribute("com.groupon.odo.removeHeaders") != null)
                headersToRemove = (ArrayList<String>) r1.getAttribute("com.groupon.odo.removeHeaders");

            boolean removeHeader = false;
            // need to loop through removeHeaders to make things case insensitive
            for (String headerToRemove : headersToRemove) {
                if (headerToRemove.toLowerCase().equals(name.toLowerCase())) {
                    removeHeader = true;
                    break;
                }
            }

            if (! removeHeader) {
                super.setHeader(name, value);
            }
        }
    });
}
 
Example #26
Source File: DenyGoCDAccessForArtifactsFilterChainTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
public static ServletResponse wrap(MockHttpServletResponse response) {
    return argThat(new ArgumentMatcher<ServletResponse>() {
        @Override
        public boolean matches(ServletResponse actualResponse) {
            while (actualResponse instanceof HttpServletResponseWrapper) {
                actualResponse = ((HttpServletResponseWrapper) actualResponse).getResponse();
            }

            return actualResponse == response;
        }
    });
}
 
Example #27
Source File: MockRequestDispatcher.java    From gocd with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the underlying {@link MockHttpServletResponse}, unwrapping
 * {@link HttpServletResponseWrapper} decorators if necessary.
 */
protected MockHttpServletResponse getMockHttpServletResponse(ServletResponse response) {
	if (response instanceof MockHttpServletResponse) {
		return (MockHttpServletResponse) response;
	}
	if (response instanceof HttpServletResponseWrapper) {
		return getMockHttpServletResponse(((HttpServletResponseWrapper) response).getResponse());
	}
	throw new IllegalArgumentException("MockRequestDispatcher requires MockHttpServletResponse");
}
 
Example #28
Source File: NoETagFilter.java    From javaee-cache-filter with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Disables {@code ETag} HTTP header.
 * </p>
 * {@inheritDoc}
 */
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    filterChain.doFilter(servletRequest, new HttpServletResponseWrapper((HttpServletResponse) servletResponse) {
        @Override
        public void setHeader(String name, String value) {
            if (!HTTPCacheHeader.ETAG.getName().equalsIgnoreCase(name)) {
                super.setHeader(name, value);
            }
        }
    });
}
 
Example #29
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 #30
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");
	}
}