Author: markt
Date: Thu May 10 13:16:20 2018
New Revision: 1831338

URL: http://svn.apache.org/viewvc?rev=1831338&view=rev
Log:
Expand lookup-name implementation to ejb-ref, resource-ref, and resource-env-ref

Modified:
    tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java
    tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/deploy/NamingResourcesImpl.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1831338&r1=1831337&r2=1831338&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java Thu 
May 10 13:16:20 2018
@@ -654,24 +654,27 @@ public class NamingContextListener
      */
     public void addEjb(ContextEjb ejb) {
 
-        // Create a reference to the EJB.
-        Reference ref = new EjbRef
-            (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
-        // Adding the additional parameters, if any
-        Iterator<String> params = ejb.listProperties();
-        while (params.hasNext()) {
-            String paramName = params.next();
-            String paramValue = (String) ejb.getProperty(paramName);
-            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
-            ref.add(refAddr);
+        Reference ref = lookForLookupRef(ejb);
+
+        if (ref == null) {
+            // Create a reference to the EJB.
+            ref = new EjbRef(ejb.getType(), ejb.getHome(), ejb.getRemote(), 
ejb.getLink());
+            // Adding the additional parameters, if any
+            Iterator<String> params = ejb.listProperties();
+            while (params.hasNext()) {
+                String paramName = params.next();
+                String paramValue = (String) ejb.getProperty(paramName);
+                StringRefAddr refAddr = new StringRefAddr(paramName, 
paramValue);
+                ref.add(refAddr);
+            }
         }
+
         try {
             createSubcontexts(envCtx, ejb.getName());
             envCtx.bind(ejb.getName(), ref);
         } catch (NamingException e) {
             log.error(sm.getString("naming.bindFailed", e));
         }
-
     }
 
 
@@ -944,23 +947,25 @@ public class NamingContextListener
      */
     public void addResource(ContextResource resource) {
 
-        // Create a reference to the resource.
-        Reference ref = new ResourceRef
-            (resource.getType(), resource.getDescription(),
-             resource.getScope(), resource.getAuth(),
-             resource.getSingleton());
-        // Adding the additional parameters, if any
-        Iterator<String> params = resource.listProperties();
-        while (params.hasNext()) {
-            String paramName = params.next();
-            String paramValue = (String) resource.getProperty(paramName);
-            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
-            ref.add(refAddr);
+        Reference ref = lookForLookupRef(resource);
+
+        if (ref == null) {
+            // Create a reference to the resource.
+            ref = new ResourceRef(resource.getType(), 
resource.getDescription(),
+                    resource.getScope(), resource.getAuth(), 
resource.getSingleton());
+            // Adding the additional parameters, if any
+            Iterator<String> params = resource.listProperties();
+            while (params.hasNext()) {
+                String paramName = params.next();
+                String paramValue = (String) resource.getProperty(paramName);
+                StringRefAddr refAddr = new StringRefAddr(paramName, 
paramValue);
+                ref.add(refAddr);
+            }
         }
+
         try {
             if (log.isDebugEnabled()) {
-                log.debug("  Adding resource ref "
-                             + resource.getName() + "  " + ref);
+                log.debug("  Adding resource ref " + resource.getName() + "  " 
+ ref);
             }
             createSubcontexts(envCtx, resource.getName());
             envCtx.bind(resource.getName(), ref);
@@ -991,15 +996,19 @@ public class NamingContextListener
      */
     public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {
 
-        // Create a reference to the resource env.
-        Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
-        // Adding the additional parameters, if any
-        Iterator<String> params = resourceEnvRef.listProperties();
-        while (params.hasNext()) {
-            String paramName = params.next();
-            String paramValue = (String) resourceEnvRef.getProperty(paramName);
-            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
-            ref.add(refAddr);
+        Reference ref = lookForLookupRef(resourceEnvRef);
+
+        if (ref == null) {
+            // Create a reference to the resource env.
+            ref = new ResourceEnvRef(resourceEnvRef.getType());
+            // Adding the additional parameters, if any
+            Iterator<String> params = resourceEnvRef.listProperties();
+            while (params.hasNext()) {
+                String paramName = params.next();
+                String paramValue = (String) 
resourceEnvRef.getProperty(paramName);
+                StringRefAddr refAddr = new StringRefAddr(paramName, 
paramValue);
+                ref.add(refAddr);
+            }
         }
 
         try {

Modified: tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=1831338&r1=1831337&r2=1831338&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties Thu 
May 10 13:16:20 2018
@@ -18,6 +18,7 @@ namingResources.cleanupCloseSecurity=Una
 namingResources.cleanupNoClose=Resource [{0}] in container [{1}] does not have 
a [{2}] method so no cleanup was performed for that resource
 namingResources.cleanupNoContext=Failed to retrieve JNDI naming context for 
container [{0}] so no cleanup was performed for that container
 namingResources.cleanupNoResource=Failed to retrieve JNDI resource [{0}] for 
container [{1}] so no cleanup was performed for that resource
+namingResources.ejbLookupLink=The EJB reference [{0}] specifies both a 
ejb-link and a lookup-name
 namingResources.envEntryLookupValue=The environment entry [{0}] specifies both 
a lookup-name and a value
 namingResources.mbeanCreateFail=Failed to create MBean for naming resource 
[{0}]
 namingResources.mbeanDestroyFail=Failed to destroy MBean for naming resource 
[{0}]

Modified: tomcat/trunk/java/org/apache/catalina/deploy/NamingResourcesImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/NamingResourcesImpl.java?rev=1831338&r1=1831337&r2=1831338&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/NamingResourcesImpl.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/NamingResourcesImpl.java Thu 
May 10 13:16:20 2018
@@ -215,6 +215,15 @@ public class NamingResourcesImpl extends
      */
     public void addEjb(ContextEjb ejb) {
 
+        // Entries with lookup-name and ejb-link are an error (EE.5.5.2 / 
EE.5.5.3)
+        String ejbLink = ejb.getLink();
+        String lookupName = ejb.getLookupName();
+
+        if (ejbLink != null && ejbLink.length() > 0 && lookupName != null && 
lookupName.length() > 0) {
+            throw new IllegalArgumentException(
+                    sm.getString("namingResources.ejbLookupLink", 
ejb.getName()));
+        }
+
         if (entries.contains(ejb.getName())) {
             return;
         } else {

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1831338&r1=1831337&r2=1831338&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu May 10 13:16:20 2018
@@ -79,7 +79,9 @@
       </fix>
       <fix>
         Partial fix for <bug>50019</bug>: Add support for
-        <code>&lt;lookup-name&gt;</code> with environment entries. (markt)
+        <code>&lt;lookup-name&gt;</code> with environment entries, EJB
+        references, resource references and resource environment references.
+        (markt)
       </fix>
     </changelog>
   </subsection>



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

Reply via email to