Author: markt
Date: Wed Jul 10 13:21:39 2013
New Revision: 1501761

URL: http://svn.apache.org/r1501761
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55230
Use the correct resource path when obtaining an InputStream for resources 
served by a ProxyDirContext.

Modified:
    
tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java?rev=1501761&r1=1501760&r2=1501761&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
 Wed Jul 10 13:21:39 2013
@@ -5,15 +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.naming.resources;
 
@@ -47,11 +47,11 @@ import org.apache.tomcat.util.http.FastH
 /**
  * Connection to a JNDI directory context.
  * <p/>
- * Note: All the object attribute names are the WebDAV names, not the HTTP 
+ * Note: All the object attribute names are the WebDAV names, not the HTTP
  * names, so this class overrides some methods from URLConnection to do the
- * queries using the right names. Content handler is also not used; the 
+ * queries using the right names. Content handler is also not used; the
  * content is directly returned.
- * 
+ *
  * @author <a href="mailto:r...@apache.org";>Remy Maucherat</a>
  * @version $Revision$
  */
@@ -65,7 +65,7 @@ public class DirContextURLConnection ext
     }
 
     // ----------------------------------------------------------- Constructors
-    
+
     public DirContextURLConnection(DirContext context, URL url) {
         super(url);
         if (context == null)
@@ -76,53 +76,60 @@ public class DirContextURLConnection ext
     }
         this.context = context;
     }
-    
-    
+
+
     // ----------------------------------------------------- Instance Variables
-    
-    
+
+
     /**
      * Directory context.
      */
     protected DirContext context;
-    
-    
+
+
     /**
      * Associated resource.
      */
     protected Resource resource;
-    
-    
+
+
     /**
      * Associated DirContext.
      */
     protected DirContext collection;
-    
-    
+
+
     /**
      * Other unknown object.
      */
     protected Object object;
-    
-    
+
+
     /**
      * Attributes.
      */
     protected Attributes attributes;
-    
-    
+
+
     /**
      * Date.
      */
     protected long date;
-    
-    
+
+
     /**
      * Permission
      */
     protected Permission permission;
 
 
+    /**
+     * Cache the path as it there is some processing required - particularly if
+     * the context is a ProxyDirContext.
+     */
+    private String path = null;
+
+
     // ------------------------------------------------------------- Properties
 
 
@@ -130,20 +137,19 @@ public class DirContextURLConnection ext
      * Connect to the DirContext, and retrieve the bound object, as well as
      * its attributes. If no object is bound with the name specified in the
      * URL, then an IOException is thrown.
-     * 
+     *
      * @throws IOException Object not found
      */
     @Override
-    public void connect()
-        throws IOException {
-        
+    public void connect() throws IOException {
+
         if (!connected) {
-            
+
             try {
                 date = System.currentTimeMillis();
-                String path = URL_DECODER.convert(getURL().getFile(), false);
+                path = URL_DECODER.convert(getURL().getFile(), false);
                 if (context instanceof ProxyDirContext) {
-                    ProxyDirContext proxyDirContext = 
+                    ProxyDirContext proxyDirContext =
                         (ProxyDirContext) context;
                     String hostName = proxyDirContext.getHostName();
                     String contextPath = proxyDirContext.getContextPath();
@@ -168,14 +174,12 @@ public class DirContextURLConnection ext
             } catch (NamingException e) {
                 // Object not found
             }
-            
+
             connected = true;
-            
         }
-        
     }
-    
-    
+
+
     /**
      * Return the content length value.
      */
@@ -183,8 +187,8 @@ public class DirContextURLConnection ext
     public int getContentLength() {
         return getHeaderFieldInt(ResourceAttributes.CONTENT_LENGTH, -1);
     }
-    
-    
+
+
     /**
      * Return the content type value.
      */
@@ -192,8 +196,8 @@ public class DirContextURLConnection ext
     public String getContentType() {
         return getHeaderField(ResourceAttributes.CONTENT_TYPE);
     }
-    
-    
+
+
     /**
      * Return the last modified date.
      */
@@ -201,8 +205,8 @@ public class DirContextURLConnection ext
     public long getDate() {
         return date;
     }
-    
-    
+
+
     /**
      * Return the last modified date.
      */
@@ -221,7 +225,7 @@ public class DirContextURLConnection ext
         if (attributes == null)
             return 0;
 
-        Attribute lastModified = 
+        Attribute lastModified =
             attributes.get(ResourceAttributes.LAST_MODIFIED);
         if (lastModified != null) {
             try {
@@ -234,7 +238,7 @@ public class DirContextURLConnection ext
 
         return 0;
     }
-    
+
 
     protected String getHeaderValueAsString(Object headerValue) {
         if (headerValue == null) return null;
@@ -291,8 +295,8 @@ public class DirContextURLConnection ext
       return Collections.unmodifiableMap(headerFields);
 
     }
-    
-    
+
+
     /**
      * Returns the name of the specified header field.
      */
@@ -307,7 +311,7 @@ public class DirContextURLConnection ext
                 // Ignore
             }
         }
-        
+
         if (attributes == null)
             return (null);
 
@@ -327,63 +331,61 @@ public class DirContextURLConnection ext
         }
 
         return (null);
