You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/11/10 07:14:47 UTC

svn commit: r1200178 - in /tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector: RequestFacade.java Response.java ResponseFacade.java

Author: kkolinko
Date: Thu Nov 10 06:14:46 2011
New Revision: 1200178

URL: http://svn.apache.org/viewvc?rev=1200178&view=rev
Log:
Merged revision 1187753 from tomcat/trunk:
Clean-up. No functional change.
Part 5.

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/RequestFacade.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/ResponseFacade.java

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/RequestFacade.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/RequestFacade.java?rev=1200178&r1=1200177&r2=1200178&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/RequestFacade.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/RequestFacade.java Thu Nov 10 06:14:46 2011
@@ -5,17 +5,15 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina.connector;
 
 import java.io.BufferedReader;
@@ -46,7 +44,7 @@ import org.apache.catalina.security.Secu
 import org.apache.tomcat.util.res.StringManager;
 
 /**
- * Facade class that wraps a Coyote request object.  
+ * Facade class that wraps a Coyote request object.
  * All methods are delegated to the wrapped request.
  *
  * @author Craig R. McClanahan
@@ -57,46 +55,46 @@ import org.apache.tomcat.util.res.String
 
 @SuppressWarnings("deprecation")
 public class RequestFacade implements HttpServletRequest {
-        
-        
+
+
     // ----------------------------------------------------------- DoPrivileged
-    
+
     private final class GetAttributePrivilegedAction
             implements PrivilegedAction<Enumeration<String>> {
-        
+
         @Override
         public Enumeration<String> run() {
             return request.getAttributeNames();
-        }            
+        }
     }
-     
-    
+
+
     private final class GetParameterMapPrivilegedAction
             implements PrivilegedAction<Map<String,String[]>> {
-        
+
         @Override
         public Map<String,String[]> run() {
             return request.getParameterMap();
-        }        
-    }    
-    
-    
+        }
+    }
+
+
     private final class GetRequestDispatcherPrivilegedAction
             implements PrivilegedAction<RequestDispatcher> {
 
-        private String path;
+        private final String path;
 
         public GetRequestDispatcherPrivilegedAction(String path){
             this.path = path;
         }
-        
+
         @Override
-        public RequestDispatcher run() {   
+        public RequestDispatcher run() {
             return request.getRequestDispatcher(path);
-        }           
-    }    
-    
-    
+        }
+    }
+
+
     private final class GetParameterPrivilegedAction
             implements PrivilegedAction<String> {
 
@@ -107,22 +105,22 @@ public class RequestFacade implements Ht
         }
 
         @Override
-        public String run() {       
+        public String run() {
             return request.getParameter(name);
-        }           
-    }    
-    
-     
+        }
+    }
+
+
     private final class GetParameterNamesPrivilegedAction
             implements PrivilegedAction<Enumeration<String>> {
-        
+
         @Override
-        public Enumeration<String> run() {          
+        public Enumeration<String> run() {
             return request.getParameterNames();
-        }           
-    } 
-    
-    
+        }
+    }
+
+
     private final class GetParameterValuePrivilegedAction
             implements PrivilegedAction<String[]> {
 
@@ -133,90 +131,90 @@ public class RequestFacade implements Ht
         }
 
         @Override
-        public String[] run() {       
+        public String[] run() {
             return request.getParameterValues(name);
-        }           
-    }    
-  
-    
+        }
+    }
+
+
     private final class GetCookiesPrivilegedAction
             implements PrivilegedAction<Cookie[]> {
-        
+
         @Override
-        public Cookie[] run() {       
+        public Cookie[] run() {
             return request.getCookies();
-        }           
-    }      
-    
-    
+        }
+    }
+
+
     private final class GetCharacterEncodingPrivilegedAction
             implements PrivilegedAction<String> {
-        
+
         @Override
-        public String run() {       
+        public String run() {
             return request.getCharacterEncoding();
-        }           
-    }   
-        
-    
+        }
+    }
+
+
     private final class GetHeadersPrivilegedAction
             implements PrivilegedAction<Enumeration<String>> {
 
-        private String name;
+        private final String name;
 
         public GetHeadersPrivilegedAction(String name){
             this.name = name;
         }
-        
+
         @Override
-        public Enumeration<String> run() {       
+        public Enumeration<String> run() {
             return request.getHeaders(name);
-        }           
-    }    
-        
-    
+        }
+    }
+
+
     private final class GetHeaderNamesPrivilegedAction
             implements PrivilegedAction<Enumeration<String>> {
 
         @Override
-        public Enumeration<String> run() {       
+        public Enumeration<String> run() {
             return request.getHeaderNames();
-        }           
-    }  
-            
-    
+        }
+    }
+
+
     private final class GetLocalePrivilegedAction
             implements PrivilegedAction<Locale> {
 
         @Override
-        public Locale run() {       
+        public Locale run() {
             return request.getLocale();
-        }           
-    }    
-            
-    
+        }
+    }
+
+
     private final class GetLocalesPrivilegedAction
             implements PrivilegedAction<Enumeration<Locale>> {
 
         @Override
-        public Enumeration<Locale> run() {       
+        public Enumeration<Locale> run() {
             return request.getLocales();
-        }           
-    }    
-    
+        }
+    }
+
     private final class GetSessionPrivilegedAction
             implements PrivilegedAction<HttpSession> {
 
-        private boolean create;
-        
+        private final boolean create;
+
         public GetSessionPrivilegedAction(boolean create){
             this.create = create;
         }
-                
+
         @Override
-        public HttpSession run() {  
+        public HttpSession run() {
             return request.getSession(create);
-        }           
+        }
     }
 
     // ----------------------------------------------------------- Constructors
@@ -260,7 +258,7 @@ public class RequestFacade implements Ht
         request = null;
     }
 
-    
+
     /**
      * Prevent cloning the facade.
      */
