ASF Bugzilla – Attachment 26095 Details for
Bug 50019
Adding JNDI "lookup-name" support In XML and Resource Annotations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch that provides lookup functionality and resolves explained issue
patch_lookup.txt (text/plain), 44.46 KB, created by
Gurkan Erdogdu
on 2010-09-28 10:38:17 UTC
(
hide
)
Description:
Patch that provides lookup functionality and resolves explained issue
Filename:
MIME Type:
Creator:
Gurkan Erdogdu
Created:
2010-09-28 10:38:17 UTC
Size:
44.46 KB
patch
obsolete
>Index: org/apache/naming/LookupJndiRef.java >=================================================================== >--- org/apache/naming/LookupJndiRef.java (revision 0) >+++ org/apache/naming/LookupJndiRef.java (revision 0) >@@ -0,0 +1,99 @@ >+/* >+ * 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.naming; >+ >+import javax.naming.Context; >+import javax.naming.RefAddr; >+import javax.naming.Reference; >+import javax.naming.StringRefAddr; >+ >+/** >+ * Represents a reference to lookup. >+ */ >+ >+public class LookupJndiRef >+ extends Reference { >+ >+ >+ // -------------------------------------------------------------- Constants >+ >+ /** >+ * JNDI name for the lookup >+ */ >+ public static final String LOOKUP_NAME = "lookup-name"; >+ >+ >+ /** >+ * Default factory for this reference. >+ */ >+ public static final String DEFAULT_FACTORY = >+ org.apache.naming.factory.Constants.DEFAULT_LOOKUP_JNDI_FACTORY; >+ >+ // ----------------------------------------------------------- Constructors >+ >+ public LookupJndiRef(String lookupName) { >+ this("java.lang.Object",lookupName); >+ } >+ >+ >+ public LookupJndiRef(String resourceType, String lookupName) { >+ this(resourceType,null,null,lookupName); >+ } >+ >+ >+ public LookupJndiRef(String resourceType, String factory, >+ String factoryLocation, String lookupName) { >+ super(resourceType, factory, factoryLocation); >+ if(lookupName != null && !lookupName.equals("")){ >+ RefAddr ref = new StringRefAddr(LOOKUP_NAME, lookupName); >+ add(ref); >+ } >+ } >+ >+ >+ // ----------------------------------------------------- Instance Variables >+ >+ >+ // ------------------------------------------------------ Reference Methods >+ >+ >+ /** >+ * Retrieves the class name of the factory of the object to which this >+ * reference refers. >+ */ >+ @Override >+ public String getFactoryClassName() { >+ String factory = super.getFactoryClassName(); >+ if (factory != null) { >+ return factory; >+ } else { >+ factory = System.getProperty(Context.OBJECT_FACTORIES); >+ if (factory != null) { >+ return null; >+ } else { >+ return DEFAULT_FACTORY; >+ } >+ } >+ } >+ >+ >+ // ------------------------------------------------------------- Properties >+ >+ >+} > >Property changes on: org/apache/naming/LookupJndiRef.java >___________________________________________________________________ >Added: svn:eol-style > + native > >Index: org/apache/naming/factory/LookupJndiFactory.java >=================================================================== >--- org/apache/naming/factory/LookupJndiFactory.java (revision 0) >+++ org/apache/naming/factory/LookupJndiFactory.java (revision 0) >@@ -0,0 +1,133 @@ >+/* >+ * 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.naming.factory; >+ >+import java.util.Hashtable; >+ >+import javax.naming.InitialContext; >+import javax.naming.Name; >+import javax.naming.Context; >+import javax.naming.NamingException; >+import javax.naming.Reference; >+import javax.naming.RefAddr; >+import javax.naming.spi.ObjectFactory; >+ >+import org.apache.naming.LookupJndiRef; >+ >+/** >+ * Object factory for lookups. >+ */ >+ >+public class LookupJndiFactory >+ implements ObjectFactory { >+ >+ >+ // ----------------------------------------------------------- Constructors >+ >+ >+ // -------------------------------------------------------------- Constants >+ >+ >+ // ----------------------------------------------------- Instance Variables >+ >+ >+ // --------------------------------------------------------- Public Methods >+ >+ >+ // -------------------------------------------------- ObjectFactory Methods >+ >+ >+ /** >+ * Create a new Resource env instance. >+ * >+ * @param obj The reference object describing the DataSource >+ */ >+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, >+ Hashtable<?,?> environment) >+ throws Exception { >+ >+ String lookupName = null; >+ if (obj instanceof LookupJndiRef) { >+ Reference ref = (Reference) obj; >+ ObjectFactory factory = null; >+ RefAddr lookupNameRefAddr = ref.get(LookupJndiRef.LOOKUP_NAME); >+ if(lookupNameRefAddr != null){ >+ lookupName = lookupNameRefAddr.getContent().toString(); >+ } >+ RefAddr factoryRefAddr = ref.get(Constants.FACTORY); >+ if (factoryRefAddr != null) { >+ // Using the specified factory >+ String factoryClassName = >+ factoryRefAddr.getContent().toString(); >+ // Loading factory >+ ClassLoader tcl = >+ Thread.currentThread().getContextClassLoader(); >+ Class<?> factoryClass = null; >+ if (tcl != null) { >+ try { >+ factoryClass = tcl.loadClass(factoryClassName); >+ } catch(ClassNotFoundException e) { >+ NamingException ex = new NamingException >+ ("Could not load jndi lookup factory class"); >+ ex.initCause(e); >+ throw ex; >+ } >+ } else { >+ try { >+ factoryClass = Class.forName(factoryClassName); >+ } catch(ClassNotFoundException e) { >+ NamingException ex = new NamingException >+ ("Could not load jndi lookup factory class"); >+ ex.initCause(e); >+ throw ex; >+ } >+ } >+ if (factoryClass != null) { >+ try { >+ factory = (ObjectFactory) factoryClass.newInstance(); >+ } catch(Throwable t) { >+ if (t instanceof NamingException) >+ throw (NamingException) t; >+ NamingException ex = new NamingException >+ ("Could not create jndi lookup factory instance"); >+ ex.initCause(t); >+ throw ex; >+ } >+ } >+ } >+ // Note: No defaults here >+ if (factory != null) { >+ return factory.getObjectInstance >+ (obj, name, nameCtx, environment); >+ } else { >+ if(lookupName == null){ >+ throw new NamingException >+ ("Cannot create jndi lookup factory instance"); >+ }else{ >+ return new InitialContext().lookup(lookupName); >+ } >+ } >+ } >+ >+ return null; >+ >+ } >+ >+ >+} > >Property changes on: org/apache/naming/factory/LookupJndiFactory.java >___________________________________________________________________ >Added: svn:eol-style > + native > >Index: org/apache/naming/factory/Constants.java >=================================================================== >--- org/apache/naming/factory/Constants.java (revision 1002140) >+++ org/apache/naming/factory/Constants.java (working copy) >@@ -53,6 +53,10 @@ > > public static final String OPENEJB_EJB_FACTORY = > Package + ".OpenEjbFactory"; >+ >+ public static final String DEFAULT_LOOKUP_JNDI_FACTORY = >+ Package + ".LookupJndiFactory"; >+ > > public static final String OBJECT_FACTORIES = ""; > >Index: org/apache/catalina/core/DefaultInstanceManager.java >=================================================================== >--- org/apache/catalina/core/DefaultInstanceManager.java (revision 1002140) >+++ org/apache/catalina/core/DefaultInstanceManager.java (working copy) >@@ -29,6 +29,7 @@ > import java.security.PrivilegedAction; > import java.security.PrivilegedActionException; > import java.security.PrivilegedExceptionAction; >+import java.util.HashMap; > import java.util.Map; > import java.util.Properties; > >@@ -133,12 +134,28 @@ > > private Object newInstance(Object instance, Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException { > if (!ignoreAnnotations) { >- Map<String, String> injections = injectionMap.get(clazz.getName()); >+ Map<String, String> injections = getInjections(clazz); > processAnnotations(instance, injections); > postConstruct(instance, clazz); > } > return instance; > } >+ >+ private Map<String, String> getInjections(Class<?> clazz){ >+ Class<?> temp = clazz; >+ Map<String, String> injections = new HashMap<String, String>(); >+ do{ >+ Map<String, String> tempInjections = injectionMap.get(temp.getName()); >+ if(tempInjections != null){ >+ injections.putAll(tempInjections); >+ } >+ >+ temp = temp.getSuperclass(); >+ >+ }while(temp != Object.class); >+ >+ return injections; >+ } > > @Override > public void destroyInstance(Object instance) throws IllegalAccessException, InvocationTargetException { >@@ -451,6 +468,7 @@ > Object instance, Field field, String name, Class<?> clazz) > throws NamingException, IllegalAccessException { > >+ name = normalize(name); > Object lookedupResource; > boolean accessibility; > >@@ -485,6 +503,7 @@ > Object instance, Method method, String name, Class<?> clazz) > throws NamingException, IllegalAccessException, InvocationTargetException { > >+ name = normalize(name); > if (!method.getName().startsWith("set") > || method.getName().length() < 4 > || method.getParameterTypes().length != 1 >@@ -508,16 +527,24 @@ > method.invoke(instance, lookedupResource); > method.setAccessible(accessibility); > } >+ >+ private static String normalize(String jndiName){ >+ if(jndiName != null && jndiName.startsWith("java:comp/env/")){ >+ return jndiName.substring(14); >+ } >+ return jndiName; >+ } >+ > >- public static String getName(Method setter) { >- StringBuilder name = new StringBuilder(setter.getName()); >+ public static String getName(Method setter) { >+ StringBuilder name = new StringBuilder(setter.getName()); > >- // remove 'set' >- name.delete(0, 3); >+ // remove 'set' >+ name.delete(0, 3); > >- // lowercase first char >- name.setCharAt(0, Character.toLowerCase(name.charAt(0))); >+ // lowercase first char >+ name.setCharAt(0, Character.toLowerCase(name.charAt(0))); > >- return name.toString(); >- } >+ return name.toString(); >+ } > } >Index: org/apache/catalina/core/NamingContextListener.java >=================================================================== >--- org/apache/catalina/core/NamingContextListener.java (revision 1002140) >+++ org/apache/catalina/core/NamingContextListener.java (working copy) >@@ -54,12 +54,14 @@ > import org.apache.catalina.deploy.ContextService; > import org.apache.catalina.deploy.ContextTransaction; > 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.LookupJndiRef; > import org.apache.naming.NamingContext; > import org.apache.naming.ResourceEnvRef; > import org.apache.naming.ResourceLinkRef; >@@ -738,17 +740,22 @@ > */ > 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); >@@ -764,85 +771,87 @@ > */ > 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 = new Byte((byte) 0); >- } else { >- value = Byte.decode(env.getValue()); >- } >- } else if (type.equals("java.lang.Short")) { >- if (env.getValue() == null) { >- value = new Short((short) 0); >- } else { >- value = Short.decode(env.getValue()); >- } >- } else if (type.equals("java.lang.Integer")) { >- if (env.getValue() == null) { >- value = new Integer(0); >- } else { >- value = Integer.decode(env.getValue()); >- } >- } else if (type.equals("java.lang.Long")) { >- if (env.getValue() == null) { >- value = new Long(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 = new Double(0); >- } else { >- value = Double.valueOf(env.getValue()); >- } >- } else if (type.equals("java.lang.Float")) { >- if (env.getValue() == null) { >- value = new Float(0); >- } else { >- value = Float.valueOf(env.getValue()); >- } >- } else if (type.equals("java.lang.Character")) { >- if (env.getValue() == null) { >- value = new Character((char) 0); >- } else { >- if (env.getValue().length() == 1) { >- value = new Character(env.getValue().charAt(0)); >+ //Lets check that lookup exist >+ 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 = new Byte((byte) 0); > } else { >- throw new IllegalArgumentException(); >+ value = Byte.decode(env.getValue()); > } >+ } else if (type.equals("java.lang.Short")) { >+ if (env.getValue() == null) { >+ value = new Short((short) 0); >+ } else { >+ value = Short.decode(env.getValue()); >+ } >+ } else if (type.equals("java.lang.Integer")) { >+ if (env.getValue() == null) { >+ value = new Integer(0); >+ } else { >+ value = Integer.decode(env.getValue()); >+ } >+ } else if (type.equals("java.lang.Long")) { >+ if (env.getValue() == null) { >+ value = new Long(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 = new Double(0); >+ } else { >+ value = Double.valueOf(env.getValue()); >+ } >+ } else if (type.equals("java.lang.Float")) { >+ if (env.getValue() == null) { >+ value = new Float(0); >+ } else { >+ value = Float.valueOf(env.getValue()); >+ } >+ } else if (type.equals("java.lang.Character")) { >+ if (env.getValue() == null) { >+ value = new Character((char) 0); >+ } else { >+ if (env.getValue().length() == 1) { >+ value = new Character(env.getValue().charAt(0)); >+ } else { >+ throw new IllegalArgumentException(); >+ } >+ } >+ } else { >+ logger.error(sm.getString("naming.invalidEnvEntryType", env.getName())); > } >- } else { >- logger.error(sm.getString("naming.invalidEnvEntryType", env.getName())); >- } >- } catch (NumberFormatException e) { >- logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName())); >- } catch (IllegalArgumentException e) { >- logger.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()); >- createSubcontexts(envCtx, env.getName()); >- envCtx.bind(env.getName(), value); >- } catch (NamingException e) { >- logger.error(sm.getString("naming.invalidEnvEntryValue", e)); >+ try { >+ if (logger.isDebugEnabled()) >+ logger.debug(" Adding environment entry " + env.getName()); >+ createSubcontexts(envCtx, env.getName()); >+ if(value != null){ >+ envCtx.bind(env.getName(), value); > } >+ } catch (NamingException e) { >+ logger.error(sm.getString("naming.invalidEnvEntryValue", e)); > } >- > } > >- > /** > * Set the specified local EJBs in the naming context. > */ >@@ -858,117 +867,121 @@ > */ > 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()); >+ logger.debug(" Changing service ref wsdl file for /" >+ + service.getWsdlfile()); >+ } catch (MalformedURLException e) { >+ logger.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()); >+ logger.debug(" Changing service ref jaxrpc file for /" >+ + service.getJaxrpcmappingfile()); >+ } catch (MalformedURLException e) { >+ logger.error(sm.getString("naming.wsdlFailed", e)); >+ } >+ } >+ if (jaxrpcURL == null) >+ service.setJaxrpcmappingfile(null); >+ else >+ service.setJaxrpcmappingfile(jaxrpcURL.toString()); > } >- if (jaxrpcURL == null) >- service.setJaxrpcmappingfile(null); >- else >- service.setJaxrpcmappingfile(jaxrpcURL.toString()); >- } > >- // Create a reference to the resource. >- Reference ref = new ServiceRef >- (service.getName(), service.getType(), 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)); >+ // Create a reference to the resource. >+ ref = new ServiceRef >+ (service.getName(), service.getType(), 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); > } >- 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); >+ // 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); >+ } > } >- >+ > try { > if (logger.isDebugEnabled()) { > logger.debug(" Adding service ref " >@@ -988,18 +1001,22 @@ > */ > public void addResource(ContextResource resource) { > >- // Create a reference to the resource. >- Reference ref = new ResourceRef >- (resource.getType(), resource.getDescription(), >- resource.getScope(), resource.getAuth()); >- // 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()); >+ // 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 " >@@ -1030,16 +1047,21 @@ > */ > 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()); >@@ -1209,5 +1231,19 @@ > } > } > >+ >+ /** >+ * Gets look up reference from resource if exist. >+ * @param resourceBase resource base object >+ * @return lookup ref >+ */ >+ private LookupJndiRef lookForLookupRef(ResourceBase resourceBase){ >+ String lookupName = resourceBase.getLookupName(); >+ if((lookupName != null && !lookupName.equals(""))){ >+ return new LookupJndiRef(lookupName); >+ } >+ >+ return null; >+ } > > } >Index: org/apache/catalina/deploy/ResourceBase.java >=================================================================== >--- org/apache/catalina/deploy/ResourceBase.java (revision 1002140) >+++ org/apache/catalina/deploy/ResourceBase.java (working copy) >@@ -43,6 +43,11 @@ > * The description of this Context Element. > */ > private String description = null; >+ >+ /** >+ * <lookup-name> >+ */ >+ private String lookupName = null; > > public String getDescription() { > return (this.description); >@@ -141,6 +146,14 @@ > void setNamingResources(NamingResources resources) { > this.resources = resources; > } >+ >+ public String getLookupName() { >+ return lookupName; >+ } > >+ public void setLookupName(String lookupName) { >+ this.lookupName = lookupName; >+ } > >+ > } >Index: org/apache/catalina/deploy/WebXml.java >=================================================================== >--- org/apache/catalina/deploy/WebXml.java (revision 1002140) >+++ org/apache/catalina/deploy/WebXml.java (working copy) >@@ -888,7 +888,7 @@ > target.getTargetName()); > sb.append(" </injection-target>\n"); > } >- // TODO lookup-name >+ appendElement(sb, INDENT4, "lookup-name", envEntry.getLookupName()); > sb.append(" </env-entry>\n"); > } > sb.append('\n'); >@@ -910,7 +910,7 @@ > target.getTargetName()); > sb.append(" </injection-target>\n"); > } >- // TODO lookup-name >+ appendElement(sb, INDENT4, "lookup-name", ejbRef.getLookupName()); > sb.append(" </ejb-ref>\n"); > } > sb.append('\n'); >@@ -933,7 +933,7 @@ > target.getTargetName()); > sb.append(" </injection-target>\n"); > } >- // TODO lookup-name >+ appendElement(sb, INDENT4, "lookup-name", ejbLocalRef.getLookupName()); > sb.append(" </ejb-local-ref>\n"); > } > sb.append('\n'); >@@ -989,7 +989,7 @@ > target.getTargetName()); > sb.append(" </injection-target>\n"); > } >- // TODO lookup-name >+ appendElement(sb, INDENT4, "lookup-name", serviceRef.getLookupName()); > sb.append(" </service-ref>\n"); > } > sb.append('\n'); >@@ -1012,7 +1012,7 @@ > target.getTargetName()); > sb.append(" </injection-target>\n"); > } >- // TODO lookup-name >+ appendElement(sb, INDENT4, "lookup-name", resourceRef.getLookupName()); > sb.append(" </resource-ref>\n"); > } > sb.append('\n'); >@@ -1035,7 +1035,7 @@ > target.getTargetName()); > sb.append(" </injection-target>\n"); > } >- // TODO lookup-name >+ appendElement(sb, INDENT4, "lookup-name", resourceEnvRef.getLookupName()); > sb.append(" </resource-env-ref>\n"); > } > sb.append('\n'); >@@ -1060,7 +1060,7 @@ > target.getTargetName()); > sb.append(" </injection-target>\n"); > } >- // TODO lookup-name >+ appendElement(sb, INDENT4, "lookup-name", mdr.getLookupName()); > sb.append(" </message-destination-ref>\n"); > } > sb.append('\n'); >@@ -1071,7 +1071,7 @@ > appendElement(sb, INDENT4, "display-name", md.getDisplayName()); > appendElement(sb, INDENT4, "message-destination-name", > md.getName()); >- // TODO mapped-name >+ appendElement(sb, INDENT4, "lookup-name", md.getLookupName()); > sb.append(" </message-destination>\n"); > } > sb.append('\n'); >Index: org/apache/catalina/startup/WebRuleSet.java >=================================================================== >--- org/apache/catalina/startup/WebRuleSet.java (revision 1002140) >+++ org/apache/catalina/startup/WebRuleSet.java (working copy) >@@ -472,6 +472,8 @@ > "setLocal", 0); > digester.addCallMethod(fullPrefix + "/ejb-local-ref/local-home", > "setHome", 0); >+ digester.addCallMethod(fullPrefix + "/ejb-local-ref/lookup-name", >+ "setLookupName", 0); > configureInjectionRules(digester, "web-app/ejb-local-ref/"); > > //ejb-ref >@@ -492,6 +494,8 @@ > "setHome", 0); > digester.addCallMethod(fullPrefix + "/ejb-ref/remote", > "setRemote", 0); >+ digester.addCallMethod(fullPrefix + "/ejb-ref/lookup-name", >+ "setLookupName", 0); > configureInjectionRules(digester, "web-app/ejb-ref/"); > > //env-entry >@@ -508,6 +512,8 @@ > "setType", 0); > digester.addCallMethod(fullPrefix + "/env-entry/env-entry-value", > "setValue", 0); >+ digester.addCallMethod(fullPrefix + "/env-entry/lookup-name", >+ "setLookupName", 0); > configureInjectionRules(digester, "web-app/env-entry/"); > > //resource-env-ref >@@ -520,6 +526,8 @@ > "setName", 0); > digester.addCallMethod(fullPrefix + "/resource-env-ref/resource-env-ref-type", > "setType", 0); >+ digester.addCallMethod(fullPrefix + "/resource-env-ref/lookup-name", >+ "setLookupName", 0); > configureInjectionRules(digester, "web-app/resource-env-ref/"); > > //message-destination >@@ -536,6 +544,8 @@ > "setLargeIcon", 0); > digester.addCallMethod(fullPrefix + "/message-destination/icon/small-icon", > "setSmallIcon", 0); >+ digester.addCallMethod(fullPrefix + "/message-destination/lookup-name", >+ "setLookupName", 0); > digester.addCallMethod(fullPrefix + "/message-destination/message-destination-name", > "setName", 0); > >@@ -555,7 +565,8 @@ > "setType", 0); > digester.addCallMethod(fullPrefix + "/message-destination-ref/message-destination-usage", > "setUsage", 0); >- >+ digester.addCallMethod(fullPrefix + "/message-destination-ref/lookup-name", >+ "setLookupName", 0); > configureInjectionRules(digester, "web-app/message-destination-ref/"); > > //resource-ref >@@ -574,6 +585,8 @@ > "setScope", 0); > digester.addCallMethod(fullPrefix + "/resource-ref/res-type", > "setType", 0); >+ digester.addCallMethod(fullPrefix + "/resource-ref/lookup-name", >+ "setLookupName", 0); > configureInjectionRules(digester, "web-app/resource-ref/"); > > //service-ref >@@ -631,6 +644,8 @@ > "addSoapRole", 0); > digester.addCallMethod(fullPrefix + "/service-ref/handler/port-name", > "addPortName", 0); >+ digester.addCallMethod(fullPrefix + "/service-ref/lookup-name", >+ "setLookupName", 0); > configureInjectionRules(digester, "web-app/service-ref/"); > > >Index: javax/ejb/EJB.java >=================================================================== >--- javax/ejb/EJB.java (revision 1002140) >+++ javax/ejb/EJB.java (working copy) >@@ -33,4 +33,5 @@ > Class beanInterface() default java.lang.Object.class; > String beanName() default ""; > String mappedName() default ""; >+ public String lookup() default ""; > } >Index: javax/xml/ws/WebServiceRef.java >=================================================================== >--- javax/xml/ws/WebServiceRef.java (revision 1002140) >+++ javax/xml/ws/WebServiceRef.java (working copy) >@@ -34,4 +34,5 @@ > public Class value() default java.lang.Object.class; > public String wsdlLocation() default ""; > public String mappedName() default ""; >+ public String lookup() default ""; > } >Index: javax/annotation/Resource.java >=================================================================== >--- javax/annotation/Resource.java (revision 1002140) >+++ javax/annotation/Resource.java (working copy) >@@ -37,5 +37,6 @@ > public AuthenticationType authenticationType() default AuthenticationType.CONTAINER; > public boolean shareable() default true; > public String description() default ""; >- public String mappedName() default ""; >+ public String mappedName() default ""; >+ public String lookup() default ""; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 50019
: 26095 |
26096