-        
+
     }
-    
-    
+
+
     /**
      * Get object content.
      */
     @Override
     public Object getContent()
         throws IOException {
-        
+
         if (!connected)
             connect();
-        
+
         if (resource != null)
             return getInputStream();
         if (collection != null)
             return collection;
         if (object != null)
             return object;
-        
+
         throw new FileNotFoundException(
                 getURL() == null ? "null" : getURL().toString());
-        
+
     }
-    
-    
+
+
     /**
      * Get object content.
      */
-    @SuppressWarnings("rawtypes") // overridden method uses raw type Class[]
     @Override
     public Object getContent(Class[] classes)
         throws IOException {
-        
+
         Object obj = getContent();
-        
+
         for (int i = 0; i < classes.length; i++) {
             if (classes[i].isInstance(obj))
                 return obj;
         }
-        
+
         return null;
-        
+
     }
-    
-    
+
+
     /**
      * Get input stream.
      */
     @Override
-    public InputStream getInputStream() 
-        throws IOException {
-        
+    public InputStream getInputStream() throws IOException {
+
         if (!connected)
             connect();
-        
+
         if (resource == null) {
             throw new FileNotFoundException(
                     getURL() == null ? "null" : getURL().toString());
@@ -391,17 +393,15 @@ public class DirContextURLConnection ext
 
         // Reopen resource
         try {
-            resource = (Resource) context.lookup(
-                    URL_DECODER.convert(getURL().getFile(), false));
+            resource = (Resource) context.lookup(path);
         } catch (NamingException e) {
             // Ignore
         }
-        
+
         return (resource.streamContent());
-        
     }
-    
-    
+
+
     /**
      * Get the Permission for this URL
      */
@@ -413,26 +413,26 @@ public class DirContextURLConnection ext
 
 
     // --------------------------------------------------------- Public Methods
-    
-    
+
+
     /**
      * List children of this collection. The names given are relative to this
      * URI's path. The full uri of the children is then : path + "/" + name.
      */
     public Enumeration<String> list()
         throws IOException {
-        
+
         if (!connected) {
             connect();
         }
-        
+
         if ((resource == null) && (collection == null)) {
             throw new FileNotFoundException(
                     getURL() == null ? "null" : getURL().toString());
         }
-        
+
         Vector<String> result = new Vector<String>();
-        
+
         if (collection != null) {
             try {
                 NamingEnumeration<NameClassPair> enumeration =
@@ -449,10 +449,10 @@ public class DirContextURLConnection ext
                         getURL() == null ? "null" : getURL().toString());
             }
         }
-        
+
         return result.elements();
-        
+
     }
-    
-    
+
+
 }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1501761&r1=1501760&r2=1501761&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Jul 10 13:21:39 2013
@@ -89,6 +89,10 @@
         a named attribute <code>ELResolver.RESOLVABLE_AT_DESIGN_TIME</code> -
         true. (violetagg)
       </fix>
+      <fix>
+        <bug>55230</bug>: Use the correct resource path when obtaining an
+        InputStream for resources served by a ProxyDirContext. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">



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

Reply via email to