@@ -296,7 +294,7 @@ public class RequestFacade implements Ht
 
         if (Globals.IS_SECURITY_ENABLED){
             return AccessController.doPrivileged(
-                new GetAttributePrivilegedAction());        
+                new GetAttributePrivilegedAction());
         } else {
             return request.getAttributeNames();
         }
@@ -316,7 +314,7 @@ public class RequestFacade implements Ht
                 new GetCharacterEncodingPrivilegedAction());
         } else {
             return request.getCharacterEncoding();
-        }         
+        }
     }
 
 
@@ -441,7 +439,7 @@ public class RequestFacade implements Ht
 
         if (Globals.IS_SECURITY_ENABLED){
             return AccessController.doPrivileged(
-                new GetParameterMapPrivilegedAction());        
+                new GetParameterMapPrivilegedAction());
         } else {
             return request.getParameterMap();
         }
@@ -569,7 +567,7 @@ public class RequestFacade implements Ht
                 new GetLocalePrivilegedAction());
         } else {
             return request.getLocale();
-        }        
+        }
     }
 
 
@@ -586,7 +584,7 @@ public class RequestFacade implements Ht
                 new GetLocalesPrivilegedAction());
         } else {
             return request.getLocales();
-        }        
+        }
     }
 
 
@@ -707,7 +705,7 @@ public class RequestFacade implements Ht
                 new GetHeadersPrivilegedAction(name));
         } else {
             return request.getHeaders(name);
-        }         
+        }
     }
 
 
@@ -724,7 +722,7 @@ public class RequestFacade implements Ht
                 new GetHeaderNamesPrivilegedAction());
         } else {
             return request.getHeaderNames();
-        }             
+        }
     }
 
 
@@ -1043,7 +1041,7 @@ public class RequestFacade implements Ht
         return request.isAsyncSupported();
     }
 
