// Set up to handle the specified request and response
setup(request, response, false);
+ if (Globals.STRICT_SERVLET_COMPLIANCE) {
+ // Check SRV.8.2 / SRV.14.2.5.1 compliance
+ checkSameObjects();
+ }
+
// Identify the HTTP-specific request and response objects (if any)
HttpServletRequest hrequest = null;
if (request instanceof HttpServletRequest)
// Set up to handle the specified request and response
setup(request, response, true);
+ if (Globals.STRICT_SERVLET_COMPLIANCE) {
+ // Check SRV.8.2 / SRV.14.2.5.1 compliance
+ checkSameObjects();
+ }
+
// Create a wrapped response to use for this request
// ServletResponse wresponse = null;
ServletResponse wresponse = wrapResponse();
}
+ private void checkSameObjects() throws ServletException {
+ ServletRequest originalRequest =
+ ApplicationFilterChain.getLastServicedRequest();
+ ServletResponse originalResponse =
+ ApplicationFilterChain.getLastServicedResponse();
+
+ // Some forwards, eg from valves will not set original values
+ if (originalRequest == null || originalResponse == null) {
+ return;
+ }
+
+ boolean same = false;
+ ServletRequest dispatchedRequest = appRequest;
+
+ while (!same) {
+ if (originalRequest.equals(dispatchedRequest)) {
+ same = true;
+ }
+ if (!same && dispatchedRequest instanceof ServletRequestWrapper) {
+ dispatchedRequest =
+ ((ServletRequestWrapper) dispatchedRequest).getRequest();
+ } else {
+ break;
+ }
+ }
+ if (!same) {
+ throw new ServletException(sm.getString(
+ "applicationDispatcher.specViolation.request"));
+ }
+
+ same = false;
+ ServletResponse dispatchedResponse = appResponse;
+
+ while (!same) {
+ if (originalResponse.equals(dispatchedResponse)) {
+ same = true;
+ }
+
+ if (!same && dispatchedResponse instanceof ServletResponseWrapper) {
+ dispatchedResponse =
+ ((ServletResponseWrapper) dispatchedResponse).getResponse();
+ } else {
+ break;
+ }
+ }
+ if (!same) {
+ throw new ServletException(sm.getString(
+ "applicationDispatcher.specViolation.response"));
+ }
+ }
}
import org.apache.catalina.CometFilter;
import org.apache.catalina.CometFilterChain;
import org.apache.catalina.CometProcessor;
+import org.apache.catalina.Globals;
import org.apache.catalina.InstanceEvent;
import org.apache.catalina.security.SecurityUtil;
import org.apache.catalina.util.InstanceSupport;
final class ApplicationFilterChain implements FilterChain, CometFilterChain {
+ // Used to enforce requirements of SRV.8.2 / SRV.14.2.5.1
+ private final static ThreadLocal lastServicedRequest;
+ private final static ThreadLocal lastServicedResponse;
+
+ static {
+ if (Globals.STRICT_SERVLET_COMPLIANCE) {
+ lastServicedRequest = new ThreadLocal();
+ lastServicedResponse = new ThreadLocal();
+ } else {
+ lastServicedRequest = null;
+ lastServicedResponse = null;
+ }
+ }
// -------------------------------------------------------------- Constants
// We fell off the end of the chain -- call the servlet instance
try {
+ if (Globals.STRICT_SERVLET_COMPLIANCE) {
+ lastServicedRequest.set(request);
+ lastServicedResponse.set(response);
+ }
+
support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
servlet, request, response);
if ((request instanceof HttpServletRequest) &&
servlet, request, response, e);
throw new ServletException
(sm.getString("filterChain.servlet"), e);
+ } finally {
+ if (Globals.STRICT_SERVLET_COMPLIANCE) {
+ lastServicedRequest.set(null);
+ lastServicedResponse.set(null);
+ }
}
}
}
}
+
+ /**
+ * The last request passed to a servlet for servicing from the current
+ * thread.
+ *
+ * @return The last request to be serviced.
+ */
+ public static ServletRequest getLastServicedRequest() {
+ return (ServletRequest) lastServicedRequest.get();
+ }
+
+
+ /**
+ * The last response passed to a servlet for servicing from the current
+ * thread.
+ *
+ * @return The last response to be serviced.
+ */
+ public static ServletResponse getLastServicedResponse() {
+ return (ServletResponse) lastServicedResponse.get();
+ }
+
+
private void internalDoFilterEvent(CometEvent event)
throws IOException, ServletException {
applicationDispatcher.include.throw=Included resource threw an exception
applicationDispatcher.isUnavailable=Servlet {0} is currently unavailable
applicationDispatcher.serviceException=Servlet.service() for servlet {0} threw exception
+applicationDispatcher.specViolation.request=Original SevletRequest or wrapped original ServletRequest not passed to RequestDispatcher in violation of SRV.8.2 and SRV.14.2.5.1
+applicationDispatcher.specViolation.response=Original SevletResponse or wrapped original ServletResponse not passed to RequestDispatcher in violation of SRV.8.2 and SRV.14.2.5.1
applicationRequest.badParent=Cannot locate parent Request implementation
applicationRequest.badRequest=Request is not a javax.servlet.ServletRequestWrapper
applicationResponse.badParent=Cannot locate parent Response implementation