From: fhanik Date: Tue, 21 Nov 2006 16:35:19 +0000 (+0000) Subject: Fix the logic of the checkSameObjects method. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=894f2d9df11178c46cc8aff58b6c4c2ed3a2dba4;p=tomcat7.0 Fix the logic of the checkSameObjects method. The method did not take into account that the lastServiceRequest/Response could be wrapped themselves. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@477737 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java b/java/org/apache/catalina/core/ApplicationDispatcher.java index f5e8e1dee..4602364e8 100644 --- a/java/org/apache/catalina/core/ApplicationDispatcher.java +++ b/java/org/apache/catalina/core/ApplicationDispatcher.java @@ -969,10 +969,8 @@ final class ApplicationDispatcher } private void checkSameObjects() throws ServletException { - ServletRequest originalRequest = - ApplicationFilterChain.getLastServicedRequest(); - ServletResponse originalResponse = - ApplicationFilterChain.getLastServicedResponse(); + ServletRequest originalRequest = ApplicationFilterChain.getLastServicedRequest(); + ServletResponse originalResponse = ApplicationFilterChain.getLastServicedResponse(); // Some forwards, eg from valves will not set original values if (originalRequest == null || originalResponse == null) { @@ -982,41 +980,47 @@ final class ApplicationDispatcher boolean same = false; ServletRequest dispatchedRequest = appRequest; + //find the bottom most request, the one that was passed into the service method + while ( originalRequest instanceof ServletRequestWrapper && ((ServletRequestWrapper) originalRequest).getRequest()!=null ) { + originalRequest = ((ServletRequestWrapper) originalRequest).getRequest(); + } + //compare with the dispatched request while (!same) { if (originalRequest.equals(dispatchedRequest)) { same = true; } if (!same && dispatchedRequest instanceof ServletRequestWrapper) { - dispatchedRequest = - ((ServletRequestWrapper) dispatchedRequest).getRequest(); + dispatchedRequest = ((ServletRequestWrapper) dispatchedRequest).getRequest(); } else { break; } } if (!same) { - throw new ServletException(sm.getString( - "applicationDispatcher.specViolation.request")); + throw new ServletException(sm.getString("applicationDispatcher.specViolation.request")); } same = false; ServletResponse dispatchedResponse = appResponse; + //find the bottom most response, the one that was passed into the service method + while ( originalResponse instanceof ServletResponseWrapper && ((ServletResponseWrapper) originalResponse).getResponse()!=null ) { + originalResponse = ((ServletResponseWrapper) originalResponse).getResponse(); + } + //compare with the dispatched response while (!same) { if (originalResponse.equals(dispatchedResponse)) { same = true; } if (!same && dispatchedResponse instanceof ServletResponseWrapper) { - dispatchedResponse = - ((ServletResponseWrapper) dispatchedResponse).getResponse(); + dispatchedResponse = ((ServletResponseWrapper) dispatchedResponse).getResponse(); } else { break; } } if (!same) { - throw new ServletException(sm.getString( - "applicationDispatcher.specViolation.response")); + throw new ServletException(sm.getString("applicationDispatcher.specViolation.response")); } } }