-    
+
     @Override
     public AsyncContext getAsyncContext() {
         return request.getAsyncContext();
@@ -1053,7 +1051,7 @@ public class RequestFacade implements Ht
     public DispatcherType getDispatcherType() {
         return request.getDispatcherType();
     }
-    
+
     @Override
     public boolean authenticate(HttpServletResponse response)
     throws IOException, ServletException {
@@ -1065,18 +1063,18 @@ public class RequestFacade implements Ht
     throws ServletException {
         request.login(username, password);
     }
-    
+
     @Override
     public void logout() throws ServletException {
         request.logout();
     }
-    
+
     @Override
     public Collection<Part> getParts() throws IllegalStateException,
             IOException, ServletException {
         return request.getParts();
     }
-    
+
     @Override
     public Part getPart(String name) throws IllegalStateException, IOException,
             ServletException {
@@ -1086,5 +1084,5 @@ public class RequestFacade implements Ht
     public boolean getAllowTrace() {
         return request.getConnector().getAllowTrace();
     }
-    
+
 }

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java?rev=1200178&r1=1200177&r2=1200178&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java Thu Nov 10 06:14:46 2011
@@ -5,17 +5,15 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina.connector;
 
 
@@ -160,7 +158,7 @@ public class Response
 
     /**
      * Set the Coyote response.
-     * 
+     *
      * @param coyoteResponse The Coyote response
      */
     public void setCoyoteResponse(org.apache.coyote.Response coyoteResponse) {
@@ -227,12 +225,12 @@ public class Response
      */
     protected boolean included = false;
 
-    
+
     /**
      * The characterEncoding flag
      */
     private boolean isCharacterEncodingSet = false;
-    
+
     /**
      * The error flag.
      */
@@ -279,7 +277,7 @@ public class Response
         included = false;
         error = false;
         isCharacterEncodingSet = false;
-        
+
         if (Globals.IS_SECURITY_ENABLED || Connector.RECYCLE_FACADES) {
             if (facade != null) {
                 facade.clear();
@@ -306,7 +304,7 @@ public class Response
     public void clearEncoders() {
         outputBuffer.clearEncoders();
     }
-    
+
 
     // ------------------------------------------------------- Response Methods
 
@@ -338,7 +336,7 @@ public class Response
 
     /**
      * Set the application commit flag.
-     * 
+     *
      * @param appCommitted The new application committed flag value
      */
     public void setAppCommitted(boolean appCommitted) {
@@ -351,7 +349,7 @@ public class Response
      */
     public boolean isAppCommitted() {
         return (this.appCommitted || isCommitted() || isSuspended()
-                || ((getContentLength() > 0) 
+                || ((getContentLength() > 0)
                     && (getContentWritten() >= getContentLength())));
     }
 
@@ -440,7 +438,7 @@ public class Response
 
     /**
      * Set the suspended flag.
-     * 
+     *
      * @param suspended The new suspended flag value
      */
     public void setSuspended(boolean suspended) {
@@ -503,7 +501,7 @@ public class Response
      *
      * @exception IOException if an input/output error occurs
      */
-    public void finishResponse() 
+    public void finishResponse()
         throws IOException {
         // Writing leftover bytes
         outputBuffer.close();
@@ -562,7 +560,7 @@ public class Response
      * @exception IOException if an input/output error occurs
      */
     @Override
-    public void flushBuffer() 
+    public void flushBuffer()
         throws IOException {
         outputBuffer.flush();
     }
@@ -594,12 +592,13 @@ public class Response
      * @exception IOException if an input/output error occurs
      */
     @Override
-    public ServletOutputStream getOutputStream() 
+    public ServletOutputStream getOutputStream()
         throws IOException {
 
-        if (usingWriter)
+        if (usingWriter) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.getOutputStream.ise"));
+        }
 
         usingOutputStream = true;
         if (outputStream == null) {
@@ -627,12 +626,13 @@ public class Response
      * @exception IOException if an input/output error occurs
      */
     @Override
-    public PrintWriter getWriter() 
+    public PrintWriter getWriter()
         throws IOException {
 
-        if (usingOutputStream)
+        if (usingOutputStream) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.getWriter.ise"));
+        }
 
         if (ENFORCE_ENCODING_IN_GET_WRITER) {
             /*
@@ -679,7 +679,9 @@ public class Response
     public void reset() {
 
         if (included)
+         {
             return;     // Ignore any call from an included servlet
+        }
 
         coyoteResponse.reset();
         outputBuffer.reset();
@@ -700,7 +702,7 @@ public class Response
         resetBuffer(false);
     }
 
-    
+
     /**
      * Reset the data buffer and the using Writer/Stream flags but not any
      * status or header information.
@@ -708,18 +710,19 @@ public class Response
      * @param resetWriterStreamFlags <code>true</code> if the internal
      *        <code>usingWriter</code>, <code>usingOutputStream</code>,
      *        <code>isCharacterEncodingSet</code> flags should also be reset
-     * 
+     *
      * @exception IllegalStateException if the response has already
      *  been committed
      */
     public void resetBuffer(boolean resetWriterStreamFlags) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.resetBuffer.ise"));
+        }
 
         outputBuffer.reset();
-        
+
         if(resetWriterStreamFlags) {
             usingOutputStream = false;
             usingWriter = false;
@@ -728,7 +731,7 @@ public class Response
 
     }
 
-    
+
     /**
      * Set the buffer size to be used for this Response.
      *
@@ -740,9 +743,10 @@ public class Response
     @Override
     public void setBufferSize(int size) {
 
-        if (isCommitted() || !outputBuffer.isNew())
+        if (isCommitted() || !outputBuffer.isNew()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.setBufferSize.ise"));
+        }
 
         outputBuffer.setBufferSize(size);
 
@@ -757,13 +761,15 @@ public class Response
     @Override
     public void setContentLength(int length) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
+        if (included) {
             return;
-        
+        }
+
         coyoteResponse.setContentLength(length);
 
     }
@@ -778,12 +784,14 @@ public class Response
     @SuppressWarnings("deprecation") // isSpace (deprecated) cannot be replaced by isWhiteSpace
     public void setContentType(String type) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
+        if (included) {
             return;
+        }
 
         // Ignore charset if getWriter() has already been called
         if (usingWriter) {
@@ -833,17 +841,20 @@ public class Response
     @Override
     public void setCharacterEncoding(String charset) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
-        
+        }
+
         // Ignore any call from an included servlet
-        if (included)
-            return;     
-        
+        if (included) {
+            return;
+        }
+
         // Ignore any call made after the getWriter has been invoked
         // The default should be used
-        if (usingWriter)
+        if (usingWriter) {
             return;
+        }
 
         coyoteResponse.setCharacterEncoding(charset);
         isCharacterEncodingSet = true;
@@ -859,19 +870,22 @@ public class Response
     @Override
     public void setLocale(Locale locale) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
+        if (included) {
             return;
+        }
 
         coyoteResponse.setLocale(locale);
 
         // Ignore any call made after the getWriter has been invoked.
         // The default should be used
-        if (usingWriter)
+        if (usingWriter) {
             return;
+        }
 
         if (isCharacterEncodingSet) {
             return;
@@ -984,8 +998,9 @@ public class Response
     public void addCookie(final Cookie cookie) {
 
         // Ignore any call from an included servlet
-        if (included || isCommitted())
+        if (included || isCommitted()) {
             return;
+        }
 
         final StringBuffer sb = generateCookieString(cookie);
         //if we reached here, no exception, cookie is valid
@@ -996,14 +1011,15 @@ public class Response
     }
 
     /**
-     * Special method for adding a session cookie as we should be overriding 
-     * any previous 
+     * Special method for adding a session cookie as we should be overriding
+     * any previous
      * @param cookie
      */
     public void addSessionCookieInternal(final Cookie cookie) {
-        if (isCommitted())
+        if (isCommitted()) {
             return;
-        
+        }
+
         String name = cookie.getName();
         final String headername = "Set-Cookie";
         final String startsWith = name + "=";
@@ -1022,22 +1038,22 @@ public class Response
         if (!set) {
             addHeader(headername, sb.toString());
         }
-        
-        
+
+
     }
 
     public StringBuffer generateCookieString(final Cookie cookie) {
         final StringBuffer sb = new StringBuffer();
-        //web application code can receive a IllegalArgumentException 
+        //web application code can receive a IllegalArgumentException
         //from the appendCookieValue invocation
         if (SecurityUtil.isPackageProtectionEnabled()) {
             AccessController.doPrivileged(new PrivilegedAction<Void>() {
                 @Override
                 public Void run(){
                     ServerCookie.appendCookieValue
-                        (sb, cookie.getVersion(), cookie.getName(), 
-                         cookie.getValue(), cookie.getPath(), 
-                         cookie.getDomain(), cookie.getComment(), 
+                        (sb, cookie.getVersion(), cookie.getName(),
+                         cookie.getValue(), cookie.getPath(),
+                         cookie.getDomain(), cookie.getComment(),
                          cookie.getMaxAge(), cookie.getSecure(),
                          cookie.isHttpOnly());
                     return null;
@@ -1046,7 +1062,7 @@ public class Response
         } else {
             ServerCookie.appendCookieValue
                 (sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
-                     cookie.getPath(), cookie.getDomain(), cookie.getComment(), 
+                     cookie.getPath(), cookie.getDomain(), cookie.getComment(),
                      cookie.getMaxAge(), cookie.getSecure(),
                      cookie.isHttpOnly());
         }
@@ -1067,8 +1083,9 @@ public class Response
             return;
         }
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
         if (included) {
@@ -1099,12 +1116,14 @@ public class Response
             return;
         }
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
+        if (included) {
             return;
+        }
 
         coyoteResponse.addHeader(name, value);
 
@@ -1124,12 +1143,14 @@ public class Response
             return;
         }
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
+        if (included) {
             return;
+        }
 
         addHeader(name, "" + value);
 
@@ -1203,10 +1224,10 @@ public class Response
      */
     @Override
     public String encodeURL(String url) {
-        
+
         String absolute = toAbsolute(url);
         if (isEncodeable(absolute)) {
-            // W3c spec clearly said 
+            // W3c spec clearly said
             if (url.equalsIgnoreCase("")) {
                 url = absolute;
             } else if (url.equals(absolute) && !hasPath(url)) {
@@ -1238,18 +1259,20 @@ public class Response
 
     /**
      * Send an acknowledgment of a request.
-     * 
+     *
      * @exception IOException if an input/output error occurs
      */
     public void sendAcknowledgement()
         throws IOException {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
-            return; 
+        if (included) {
+            return;
+        }
 
         coyoteResponse.acknowledge();
 
@@ -1267,7 +1290,7 @@ public class Response
      * @exception IOException if an input/output error occurs
      */
     @Override
-    public void sendError(int status) 
+    public void sendError(int status)
         throws IOException {
         sendError(status, null);
     }
@@ -1284,21 +1307,23 @@ public class Response
      * @exception IOException if an input/output error occurs
      */
     @Override
-    public void sendError(int status, String message) 
+    public void sendError(int status, String message)
         throws IOException {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.sendError.ise"));
+        }
 
         // Ignore any call from an included servlet
-        if (included)
-            return; 
+        if (included) {
+            return;
+        }
 
         Wrapper wrapper = getRequest().getWrapper();
         if (wrapper != null) {
             wrapper.incrementErrorCount();
-        } 
+        }
 
         setError();
 
@@ -1324,16 +1349,18 @@ public class Response
      * @exception IOException if an input/output error occurs
      */
     @Override
-    public void sendRedirect(String location) 
+    public void sendRedirect(String location)
         throws IOException {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.sendRedirect.ise"));
+        }
 
         // Ignore any call from an included servlet
-        if (included)
-            return; 
+        if (included) {
+            return;
+        }
 
         // Clear any data content that has been buffered
         resetBuffer(true);
@@ -1372,8 +1399,9 @@ public class Response
             return;
         }
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
         if (included) {
@@ -1404,12 +1432,14 @@ public class Response
             return;
         }
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
+        if (included) {
             return;
+        }
 
         coyoteResponse.setHeader(name, value);
 
@@ -1429,12 +1459,14 @@ public class Response
             return;
         }
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
+        if (included) {
             return;
+        }
 
         setHeader(name, "" + value);
 
@@ -1466,12 +1498,14 @@ public class Response
     @Deprecated
     public void setStatus(int status, String message) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         // Ignore any call from an included servlet
-        if (included)
+        if (included) {
             return;
+        }
 
         coyoteResponse.setStatus(status);
         coyoteResponse.setMessage(message);
@@ -1497,25 +1531,30 @@ public class Response
      */
     protected boolean isEncodeable(final String location) {
 
-        if (location == null)
+        if (location == null) {
             return (false);
+        }
 
         // Is this an intra-document reference?
-        if (location.startsWith("#"))
+        if (location.startsWith("#")) {
             return (false);
+        }
 
         // Are we in a valid session that is not using cookies?
         final Request hreq = request;
         final Session session = hreq.getSessionInternal(false);
-        if (session == null)
+        if (session == null) {
             return (false);
-        if (hreq.isRequestedSessionIdFromCookie())
+        }
+        if (hreq.isRequestedSessionIdFromCookie()) {
             return (false);
-        
+        }
+
         // Is URL encoding permitted
         if (!hreq.getServletContext().getEffectiveSessionTrackingModes().
-                contains(SessionTrackingMode.URL))
+                contains(SessionTrackingMode.URL)) {
             return false;
+        }
 
         if (SecurityUtil.isPackageProtectionEnabled()) {
             return (
@@ -1531,7 +1570,7 @@ public class Response
         }
     }
 
-    private boolean doIsEncodeable(Request hreq, Session session, 
+    private boolean doIsEncodeable(Request hreq, Session session,
                                    String location) {
         // Is this a valid absolute URL?
         URL url = null;
@@ -1542,38 +1581,45 @@ public class Response
         }
 
         // Does this URL match down to (and including) the context path?
-        if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol()))
+        if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol())) {
             return (false);
-        if (!hreq.getServerName().equalsIgnoreCase(url.getHost()))
+        }
+        if (!hreq.getServerName().equalsIgnoreCase(url.getHost())) {
             return (false);
+        }
         int serverPort = hreq.getServerPort();
         if (serverPort == -1) {
-            if ("https".equals(hreq.getScheme()))
+            if ("https".equals(hreq.getScheme())) {
                 serverPort = 443;
-            else
+            } else {
                 serverPort = 80;
+            }
         }
         int urlPort = url.getPort();
         if (urlPort == -1) {
-            if ("https".equals(url.getProtocol()))
+            if ("https".equals(url.getProtocol())) {
                 urlPort = 443;
-            else
+            } else {
                 urlPort = 80;
+            }
         }
-        if (serverPort != urlPort)
+        if (serverPort != urlPort) {
             return (false);
+        }
 
         String contextPath = getContext().getPath();
         if (contextPath != null) {
             String file = url.getFile();
-            if ((file == null) || !file.startsWith(contextPath))
+            if ((file == null) || !file.startsWith(contextPath)) {
                 return (false);
+            }
             String tok = ";" +
                     ApplicationSessionCookieConfig.getSessionUriParamName(
                                 request.getContext()) +
                     "=" + session.getIdInternal();
-            if( file.indexOf(tok, contextPath.length()) >= 0 )
+            if( file.indexOf(tok, contextPath.length()) >= 0 ) {
                 return (false);
+            }
         }
 
         // This URL belongs to our web application, so it is encodeable
@@ -1594,8 +1640,9 @@ public class Response
      */
     protected String toAbsolute(String location) {
 
-        if (location == null)
+        if (location == null) {
             return (location);
+        }
 
         boolean leadingSlash = location.startsWith("/");
 
@@ -1638,18 +1685,18 @@ public class Response
                     String relativePath = request.getDecodedRequestURI();
                     int pos = relativePath.lastIndexOf('/');
                     relativePath = relativePath.substring(0, pos);
-                    
+
                     String encodedURI = null;
                     final String frelativePath = relativePath;
                     if (SecurityUtil.isPackageProtectionEnabled() ){
                         try{
-                            encodedURI = AccessController.doPrivileged( 
-                                new PrivilegedExceptionAction<String>(){                                
+                            encodedURI = AccessController.doPrivileged(
+                                new PrivilegedExceptionAction<String>(){
                                     @Override
                                     public String run() throws IOException{
                                         return urlEncoder.encodeURL(frelativePath);
                                     }
-                           });   
+                           });
                         } catch (PrivilegedActionException pae){
                             IllegalArgumentException iae =
                                 new IllegalArgumentException(location);
@@ -1721,8 +1768,9 @@ public class Response
      */
     protected String toEncoded(String url, String sessionId) {
 
-        if ((url == null) || (sessionId == null))
+        if ((url == null) || (sessionId == null)) {
             return (url);
+        }
 
         String path = url;
         String query = "";

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/ResponseFacade.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/ResponseFacade.java?rev=1200178&r1=1200177&r2=1200178&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/ResponseFacade.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/ResponseFacade.java Thu Nov 10 06:14:46 2011
@@ -5,17 +5,15 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina.connector;
 
 import java.io.IOException;
@@ -36,7 +34,7 @@ import org.apache.catalina.security.Secu
 import org.apache.tomcat.util.res.StringManager;
 
 /**
- * Facade class that wraps a Coyote response object. 
+ * Facade class that wraps a Coyote response object.
  * All methods are delegated to the wrapped response.
  *
  * @author Remy Maucherat
@@ -44,34 +42,34 @@ import org.apache.tomcat.util.res.String
  * @version $Id$
  */
 @SuppressWarnings("deprecation")
-public class ResponseFacade 
+public class ResponseFacade
     implements HttpServletResponse {
 
 
     // ----------------------------------------------------------- DoPrivileged
-    
+
     private final class SetContentTypePrivilegedAction
             implements PrivilegedAction<Void> {
 
-        private String contentType;
+        private final String contentType;
 
         public SetContentTypePrivilegedAction(String contentType){
             this.contentType = contentType;
         }
-        
+
         @Override
         public Void run() {
             response.setContentType(contentType);
             return null;
-        }            
+        }
     }
 
     private final class DateHeaderPrivilegedAction
             implements PrivilegedAction<Void> {
 
-        private String name;
-        private long value;
-        private boolean add;
+        private final String name;
+        private final long value;
+        private final boolean add;
 
         DateHeaderPrivilegedAction(String name, long value, boolean add) {
             this.name = name;
@@ -89,7 +87,7 @@ public class ResponseFacade 
             return null;
         }
     }
-    
+
     // ----------------------------------------------------------- Constructors
 
 
@@ -197,8 +195,9 @@ public class ResponseFacade 
         //                (/*sm.getString("responseFacade.finished")*/);
 
         ServletOutputStream sos = response.getOutputStream();
-        if (isFinished())
+        if (isFinished()) {
             response.setSuspended(true);
+        }
         return (sos);
 
     }
@@ -213,8 +212,9 @@ public class ResponseFacade 
         //                (/*sm.getString("responseFacade.finished")*/);
 
         PrintWriter writer = response.getWriter();
-        if (isFinished())
+        if (isFinished()) {
             response.setSuspended(true);
+        }
         return (writer);
 
     }
@@ -223,8 +223,9 @@ public class ResponseFacade 
     @Override
     public void setContentLength(int len) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.setContentLength(len);
 
@@ -234,13 +235,14 @@ public class ResponseFacade 
     @Override
     public void setContentType(String type) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
-        
+        }
+
         if (SecurityUtil.isPackageProtectionEnabled()){
             AccessController.doPrivileged(new SetContentTypePrivilegedAction(type));
         } else {
-            response.setContentType(type);            
+            response.setContentType(type);
         }
     }
 
@@ -248,9 +250,10 @@ public class ResponseFacade 
     @Override
     public void setBufferSize(int size) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.setBufferSize.ise"));
+        }
 
         response.setBufferSize(size);
 
@@ -273,10 +276,11 @@ public class ResponseFacade 
     public void flushBuffer()
         throws IOException {
 
-        if (isFinished())
+        if (isFinished()) {
             //            throw new IllegalStateException
             //                (/*sm.getString("responseFacade.finished")*/);
             return;
+        }
 
         if (SecurityUtil.isPackageProtectionEnabled()){
             try{
@@ -300,7 +304,7 @@ public class ResponseFacade 
         } else {
             response.setAppCommitted(true);
 
-            response.flushBuffer();            
+            response.flushBuffer();
         }
 
     }
@@ -309,9 +313,10 @@ public class ResponseFacade 
     @Override
     public void resetBuffer() {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.resetBuffer.ise"));
+        }
 
         response.resetBuffer();
 
@@ -333,9 +338,10 @@ public class ResponseFacade 
     @Override
     public void reset() {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.reset.ise"));
+        }
 
         response.reset();
 
@@ -345,8 +351,9 @@ public class ResponseFacade 
     @Override
     public void setLocale(Locale loc) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.setLocale(loc);
     }
@@ -367,8 +374,9 @@ public class ResponseFacade 
     @Override
     public void addCookie(Cookie cookie) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.addCookie(cookie);
 
@@ -439,9 +447,10 @@ public class ResponseFacade 
     public void sendError(int sc, String msg)
         throws IOException {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.sendError.ise"));
+        }
 
         response.setAppCommitted(true);
 
@@ -454,9 +463,10 @@ public class ResponseFacade 
     public void sendError(int sc)
         throws IOException {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.sendError.ise"));
+        }
 
         response.setAppCommitted(true);
 
@@ -469,9 +479,10 @@ public class ResponseFacade 
     public void sendRedirect(String location)
         throws IOException {
 
-        if (isCommitted())
+        if (isCommitted()) {
             throw new IllegalStateException
                 (sm.getString("coyoteResponse.sendRedirect.ise"));
+        }
 
         response.setAppCommitted(true);
 
@@ -483,8 +494,9 @@ public class ResponseFacade 
     @Override
     public void setDateHeader(String name, long date) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         if(Globals.IS_SECURITY_ENABLED) {
             AccessController.doPrivileged(new DateHeaderPrivilegedAction
@@ -499,8 +511,9 @@ public class ResponseFacade 
     @Override
     public void addDateHeader(String name, long date) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         if(Globals.IS_SECURITY_ENABLED) {
             AccessController.doPrivileged(new DateHeaderPrivilegedAction
@@ -515,8 +528,9 @@ public class ResponseFacade 
     @Override
     public void setHeader(String name, String value) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.setHeader(name, value);
 
@@ -526,8 +540,9 @@ public class ResponseFacade 
     @Override
     public void addHeader(String name, String value) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.addHeader(name, value);
 
@@ -537,8 +552,9 @@ public class ResponseFacade 
     @Override
     public void setIntHeader(String name, int value) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.setIntHeader(name, value);
 
@@ -548,8 +564,9 @@ public class ResponseFacade 
     @Override
     public void addIntHeader(String name, int value) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.addIntHeader(name, value);
 
@@ -559,8 +576,9 @@ public class ResponseFacade 
     @Override
     public void setStatus(int sc) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.setStatus(sc);
 
@@ -570,8 +588,9 @@ public class ResponseFacade 
     @Override
     public void setStatus(int sc, String sm) {
 
-        if (isCommitted())
+        if (isCommitted()) {
             return;
+        }
 
         response.setStatus(sc, sm);
     }
@@ -604,17 +623,17 @@ public class ResponseFacade 
     public int getStatus() {
         return response.getStatus();
     }
-    
+
     @Override
     public String getHeader(String name) {
         return response.getHeader(name);
     }
-    
+
     @Override
     public Collection<String> getHeaderNames() {
         return response.getHeaderNames();
     }
-    
+
     @Override
     public Collection<String> getHeaders(String name) {
         return response.getHeaders(name);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org