Author: markt
Date: Mon Jul  6 09:29:44 2015
New Revision: 1689346

URL: http://svn.apache.org/r1689346
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=58096
Ensure that the correct codeBase is returned for classes loaded from 
WEB-INF/classes

Added:
    tomcat/trunk/test/org/apache/catalina/webresources/TestFileResource.java   
(with props)
    tomcat/trunk/test/webapp/WEB-INF/classes/org/
    tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/
    tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/
    tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.class   
(with props)
    tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.java   
(with props)
    tomcat/trunk/test/webapp/bug5nnnn/bug58096.jsp   (with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java

Modified: tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java?rev=1689346&r1=1689345&r2=1689346&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java Mon 
Jul  6 09:29:44 2015
@@ -210,7 +210,11 @@ public class FileResource extends Abstra
 
     @Override
     public URL getCodeBase() {
-        return getURL();
+        if (getWebappPath().startsWith("/WEB-INF/classes/") && 
name.endsWith(".class")) {
+            return 
getWebResourceRoot().getResource("/WEB-INF/classes/").getURL();
+        } else {
+            return getURL();
+        }
     }
 
     @Override

Added: tomcat/trunk/test/org/apache/catalina/webresources/TestFileResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestFileResource.java?rev=1689346&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/webresources/TestFileResource.java 
(added)
+++ tomcat/trunk/test/org/apache/catalina/webresources/TestFileResource.java 
Mon Jul  6 09:29:44 2015
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.webresources;
+
+import java.io.File;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class TestFileResource extends TomcatBaseTest {
+
+    @Test
+    public void doIt() throws Exception {
+        getTomcatInstanceTestWebapp(false, true);
+
+        ByteChunk out = new ByteChunk();
+
+        int rc = getUrl("http://localhost:"; + getPort() + 
"/test/bug5nnnn/bug58096.jsp", out, null);
+
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+
+        // Build the expected location the same way the webapp base dir is 
built
+        File f = new File("test/webapp/WEB-INF/classes");
+        Assert.assertEquals(f.toURI().toURL().toString(), 
out.toString().trim());
+    }
+}

Propchange: 
tomcat/trunk/test/org/apache/catalina/webresources/TestFileResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.class
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.class?rev=1689346&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.java?rev=1689346&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.java 
(added)
+++ tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.java 
Mon Jul  6 09:29:44 2015
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.tomcat;
+
+/**
+ * Contains no functionality since it is only used tp test the code source
+ * assigned to the class.
+ */
+public class Bug58096 {
+}

Propchange: 
tomcat/trunk/test/webapp/WEB-INF/classes/org/apache/tomcat/Bug58096.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/webapp/bug5nnnn/bug58096.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/bug5nnnn/bug58096.jsp?rev=1689346&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/bug5nnnn/bug58096.jsp (added)
+++ tomcat/trunk/test/webapp/bug5nnnn/bug58096.jsp Mon Jul  6 09:29:44 2015
@@ -0,0 +1,17 @@
+<%--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  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.
+--%>
+<%= 
org.apache.tomcat.Bug58096.class.getProtectionDomain().getCodeSource().getLocation()
 %>
\ No newline at end of file

Propchange: tomcat/trunk/test/webapp/bug5nnnn/bug58096.jsp
------------------------------------------------------------------------------
    svn:eol-style = native



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

Reply via email to