You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by "Alban THOMAS (JIRA)" <ji...@apache.org> on 2017/10/04 11:03:02 UTC

[jira] [Resolved] (TOMEE-2130) Tomcat + OpenEJB embedded in JEE6 webapp : Injection data not found in JNDI context

     [ https://issues.apache.org/jira/browse/TOMEE-2130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alban THOMAS resolved TOMEE-2130.
---------------------------------
    Resolution: Information Provided

> Tomcat + OpenEJB embedded in JEE6 webapp : Injection data not found in JNDI context
> -----------------------------------------------------------------------------------
>
>                 Key: TOMEE-2130
>                 URL: https://issues.apache.org/jira/browse/TOMEE-2130
>             Project: TomEE
>          Issue Type: Bug
>    Affects Versions: 1.7.4
>         Environment: OpenEJB 4.7.4
> Tomcat 8.5.20
>            Reporter: Alban THOMAS
>            Priority: Minor
>         Attachments: Alban2.war, Alban.war
>
>
> I am building a java webapp with EJB 3.0 into Tomcat (not TomEE).
> OpenEJB is "manually" initialized at server startup.
> {code:java}
> Properties p = new Properties();
> p.put(Context.INITIALCONTEXTFACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
> p.setProperty("openejb.jndiname.format", "app/{ejbName}!{interfaceClass}");
> p.setProperty("openejb.deploymentId.format", "{ejbClass}");
> p.setProperty("openejb.deployments.classpath.ear", "false");
> p.setProperty("openejb.validation.skip", "true");
> InitialContext ic = new InitialContext(p);
> {code}
> My stateless beans have a javax.ejb.SessionContext variable with javax.annotation.Resource annotation :
> {code:java}
> @Stateless
> @TransactionManagement(TransactionManagementType.BEAN)
> @Local(AlbanBeanI.class)
> public class AlbanBean {
> 	@Resource
> 	private SessionContext albanSessionCtx;
> 	public void printContext() {
> 		System.out.println("AlbanBean::printContext() = " + albanSessionCtx);
> 	}
> }
> {code}
> Lookup on the bean JNDI name works fine, but it seems that the SessionContext variable is null because injection data is not found.
> Running this code :
> {code:java}
> try {
> 	Object bean = ic.lookup("app/AlbanBean!xALTH.AlbanBeanI");
> 	System.out.println("lookup app/AlbanBean!xALTH.AlbanBeanI returned " + bean);
> 	Method m = bean.getClass().getMethod("printContext");
> 	System.out.println("Method = " + m);
> 	m.invoke(bean);
> 	
> }
> catch(Exception e) {
> 	e.printStackTrace();
> }
> {code}
> Gives following output :
> {panel}
> lookup app/AlbanBean!xALTH.AlbanBeanI returned proxy=xALTH.AlbanBeanI;deployment=xALTH.AlbanBean;pk=null
> Method = public final void com.sun.proxy.$Proxy36.printContext()
> {color:red}04-Oct-2017 08:40:17.410 AVERTISSEMENT localhost-startStop-1 org.apache.openejb.InjectionProcessor.fillInjectionProperties Injection data not found in JNDI context: jndiName='comp/env/xALTH.AlbanBean/albanSessionCtx', target=xALTH.AlbanBean/albanSessionCtx{color}
> AlbanBean::printContext() = null
> {panel}
> This can be reproduced by deploying attached [^Alban.war] into Tomcat (codes run at Tomcat startup).
> After intensive debug into OpenEJB and Catalina classes , it seems to me that the InjectionProcessor tries to resolve a org.apache.openejb.core.ivm.naming.JndiUrlReference for this injection, whose JNDI name is java:comp/EJBContext.
> Unfortunately, lookup on this name on a new InitialContext() throws a NameNotFoundException.
> I noticed that I did not had the same issue within TomEE, the difference beeing that java:comp/EJBContext on a new InitialContext is found.
> Going deeper into the lookup, I found that org.apache.naming.ContextBindings::isThreadBound() return true in that context, while it returns false into my Tomcat test case.
> This leads to do the lookups on different BoundContext instances, respectively org.apache.tomee.catalina.OpenEJBContext versus org.apache.naming.NamingContext
> I figured out that the difference is linked to org.apache.tomee.cataligna.TomcatLoader::initialize(), which is adding a TomEE specific listener on org.apache.openejb.core.ThreadContext
> If execute this code line after initializing OpenEJB, the issue is somehow "solved" :
> {code:java}
> ThreadContext.addThreadContextListener(new TomcatThreadContextListener());
> {code}
> This can be reproduced by deploying attached [^Alban2.war]
> albanSessionCtx instance is now correctly valorized by injection (no Injection data warning by the way)
> {panel}
> lookup app/AlbanBean!xALTH.AlbanBeanI returned proxy=xALTH.AlbanBeanI;deployment=xALTH.AlbanBean;pk=null
> Method = public final void com.sun.proxy.$Proxy36.printContext()
> AlbanBean::printContext() = org.apache.openejb.core.stateless.StatelessContext@35bff8af
> {panel}
> I dont think that injection should need that in order to work. It leads me to add some tomee-catalina.jar into my dependencies, which I dont want. So I certainly am willing to admit that I do miss something.
> Any suggestions/ideas appreciated.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)