Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49956
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 6 Oct 2010 21:58:37 +0000 (21:58 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 6 Oct 2010 21:58:37 +0000 (21:58 +0000)
Handle case when @Resource annotation uses the full JNDI name for a resource.
Based on a patch by Gurkan Erdogdu.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1005271 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/DefaultInstanceManager.java
webapps/docs/changelog.xml

index 8c989e3..85187fe 100644 (file)
@@ -454,9 +454,10 @@ public class DefaultInstanceManager implements InstanceManager {
         Object lookedupResource;
         boolean accessibility;
 
-        if ((name != null) &&
-                (name.length() > 0)) {
-            lookedupResource = context.lookup(name);
+        String normalizedName = normalize(name);
+
+        if ((normalizedName != null) && (normalizedName.length() > 0)) {
+            lookedupResource = context.lookup(normalizedName);
         } else {
             lookedupResource =
                 context.lookup(clazz.getName() + "/" + field.getName());
@@ -495,9 +496,10 @@ public class DefaultInstanceManager implements InstanceManager {
         Object lookedupResource;
         boolean accessibility;
 
-        if ((name != null) &&
-                (name.length() > 0)) {
-            lookedupResource = context.lookup(name);
+        String normalizedName = normalize(name);
+
+        if ((normalizedName != null) && (normalizedName.length() > 0)) {
+            lookedupResource = context.lookup(normalizedName);
         } else {
             lookedupResource = context.lookup(
                     clazz.getName() + "/" + getName(method));
@@ -520,4 +522,11 @@ public class DefaultInstanceManager implements InstanceManager {
 
         return name.toString();
     }
+    
+    private static String normalize(String jndiName){
+        if(jndiName != null && jndiName.startsWith("java:comp/env/")){
+            return jndiName.substring(14);
+        }
+        return jndiName;
+    }
 }
index 8dccec6..435155b 100644 (file)
         <bug>49952</bug>: Allow ServletContainerInitializers to add listeners to
         a web application. Patch provided by David Jencks. (markt)
       </fix>
+      <fix>
+        <bug>49956</bug>: Handle case when @Resource annotation uses the full
+        JNDI name for a resource. Based on a patch by Gurkan Erdogdu. (markt) 
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">