That's what i saw but i wonder how you can have a non default map. Normally i fixed it in openejb (i hope i didnt forget a line) that's whu i asked if geronimo was using the method directly.
- Romain Le 20 juin 2011 03:50, "Shawn Jiang" <[email protected]> a écrit : > Our tck automation is blocked so that I just added a quick fix to refactor > the code logic to make geronimo pass. > > I have not looked into the root cause. The failure scenario in geronimo > is like this: > > 1, Get a non default Map<string, StringTemplate> from templates. > 2, The non default Map<string,StringTemplate> does not have a "default" > key. > 3, This will result in NPE. > > On Mon, Jun 20, 2011 at 12:55 AM, Romain Manni-Bucau > <[email protected]>wrote: > >> Hi Shawn, >> >> with tests i was never in the case you fixed so for me it changes nothing >> but it means my fix was not really good, did you check why it was not >> working? >> >> Is geronimo useing these API? >> >> - Romain >> >> 2011/6/19 Shawn Jiang <[email protected]> >> >> > Hi Romain, >> > >> > This revision blocked geronimo server from starting. >> > >> > I commited a quick fix with r1137371. Please take a look to see if my >> > fix >> > has any impact to you. >> > >> > On Sun, Jun 19, 2011 at 4:15 AM, <[email protected]> wrote: >> > >> > > Author: rmannibucau >> > > Date: Sat Jun 18 20:15:29 2011 >> > > New Revision: 1137242 >> > > >> > > URL: http://svn.apache.org/viewvc?rev=1137242&view=rev >> > > Log: >> > > adding a key by template strategy to avoid to loose template (useful >> for >> > > spring for example) >> > > >> > > Modified: >> > > >> > > >> > >> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java >> > > >> > > >> > >> openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/AbstractApplication.java >> > > >> > > >> > >> openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/EchoReverseBean.java >> > > >> > > Modified: >> > > >> > >> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java >> > > URL: >> > > >> > >> http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java?rev=1137242&r1=1137241&r2=1137242&view=diff >> > > >> > > >> > >> ============================================================================== >> > > --- >> > > >> > >> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java >> > > (original) >> > > +++ >> > > >> > >> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java >> > > Sat Jun 18 20:15:29 2011 >> > > @@ -18,6 +18,7 @@ package org.apache.openejb.assembler.cla >> > > >> > > import static org.apache.openejb.util.Classes.packageName; >> > > >> > > +import java.util.TreeMap; >> > > import javax.ejb.embeddable.EJBContainer; >> > > import javax.naming.NamingException; >> > > import javax.naming.Reference; >> > > @@ -56,6 +57,7 @@ import java.lang.reflect.Constructor; >> > > */ >> > > public class JndiBuilder { >> > > >> > > + public static final String DEFAULT_NAME_KEY = "default"; >> > > >> > > final boolean embeddedEjbContainerApi; >> > > >> > > @@ -165,7 +167,8 @@ public class JndiBuilder { >> > > >> > > public void begin(BeanContext beanContext); >> > > >> > > - public String getName(Class interfce, Interface type); >> > > + public String getName(Class interfce, String key, Interface >> > type); >> > > + public Map<String, String> getNames(Class interfce, Interface >> > > type); >> > > >> > > public void end(); >> > > } >> > > @@ -174,6 +177,7 @@ public class JndiBuilder { >> > > >> > > public static class TemplatedStrategy implements JndiNameStrategy { >> > > private static final String JNDINAME_FORMAT = >> > > "openejb.jndiname.format"; >> > > + private static final String KEYS = "default,local,global,app"; >> > > private org.apache.openejb.util.StringTemplate template; >> > > private HashMap<String, EnterpriseBeanInfo> beanInfos; >> > > >> > > @@ -181,7 +185,7 @@ public class JndiBuilder { >> > > private BeanContext bean; >> > > >> > > // Set in begin() >> > > - private Map<String, StringTemplate> templates; >> > > + private HashMap<String, Map<String, StringTemplate>> >> templates; >> > > >> > > private String format; >> > > private Map<String, String> appContext; >> > > @@ -234,18 +238,27 @@ public class JndiBuilder { >> > > } >> > > } >> > > >> > > + private Map<String, StringTemplate> addTemplate(Map<String, >> > > StringTemplate> map, String key, StringTemplate template) { >> > > + Map<String, StringTemplate> m = map; >> > > + if (m == null) { >> > > + m = new TreeMap<String, StringTemplate> (); >> > > + } >> > > + m.put(key, template); >> > > + return m; >> > > + } >> > > + >> > > public void begin(BeanContext bean) { >> > > this.bean = bean; >> > > >> > > EnterpriseBeanInfo beanInfo = >> > > beanInfos.get(bean.getDeploymentID()); >> > > >> > > - templates = new HashMap<String, StringTemplate>(); >> > > - templates.put("", template); >> > > + templates = new HashMap<String, Map<String, >> > > StringTemplate>>(); >> > > + templates.put("", addTemplate(null, "default", template)); >> > > >> > > for (JndiNameInfo nameInfo : beanInfo.jndiNamess) { >> > > String intrface = nameInfo.intrface; >> > > if (intrface == null) intrface = ""; >> > > - templates.put(intrface, new >> > > StringTemplate(nameInfo.name)); >> > > + templates.put(intrface, >> > > addTemplate(templates.get(intrface), getType(nameInfo.name), new >> > > StringTemplate(nameInfo.name))); >> > > } >> > > beanInfo.jndiNames.clear(); >> > > beanInfo.jndiNamess.clear(); >> > > @@ -260,11 +273,23 @@ public class JndiBuilder { >> > > this.beanContext.put("deploymentId", >> > > bean.getDeploymentID().toString()); >> > > } >> > > >> > > + private static String getType(String name) { >> > > + int start = 0; >> > > + if (name.charAt(0) == '/') { >> > > + start = 1; >> > > + } >> > > + int end = name.substring(start).indexOf('/'); >> > > + if (end < 0) { >> > > + return DEFAULT_NAME_KEY; >> > > + } >> > > + return name.substring(start, end); >> > > + } >> > > + >> > > public void end() { >> > > } >> > > >> > > - public String getName(Class interfce, Interface type) { >> > > - StringTemplate template = >> templates.get(interfce.getName()); >> > > + public String getName(Class interfce, String key, Interface >> > type) >> > > { >> > > + Map<String, StringTemplate> template = >> > > templates.get(interfce.getName()); >> > > if (template == null) template = >> > > templates.get(type.getAnnotationName()); >> > > if (template == null) template = templates.get(""); >> > > >> > > @@ -279,7 +304,18 @@ public class JndiBuilder { >> > > contextData.put("interfaceClass.simpleName", >> > > interfce.getSimpleName()); >> > > contextData.put("interfaceClass.packageName", >> > > packageName(interfce)); >> > > >> > > - return template.apply(contextData); >> > > + if (template.containsKey(key)) { >> > > + return template.get(key).apply(contextData); >> > > + } >> > > + return template.get(DEFAULT_NAME_KEY).apply(contextData); >> > > + } >> > > + >> > > + @Override public Map<String, String> getNames(Class interfce, >> > > Interface type) { >> > > + Map<String, String> names = new HashMap<String, String>(); >> > > + for (String key : KEYS.split(",")) { >> > > + names.put(key, getName(interfce, key, type)); >> > > + } >> > > + return names; >> > > } >> > > } >> > > >> > > @@ -293,7 +329,7 @@ public class JndiBuilder { >> > > public void end() { >> > > } >> > > >> > > - public String getName(Class interfce, Interface type) { >> > > + public String getName(Class interfce, String key, Interface >> > type) >> > > { >> > > String id = beanContext.getDeploymentID() + ""; >> > > if (id.charAt(0) == '/') { >> > > id = id.substring(1); >> > > @@ -311,6 +347,12 @@ public class JndiBuilder { >> > > } >> > > return id; >> > > } >> > > + >> > > + @Override public Map<String, String> getNames(Class interfce, >> > > Interface type) { >> > > + Map<String, String> names = new HashMap<String, String>(); >> > > + names.put("", getName(interfce, DEFAULT_NAME_KEY, type)); >> > > + return names; >> > > + } >> > > } >> > > >> > > public void bind(EjbJarInfo ejbJarInfo, BeanContext bean, >> > > EnterpriseBeanInfo beanInfo, JndiNameStrategy strategy) { >> > > @@ -350,7 +392,7 @@ public class JndiBuilder { >> > > String internalName = "openejb/Deployment/" + >> > > format(bean.getDeploymentID(), beanClass.getName(), >> > > InterfaceType.BUSINESS_LOCALBEAN_HOME); >> > > bind(internalName, ref, bindings, beanInfo, beanClass); >> > > >> > > - String name = strategy.getName(beanClass, >> > > JndiNameStrategy.Interface.LOCALBEAN); >> > > + String name = strategy.getName(beanClass, >> > > DEFAULT_NAME_KEY, JndiNameStrategy.Interface.LOCALBEAN); >> > > bind("openejb/local/" + name, ref, bindings, beanInfo, >> > > beanClass); >> > > bindJava(bean, beanClass, ref, bindings, beanInfo); >> > > >> > > @@ -375,7 +417,7 @@ public class JndiBuilder { >> > > String internalName = "openejb/Deployment/" + >> > > format(bean.getDeploymentID(), interfce.getName(), >> > > InterfaceType.BUSINESS_LOCAL); >> > > bind(internalName, ref, bindings, beanInfo, interfce); >> > > >> > > - String externalName = "openejb/local/" + >> > > strategy.getName(interfce, JndiNameStrategy.Interface.BUSINESS_LOCAL); >> > > + String externalName = "openejb/local/" + >> > > strategy.getName(interfce, DEFAULT_NAME_KEY, >> > > JndiNameStrategy.Interface.BUSINESS_LOCAL); >> > > bind(externalName, ref, bindings, beanInfo, interfce); >> > > bindJava(bean, interfce, ref, bindings, beanInfo); >> > > >> > > @@ -401,7 +443,7 @@ public class JndiBuilder { >> > > String internalName = "openejb/Deployment/" + >> > > format(bean.getDeploymentID(), interfce.getName(), >> > > InterfaceType.BUSINESS_REMOTE); >> > > bind(internalName, ref, bindings, beanInfo, interfce); >> > > >> > > - String name = strategy.getName(interfce, >> > > JndiNameStrategy.Interface.BUSINESS_REMOTE); >> > > + String name = strategy.getName(interfce, >> > DEFAULT_NAME_KEY, >> > > JndiNameStrategy.Interface.BUSINESS_REMOTE); >> > > bind("openejb/local/" + name, ref, bindings, beanInfo, >> > > interfce); >> > > bind("openejb/remote/" + name, ref, bindings, beanInfo, >> > > interfce); >> > > bindJava(bean, interfce, ref, bindings, beanInfo); >> > > @@ -418,7 +460,7 @@ public class JndiBuilder { >> > > >> > > ObjectReference ref = new >> > > ObjectReference(bean.getEJBLocalHome()); >> > > >> > > - String name = >> > > strategy.getName(bean.getLocalHomeInterface(), >> > > JndiNameStrategy.Interface.LOCAL_HOME); >> > > + String name = >> > > strategy.getName(bean.getLocalHomeInterface(), DEFAULT_NAME_KEY, >> > > JndiNameStrategy.Interface.LOCAL_HOME); >> > > bind("openejb/local/" + name, ref, bindings, beanInfo, >> > > localHomeInterface); >> > > >> > > optionalBind(bindings, ref, "openejb/Deployment/" + >> > > format(bean.getDeploymentID(), localHomeInterface.getName(), >> > > InterfaceType.EJB_LOCAL_HOME)); >> > > @@ -442,7 +484,7 @@ public class JndiBuilder { >> > > >> > > ObjectReference ref = new >> > > ObjectReference(bean.getEJBHome()); >> > > >> > > - String name = strategy.getName(homeInterface, >> > > JndiNameStrategy.Interface.REMOTE_HOME); >> > > + String name = strategy.getName(homeInterface, >> > > DEFAULT_NAME_KEY, JndiNameStrategy.Interface.REMOTE_HOME); >> > > bind("openejb/local/" + name, ref, bindings, beanInfo, >> > > homeInterface); >> > > bind("openejb/remote/" + name, ref, bindings, beanInfo, >> > > homeInterface); >> > > >> > > >> > > Modified: >> > > >> > >> openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/AbstractApplication.java >> > > URL: >> > > >> > >> http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/AbstractApplication.java?rev=1137242&r1=1137241&r2=1137242&view=diff >> > > >> > > >> > >> ============================================================================== >> > > --- >> > > >> > >> openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/AbstractApplication.java >> > > (original) >> > > +++ >> > > >> > >> openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/AbstractApplication.java >> > > Sat Jun 18 20:15:29 2011 >> > > @@ -36,6 +36,7 @@ import org.apache.openejb.assembler.clas >> > > import org.apache.openejb.assembler.classic.EnterpriseBeanInfo; >> > > import org.apache.openejb.assembler.classic.JndiBuilder; >> > > import >> > org.apache.openejb.assembler.classic.JndiBuilder.JndiNameStrategy; >> > > +import >> > > >> > >> org.apache.openejb.assembler.classic.JndiBuilder.JndiNameStrategy.Interface; >> > > import org.apache.openejb.loader.SystemInstance; >> > > import org.apache.openejb.util.LogCategory; >> > > import org.apache.openejb.util.Logger; >> > > @@ -120,7 +121,7 @@ public abstract class AbstractApplicatio >> > > if >> > (!applicationContext.containsBean(beanName)) >> > > { >> > > EJB ejb = entry.getValue(); >> > > >> > > applicationContext.getBeanFactory().registerSingleton(beanName, ejb); >> > > - logger.info("Exported EJB " + >> > > deployment.getEjbName() + " with interface " + >> > > entry.getValue().getInterface().getName() + " to Spring bean " + >> > > entry.getKey()); >> > > + logger.info("Exported EJB " + >> > > deployment.getEjbName() + " with interface " + >> > ejb.getInterface().getName() >> > > + " to Spring bean " + entry.getKey()); >> > > } >> > > } >> > > } >> > > @@ -142,25 +143,29 @@ public abstract class AbstractApplicatio >> > > >> > > Class remoteHome = deployment.getHomeInterface(); >> > > if (remoteHome != null) { >> > > - String externalName = strategy.getName(remoteHome, >> > > JndiNameStrategy.Interface.REMOTE_HOME); >> > > - bindings.put(externalName, new EJB(deployment, >> remoteHome)); >> > > + for (Map.Entry<String, String> entry : >> > > strategy.getNames(remoteHome, >> > > JndiNameStrategy.Interface.REMOTE_HOME).entrySet()) { >> > > + bindings.put(entry.getValue(), new EJB(deployment, >> > > remoteHome)); >> > > + } >> > > } >> > > >> > > >> > > Class localHome = deployment.getLocalHomeInterface(); >> > > if (localHome != null) { >> > > - String externalName = strategy.getName(localHome, >> > > JndiNameStrategy.Interface.LOCAL_HOME); >> > > - bindings.put(externalName, new EJB(deployment, >> remoteHome)); >> > > + for (Map.Entry<String, String> entry : >> > > strategy.getNames(localHome, Interface.LOCAL_HOME).entrySet()) { >> > > + bindings.put(entry.getValue(), new EJB(deployment, >> > > localHome)); >> > > + } >> > > } >> > > >> > > for (Class businessLocal : >> > deployment.getBusinessLocalInterfaces()) >> > > { >> > > - String externalName = strategy.getName(businessLocal, >> > > JndiNameStrategy.Interface.BUSINESS_LOCAL); >> > > - bindings.put(externalName, new EJB(deployment, >> > > businessLocal)); >> > > + for (Map.Entry<String, String> entry : >> > > strategy.getNames(businessLocal, Interface.BUSINESS_LOCAL).entrySet()) >> { >> > > + bindings.put(entry.getValue(), new EJB(deployment, >> > > businessLocal)); >> > > + } >> > > } >> > > >> > > for (Class businessRemote : >> > > deployment.getBusinessRemoteInterfaces()) { >> > > - String externalName = strategy.getName(businessRemote, >> > > JndiNameStrategy.Interface.BUSINESS_REMOTE); >> > > - bindings.put(externalName, new EJB(deployment, >> > > businessRemote)); >> > > + for (Map.Entry<String, String> entry : >> > > strategy.getNames(businessRemote, >> Interface.BUSINESS_REMOTE).entrySet()) >> > { >> > > + bindings.put(entry.getValue(), new EJB(deployment, >> > > businessRemote)); >> > > + } >> > > } >> > > >> > > // if >> > (MessageListener.class.equals(deployment.getMdbInterface())) >> > > { >> > > >> > > Modified: >> > > >> > >> openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/EchoReverseBean.java >> > > URL: >> > > >> > >> http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/EchoReverseBean.java?rev=1137242&r1=1137241&r2=1137242&view=diff >> > > >> > > >> > >> ============================================================================== >> > > --- >> > > >> > >> openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/EchoReverseBean.java >> > > (original) >> > > +++ >> > > >> > >> openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/EchoReverseBean.java >> > > Sat Jun 18 20:15:29 2011 >> > > @@ -20,7 +20,7 @@ package org.apache.openejb.spring; >> > > import javax.ejb.EJB; >> > > >> > > public class EchoReverseBean { >> > > - @EJB >> > > + @EJB(name = "EchoBeanLocal") >> > > public Echo echo; >> > > >> > > public Echo getEcho() { >> > > >> > > >> > > >> > >> > >> > -- >> > Shawn >> > >> > > > > -- > Shawn
