*/
public void include(ServletRequest topRequest, ServletResponse topResponse,
String method)
throws ServletException, IOException
{
Invocation invocation = _includeInvocation;
HttpServletRequest parentReq;
ServletRequestWrapper reqWrapper = null;
if (topRequest instanceof ServletRequestWrapper) {
ServletRequest request = topRequest;
while (request instanceof ServletRequestWrapper) {
reqWrapper = (ServletRequestWrapper) request;
request = ((ServletRequestWrapper) request).getRequest();
}
parentReq = (HttpServletRequest) request;
} else if (topRequest instanceof HttpServletRequest) {
parentReq = (HttpServletRequest) topRequest;
} else {
throw new IllegalStateException(L.l(
"expected instance of ServletRequestWrapper at `{0}'", topResponse));
}
HttpServletResponse parentRes;
ServletResponseWrapper resWrapper = null;
if (topResponse instanceof ServletResponseWrapper) {
ServletResponse response = topResponse;
while (response instanceof ServletResponseWrapper) {
resWrapper = (ServletResponseWrapper) response;
response = ((ServletResponseWrapper) response).getResponse();
}
parentRes = (HttpServletResponse) response;
} else if (topResponse instanceof HttpServletResponse) {
parentRes = (HttpServletResponse) topResponse;
} else {
throw new IllegalStateException(L.l(
"expected instance of ServletResponse at '{0}'", topResponse));
}
IncludeRequest subRequest
= new IncludeRequest(parentReq, parentRes, invocation);
// server/10yf, jsp/15di
if (subRequest.getRequestDepth(0) > MAX_DEPTH)
throw new ServletException(L.l("too many servlet includes '{0}'", parentReq.getServletPath()));
IncludeResponse subResponse = subRequest.getResponse();
if (reqWrapper != null) {
reqWrapper.setRequest(subRequest);
}
else {
topRequest = subRequest;
}
if (resWrapper != null) {
resWrapper.setResponse(subResponse);
}
else {
topResponse = subResponse;
}
// jsp/15lf, jsp/17eg - XXX: integrated with ResponseStream?
// res.flushBuffer();
subRequest.startRequest();
try {
invocation.service(topRequest, topResponse);
} finally {
if (reqWrapper != null)
reqWrapper.setRequest(parentReq);
if (resWrapper != null)