Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1831352&r1=1831351&r2=1831352&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java Thu May 10 15:52:10 2018 @@ -56,13 +56,16 @@ import org.apache.catalina.deploy.Contex import org.apache.catalina.deploy.ContextResourceLink; import org.apache.catalina.deploy.ContextService; import org.apache.catalina.deploy.ContextTransaction; +import org.apache.catalina.deploy.MessageDestinationRef; import org.apache.catalina.deploy.NamingResources; +import org.apache.catalina.deploy.ResourceBase; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.naming.ContextAccessController; import org.apache.naming.ContextBindings; import org.apache.naming.EjbRef; import org.apache.naming.HandlerRef; +import org.apache.naming.LookupRef; import org.apache.naming.NamingContext; import org.apache.naming.ResourceEnvRef; import org.apache.naming.ResourceLinkRef; @@ -470,6 +473,19 @@ public class NamingContextListener addLocalEjb(ejb); } } + } else if (name.equals("messageDestinationRef")) { + if (oldValue != null) { + MessageDestinationRef mdr = (MessageDestinationRef) oldValue; + if (mdr.getName() != null) { + removeMessageDestinationRef(mdr.getName()); + } + } + if (newValue != null) { + MessageDestinationRef mdr = (MessageDestinationRef) newValue; + if (mdr.getName() != null) { + addMessageDestinationRef(mdr); + } + } } else if (name.equals("resource")) { if (oldValue != null) { ContextResource resource = (ContextResource) oldValue; @@ -587,6 +603,12 @@ public class NamingContextListener addEjb(ejbs[i]); } + // Message Destination References + MessageDestinationRef[] mdrs = namingResources.findMessageDestinationRefs(); + for (i = 0; i < mdrs.length; i++) { + addMessageDestinationRef(mdrs[i]); + } + // WebServices references ContextService[] services = namingResources.findServices(); for (i = 0; i < services.length; i++) { @@ -678,24 +700,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) { logger.error(sm.getString("naming.bindFailed", e)); } - } @@ -704,86 +729,89 @@ public class NamingContextListener */ public void addEnvironment(ContextEnvironment env) { - Object value = null; - // Instantiating a new instance of the correct object type, and - // initializing it. - String type = env.getType(); - try { - if (type.equals("java.lang.String")) { - value = env.getValue(); - } else if (type.equals("java.lang.Byte")) { - if (env.getValue() == null) { - value = Byte.valueOf((byte) 0); - } else { - value = Byte.decode(env.getValue()); - } - } else if (type.equals("java.lang.Short")) { - if (env.getValue() == null) { - value = Short.valueOf((short) 0); - } else { - value = Short.decode(env.getValue()); - } - } else if (type.equals("java.lang.Integer")) { - if (env.getValue() == null) { - value = Integer.valueOf(0); - } else { - value = Integer.decode(env.getValue()); - } - } else if (type.equals("java.lang.Long")) { - if (env.getValue() == null) { - value = Long.valueOf(0); - } else { - value = Long.decode(env.getValue()); - } - } else if (type.equals("java.lang.Boolean")) { - value = Boolean.valueOf(env.getValue()); - } else if (type.equals("java.lang.Double")) { - if (env.getValue() == null) { - value = Double.valueOf(0); - } else { - value = Double.valueOf(env.getValue()); - } - } else if (type.equals("java.lang.Float")) { - if (env.getValue() == null) { - value = Float.valueOf(0); - } else { - value = Float.valueOf(env.getValue()); - } - } else if (type.equals("java.lang.Character")) { - if (env.getValue() == null) { - value = Character.valueOf((char) 0); - } else { - if (env.getValue().length() == 1) { - value = Character.valueOf(env.getValue().charAt(0)); + Object value = lookForLookupRef(env); + + if (value == null) { + // Instantiating a new instance of the correct object type, and + // initializing it. + String type = env.getType(); + try { + if (type.equals("java.lang.String")) { + value = env.getValue(); + } else if (type.equals("java.lang.Byte")) { + if (env.getValue() == null) { + value = Byte.valueOf((byte) 0); } else { - throw new IllegalArgumentException(); + value = Byte.decode(env.getValue()); + } + } else if (type.equals("java.lang.Short")) { + if (env.getValue() == null) { + value = Short.valueOf((short) 0); + } else { + value = Short.decode(env.getValue()); + } + } else if (type.equals("java.lang.Integer")) { + if (env.getValue() == null) { + value = Integer.valueOf(0); + } else { + value = Integer.decode(env.getValue()); + } + } else if (type.equals("java.lang.Long")) { + if (env.getValue() == null) { + value = Long.valueOf(0); + } else { + value = Long.decode(env.getValue()); + } + } else if (type.equals("java.lang.Boolean")) { + value = Boolean.valueOf(env.getValue()); + } else if (type.equals("java.lang.Double")) { + if (env.getValue() == null) { + value = Double.valueOf(0); + } else { + value = Double.valueOf(env.getValue()); + } + } else if (type.equals("java.lang.Float")) { + if (env.getValue() == null) { + value = Float.valueOf(0); + } else { + value = Float.valueOf(env.getValue()); + } + } else if (type.equals("java.lang.Character")) { + if (env.getValue() == null) { + value = Character.valueOf((char) 0); + } else { + if (env.getValue().length() == 1) { + value = Character.valueOf(env.getValue().charAt(0)); + } else { + throw new IllegalArgumentException(); + } + } + } else { + value = constructEnvEntry(env.getType(), env.getValue()); + if (value == null) { + log.error(sm.getString( + "naming.invalidEnvEntryType", env.getName())); } } - } else { - value = constructEnvEntry(env.getType(), env.getValue()); - if (value == null) { - logger.error(sm.getString( - "naming.invalidEnvEntryType", env.getName())); - } + } catch (NumberFormatException e) { + log.error(sm.getString("naming.invalidEnvEntryValue", env.getName())); + } catch (IllegalArgumentException e) { + log.error(sm.getString("naming.invalidEnvEntryValue", env.getName())); } - } catch (NumberFormatException e) { - logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName())); - } catch (IllegalArgumentException e) { - logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName())); } // Binding the object to the appropriate name if (value != null) { try { - if (logger.isDebugEnabled()) - logger.debug(" Adding environment entry " + env.getName()); + if (log.isDebugEnabled()) { + log.debug(sm.getString("naming.addEnvEntry", env.getName())); + } createSubcontexts(envCtx, env.getName()); envCtx.bind(env.getName(), value); } catch (NamingException e) { logger.error(sm.getString("naming.invalidEnvEntryValue", e)); } } - } @@ -816,10 +844,26 @@ public class NamingContextListener /** * Set the specified local EJBs in the naming context. + * + * @param localEjb the local EJB descriptor (unused) */ public void addLocalEjb( @SuppressWarnings("unused") ContextLocalEjb localEjb) { // NO-OP + // No factory in org.apache.naming.factory + // No reference in org.apache.naming + } + + + /** + * Set the specified message destination refs in the naming context. + * + * @param mdr the message destination ref descriptor (unused) + */ + public void addMessageDestinationRef(MessageDestinationRef mdr) { + // NO-OP + // No factory in org.apache.naming.factory + // No reference in org.apache.naming } @@ -828,128 +872,128 @@ public class NamingContextListener */ public void addService(ContextService service) { - if (service.getWsdlfile() != null) { - URL wsdlURL = null; + Reference ref = lookForLookupRef(service); + + if (ref == null) { + + if (service.getWsdlfile() != null) { + URL wsdlURL = null; - try { - wsdlURL = new URL(service.getWsdlfile()); - } catch (MalformedURLException e) { - // Ignore and carry on - } - if (wsdlURL == null) { try { - wsdlURL = ((Context) container). - getServletContext(). - getResource(service.getWsdlfile()); + wsdlURL = new URL(service.getWsdlfile()); } catch (MalformedURLException e) { // Ignore and carry on } - } - if (wsdlURL == null) { - try { - wsdlURL = ((Context) container). - getServletContext(). - getResource("/" + service.getWsdlfile()); - logger.debug(" Changing service ref wsdl file for /" - + service.getWsdlfile()); - } catch (MalformedURLException e) { - logger.error(sm.getString("naming.wsdlFailed", e)); + if (wsdlURL == null) { + try { + wsdlURL = ((Context) container).getServletContext().getResource( + service.getWsdlfile()); + } catch (MalformedURLException e) { + // Ignore and carry on + } + } + if (wsdlURL == null) { + try { + wsdlURL = ((Context) container).getServletContext().getResource( + "/" + service.getWsdlfile()); + log.debug(" Changing service ref wsdl file for /" + + service.getWsdlfile()); + } catch (MalformedURLException e) { + log.error(sm.getString("naming.wsdlFailed", e)); + } } + if (wsdlURL == null) + service.setWsdlfile(null); + else + service.setWsdlfile(wsdlURL.toString()); } - if (wsdlURL == null) - service.setWsdlfile(null); - else - service.setWsdlfile(wsdlURL.toString()); - } - if (service.getJaxrpcmappingfile() != null) { - URL jaxrpcURL = null; + if (service.getJaxrpcmappingfile() != null) { + URL jaxrpcURL = null; - try { - jaxrpcURL = new URL(service.getJaxrpcmappingfile()); - } catch (MalformedURLException e) { - // Ignore and carry on - } - if (jaxrpcURL == null) { try { - jaxrpcURL = ((Context) container). - getServletContext(). - getResource(service.getJaxrpcmappingfile()); + jaxrpcURL = new URL(service.getJaxrpcmappingfile()); } catch (MalformedURLException e) { // Ignore and carry on } - } - if (jaxrpcURL == null) { - try { - jaxrpcURL = ((Context) container). - getServletContext(). - getResource("/" + service.getJaxrpcmappingfile()); - logger.debug(" Changing service ref jaxrpc file for /" - + service.getJaxrpcmappingfile()); - } catch (MalformedURLException e) { - logger.error(sm.getString("naming.wsdlFailed", e)); + if (jaxrpcURL == null) { + try { + jaxrpcURL = ((Context) container).getServletContext().getResource( + service.getJaxrpcmappingfile()); + } catch (MalformedURLException e) { + // Ignore and carry on + } } + if (jaxrpcURL == null) { + try { + jaxrpcURL = ((Context) container).getServletContext().getResource( + "/" + service.getJaxrpcmappingfile()); + log.debug(" Changing service ref jaxrpc file for /" + + service.getJaxrpcmappingfile()); + } catch (MalformedURLException e) { + log.error(sm.getString("naming.wsdlFailed", e)); + } + } + if (jaxrpcURL == null) + service.setJaxrpcmappingfile(null); + else + service.setJaxrpcmappingfile(jaxrpcURL.toString()); + } + + // Create a reference to the resource. + ref = new ServiceRef(service.getName(), service.getInterface(), + service.getServiceqname(), service.getWsdlfile(), + service.getJaxrpcmappingfile()); + + // Adding the additional port-component-ref, if any + Iterator<String> portcomponent = service.getServiceendpoints(); + while (portcomponent.hasNext()) { + String serviceendpoint = portcomponent.next(); + StringRefAddr refAddr = new StringRefAddr(ServiceRef.SERVICEENDPOINTINTERFACE, serviceendpoint); + ref.add(refAddr); + String portlink = service.getPortlink(serviceendpoint); + refAddr = new StringRefAddr(ServiceRef.PORTCOMPONENTLINK, portlink); + ref.add(refAddr); } - if (jaxrpcURL == null) - service.setJaxrpcmappingfile(null); - else - service.setJaxrpcmappingfile(jaxrpcURL.toString()); - } - - // Create a reference to the resource. - Reference ref = new ServiceRef - (service.getName(), service.getInterface(), service.getServiceqname(), - service.getWsdlfile(), service.getJaxrpcmappingfile()); - // Adding the additional port-component-ref, if any - Iterator<String> portcomponent = service.getServiceendpoints(); - while (portcomponent.hasNext()) { - String serviceendpoint = portcomponent.next(); - StringRefAddr refAddr = new StringRefAddr(ServiceRef.SERVICEENDPOINTINTERFACE, serviceendpoint); - ref.add(refAddr); - String portlink = service.getPortlink(serviceendpoint); - refAddr = new StringRefAddr(ServiceRef.PORTCOMPONENTLINK, portlink); - ref.add(refAddr); - } - // Adding the additional parameters, if any - Iterator<String> handlers = service.getHandlers(); - while (handlers.hasNext()) { - String handlername = handlers.next(); - ContextHandler handler = service.getHandler(handlername); - HandlerRef handlerRef = new HandlerRef(handlername, handler.getHandlerclass()); - Iterator<String> localParts = handler.getLocalparts(); - while (localParts.hasNext()) { - String localPart = localParts.next(); - String namespaceURI = handler.getNamespaceuri(localPart); - handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_LOCALPART, localPart)); - handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_NAMESPACE, namespaceURI)); - } - Iterator<String> params = handler.listProperties(); - while (params.hasNext()) { - String paramName = params.next(); - String paramValue = (String) handler.getProperty(paramName); - handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMNAME, paramName)); - handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMVALUE, paramValue)); - } - for (int i = 0; i < handler.getSoapRolesSize(); i++) { - handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_SOAPROLE, handler.getSoapRole(i))); - } - for (int i = 0; i < handler.getPortNamesSize(); i++) { - handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PORTNAME, handler.getPortName(i))); + // Adding the additional parameters, if any + Iterator<String> handlers = service.getHandlers(); + while (handlers.hasNext()) { + String handlername = handlers.next(); + ContextHandler handler = service.getHandler(handlername); + HandlerRef handlerRef = new HandlerRef(handlername, handler.getHandlerclass()); + Iterator<String> localParts = handler.getLocalparts(); + while (localParts.hasNext()) { + String localPart = localParts.next(); + String namespaceURI = handler.getNamespaceuri(localPart); + handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_LOCALPART, localPart)); + handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_NAMESPACE, namespaceURI)); + } + Iterator<String> params = handler.listProperties(); + while (params.hasNext()) { + String paramName = params.next(); + String paramValue = (String) handler.getProperty(paramName); + handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMNAME, paramName)); + handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMVALUE, paramValue)); + } + for (int i = 0; i < handler.getSoapRolesSize(); i++) { + handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_SOAPROLE, handler.getSoapRole(i))); + } + for (int i = 0; i < handler.getPortNamesSize(); i++) { + handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PORTNAME, handler.getPortName(i))); + } + ((ServiceRef) ref).addHandler(handlerRef); } - ((ServiceRef) ref).addHandler(handlerRef); } try { - if (logger.isDebugEnabled()) { - logger.debug(" Adding service ref " - + service.getName() + " " + ref); + if (log.isDebugEnabled()) { + log.debug(" Adding service ref " + service.getName() + " " + ref); } createSubcontexts(envCtx, service.getName()); envCtx.bind(service.getName(), ref); } catch (NamingException e) { logger.error(sm.getString("naming.bindFailed", e)); } - } @@ -958,23 +1002,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 (logger.isDebugEnabled()) { - logger.debug(" Adding resource ref " - + resource.getName() + " " + ref); + if (log.isDebugEnabled()) { + log.debug(" Adding resource ref " + resource.getName() + " " + ref); } createSubcontexts(envCtx, resource.getName()); envCtx.bind(resource.getName(), ref); @@ -1003,25 +1049,30 @@ 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 { - if (logger.isDebugEnabled()) - log.debug(" Adding resource env ref " + resourceEnvRef.getName()); + if (log.isDebugEnabled()) { + log.debug(sm.getString("naming.addResourceEnvRef", resourceEnvRef.getName())); + } createSubcontexts(envCtx, resourceEnvRef.getName()); envCtx.bind(resourceEnvRef.getName(), ref); } catch (NamingException e) { logger.error(sm.getString("naming.bindFailed", e)); } - } @@ -1069,7 +1120,7 @@ public class NamingContextListener /** - * Set the specified EJBs in the naming context. + * Remove the specified EJB from the naming context. */ public void removeEjb(String name) { @@ -1083,7 +1134,7 @@ public class NamingContextListener /** - * Set the specified environment entries in the naming context. + * Remove the specified environment entry from the naming context. */ public void removeEnvironment(String name) { @@ -1097,7 +1148,7 @@ public class NamingContextListener /** - * Set the specified local EJBs in the naming context. + * Remove the specified local EJB from the naming context. */ public void removeLocalEjb(String name) { @@ -1111,7 +1162,26 @@ public class NamingContextListener /** - * Set the specified web services in the naming context. + * Remove the specified message destination ref from the naming context. + * + * @param name the name of the message destination ref which should be + * removed + */ + public void removeMessageDestinationRef(String name) { + + try { + envCtx.unbind(name); + } catch (NamingException e) { + log.error(sm.getString("naming.unbindFailed", e)); + } + + } + + + /** + * Remove the specified web service from the naming context. + * + * @param name the name of the web service which should be removed */ public void removeService(String name) { @@ -1125,7 +1195,7 @@ public class NamingContextListener /** - * Set the specified resources in the naming context. + * Remove the specified resource from the naming context. */ public void removeResource(String name) { @@ -1144,7 +1214,11 @@ public class NamingContextListener /** - * Set the specified resources in the naming context. + * Remove the specified resource environment reference from the naming + * context. + * + * @param name the name of the resource environment reference which should + * be removed */ public void removeResourceEnvRef(String name) { @@ -1158,7 +1232,7 @@ public class NamingContextListener /** - * Set the specified resources in the naming context. + * Remove the specified resource link from the naming context. */ public void removeResourceLink(String name) { @@ -1195,4 +1269,17 @@ public class NamingContextListener } + /** + * Gets look up reference from resource if exist. + * + * @param resourceBase resource base object + * @return lookup ref + */ + private LookupRef lookForLookupRef(ResourceBase resourceBase) { + String lookupName = resourceBase.getLookupName(); + if ((lookupName != null && !lookupName.equals(""))) { + return new LookupRef(resourceBase.getType(), lookupName); + } + return null; + } }
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=1831352&r1=1831351&r2=1831352&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties Thu May 10 15:52:10 2018 @@ -55,6 +55,8 @@ 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}] namingResources.resourceTypeFail=The JNDI resource named [{0}] is of type [{1}] but the type is inconsistent with the type(s) of the injection target(s) configured for that resource Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/NamingResources.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/NamingResources.java?rev=1831352&r1=1831351&r2=1831352&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/NamingResources.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/NamingResources.java Thu May 10 15:52:10 2018 @@ -24,6 +24,7 @@ import java.lang.reflect.InvocationTarge import java.lang.reflect.Method; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.naming.NamingException; @@ -200,6 +201,15 @@ public class NamingResources extends Lif */ 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 { @@ -247,12 +257,22 @@ public class NamingResources extends Lif } } + List<InjectionTarget> injectionTargets = environment.getInjectionTargets(); + String value = environment.getValue(); + String lookupName = environment.getLookupName(); + // Entries with injection targets but no value are effectively ignored - if (environment.getInjectionTargets() != null && environment.getInjectionTargets().size() > 0 && - (environment.getValue() == null || environment.getValue().length() == 0)) { + if (injectionTargets != null && injectionTargets.size() > 0 && + (value == null || value.length() == 0)) { return; } + // Entries with lookup-name and value are an error (EE.5.4.1.3) + if (value != null && value.length() > 0 && lookupName != null && lookupName.length() > 0) { + throw new IllegalArgumentException( + sm.getString("namingResources.envEntryLookupValue", environment.getName())); + } + if (!checkResourceType(environment)) { throw new IllegalArgumentException(sm.getString( "namingResources.resourceTypeFail", environment.getName(), Copied: tomcat/tc7.0.x/trunk/test/org/apache/naming/TestEnvEntry.java (from r1831350, tomcat/tc8.0.x/trunk/test/org/apache/naming/TestEnvEntry.java) URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/naming/TestEnvEntry.java?p2=tomcat/tc7.0.x/trunk/test/org/apache/naming/TestEnvEntry.java&p1=tomcat/tc8.0.x/trunk/test/org/apache/naming/TestEnvEntry.java&r1=1831350&r2=1831352&rev=1831352&view=diff ============================================================================== --- tomcat/tc8.0.x/trunk/test/org/apache/naming/TestEnvEntry.java (original) +++ tomcat/tc7.0.x/trunk/test/org/apache/naming/TestEnvEntry.java Thu May 10 15:52:10 2018 @@ -118,7 +118,7 @@ public class TestEnvEntry extends Tomcat Context context = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); Tomcat.addServlet(context, "InjectionServlet", "org.apache.naming.TesterInjectionServlet"); - context.addServletMappingDecoded("/injection", "InjectionServlet"); + context.addServletMapping("/injection", "InjectionServlet"); tomcat.enableNaming(); tomcat.start(); 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=1831352&r1=1831351&r2=1831352&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu May 10 15:52:10 2018 @@ -110,6 +110,10 @@ Refactor the <code>org.apache.naming</code> package to reduce duplicate code. Duplicate code identified by the Simian tool. (markt) </scode> + <fix> + <bug>50019</bug>: Add support for <code><lookup-name></code>. + Based on a patch by Gurkan Erdogdu. (markt) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org