You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Zog <jo...@gmail.com> on 2008/10/08 19:37:31 UTC

JNDI lookup in Tomcat

Hi
I installed the openejb.war in tomcat-6.0.18 and my ear as a collapsed ear.
When I lookup objects in the JNDI tree, I realized that I can freely look up
injected resources (I use the <resource-ref> in ejb-jar.xml for ex for data
sources),
but non injected are failing - is this normal ?
Specifically, one of my ejb is doing
InitialContext ic = new InitialContext(); // Properly initialized with the
OpenEJB ICfactory
ic.lookup("openejb/TransactionManager");
and this always throws a NameNotFoundException.

If I start OpenEJB standalone and connect through telnet, I can see
the transactionmanager using the lookup command.
Is this the expected behavior for the Tomcat integration ?

Thanks
           /zog
-- 
View this message in context: http://www.nabble.com/JNDI-lookup-in-Tomcat-tp19883726p19883726.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JNDI lookup in Tomcat

Posted by JensToerber <je...@juwimm.com>.
Hi David,

i don't think it's critical.

My/our situation is like this. We have a running application on JBoss 4.2
which does not support @EJB in Web-Tier.
Now JBoss 5 is out and it should work there.
To migrate our application on Tomcat and/or to use @EJB in Web-Tier we would
have to put a little work on it. If you use a ServiceLocator-Pattern this
should not be to critical. We use currently Spring with
JndiObjectFactoryBean and hence would only have to change one xml file.

I guess one intention for EJB3 is to be able to migrate an existing EJB2.1
application with Web-Tier to an EJB3 application with Web-Tier with not too
much effort. Then it would be comfortable to not have to take care of
different JNDI-Lookups. But as already said, if you have a ServiceLocator,
this should not be too much effort. Currently i have the following in my
managed JSF-Beans:

@EJB (beanName="AccommodationDao") 
AccommodationDaoLocal accommodationDaoLocal;
	public SearchBean() {
		if (this.accommodationDaoLocal == null) {
			this.accommodationDaoLocal =
ServiceLocator.getInstance().getAccommodationDaoLocal();

, which then works for JBoss 4.2 and any EJB3-conform-Container. Not very
beautiful, but it works. The only problem may be to detect where i am in
Openejb-JUnit-Test, in Tomcat 6.x.x with Openejb or in JBoss. My trick
currently is:

public static boolean isInJBoss() {
		String value = System.getProperty("jboss.bind.address");
		boolean inJBoss = !StringUtils.isEmpty(value);
		
		System.out.println("inJBoss: " + inJBoss);
		
		return inJBoss;
	}
	
	@SuppressWarnings("unchecked")
	public static boolean isInTomcat() {
		boolean inTomcat = false;
		Properties p = System.getProperties();
		
		if (p != null) {
			Enumeration keys = p.keys();
			
			if (keys != null) {
				while (keys.hasMoreElements()) {
					String key = (String)keys.nextElement();
					
					if (key.equals("catalina.base") || key.equals("catalina.home") ||
key.equals("tomcat.version")) {
						inTomcat = true;
						break;
					}
				}
			}
		}
		
		System.out.println("inTomcat: " + inTomcat);
		
		return inTomcat;
	}

Not very beautiful, but currently enough. If you have a better idea, would
be great to here about that. The problems are the unmanaged classes that as
far as i know are not able to get something injected. But even there with a
bit refactoring it should be easy to get the injection in a managed class
and pass that reference to an unmanaged class.

Best regards,

JT


Zog wrote:
> 
> Hi
> I installed the openejb.war in tomcat-6.0.18 and my ear as a collapsed
> ear.
> When I lookup objects in the JNDI tree, I realized that I can freely look
> up
> injected resources (I use the <resource-ref> in ejb-jar.xml for ex for
> data sources),
> but non injected are failing - is this normal ?
> Specifically, one of my ejb is doing
> InitialContext ic = new InitialContext(); // Properly initialized with the
> OpenEJB ICfactory
> ic.lookup("openejb/TransactionManager");
> and this always throws a NameNotFoundException.
> 
> If I start OpenEJB standalone and connect through telnet, I can see
> the transactionmanager using the lookup command.
> Is this the expected behavior for the Tomcat integration ?
> 
> Thanks
>            /zog
> 

-- 
View this message in context: http://www.nabble.com/JNDI-lookup-in-Tomcat-tp19883726p21553157.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JNDI lookup in Tomcat

Posted by Zog <jo...@gmail.com>.
On my side, I was specifically interested in looking up the transaction
manager from JNDI,
so if you could add 'openejb/TransactionManager' and
'openejb/UserTransaction' and map them to the proper instances, that would
have been great.


David Blevins wrote:
> 
> Hi Guys,
> 
> We don't currently expose the full internal JNDI tree via the  
> LocalInitialContextFactory.  Basically the LocalInitialContextFactory  
> and the RemoteInitialContextFactory are designed to be identical with  
> the exception that the RemoteInitialContextFactory doesn't have local  
> interface objects in it.  They both serve ejbs only.
> 
> We can certainly hook up more functionality to get at the internal  
> JNDI tree.  What entries do you need specifically?
> 
> -David
> 
> On Jan 9, 2009, at 4:51 PM, JensToerber wrote:
> 
>>
>> Hi,
>>
>> i can confirm this behaviour. Is it really the intention to use
>> org.apache.openejb.client.LocalInitialContextFactory. I thought this  
>> is only
>> for standalone local testing.
>>
>> Any news about looking from Web-Tier via IntialContext()?
>>
>> Best regards,
>>
>> Jens
>>
>> Zog wrote:
>>>
>>> In a servlet listener for my webapp, I'm using this:
>>>
>>>    public void contextInitialized(ServletContextEvent aArg0)
>>>    {
>>>        System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>>>            "org.apache.openejb.client.LocalInitialContextFactory");
>>>        System.err.println(">>>>>>> FULL JNDI TREE FROM STARTUP");
>>>        try {
>>>            InitialContext ic = new InitialContext();
>>>            listContext("",ic);
>>>        } catch (NamingException e) {
>>>            System.err.println("Could not list tree."+e);
>>>        }
>>>        System.err.println("<<<<<<< FULL JNDI TREE FROM STARTUP");
>>>    }
>>>
>>>    private static final void listContext(String s, Context c) throws
>>> NamingException
>>>    {
>>>        NamingEnumeration<NameClassPair> pairs = c.list("");
>>>        for (; pairs.hasMoreElements();)
>>>        {
>>>            NameClassPair p = pairs.next();
>>>            System.err.println(s+"/"+p.getName() + " " +
>>> p.getClassName());
>>>            Object o = c.lookup(p.getName());
>>>            if (o instanceof Context)
>>>            {
>>>                Context child = (Context) o;
>>>                listContext(s+"/"+p.getName(), child);
>>>            }
>>>        }
>>>    }
>>>
>>> And here's what I get:
>>> /. java.lang.String
>>> /openejb org.apache.openejb.core.ivm.naming.IvmContext
>>> /openejb/ConfigurationInfoBusinessRemote
>>> org.apache.openejb.core.ivm.naming.Busi
>>> nessRemoteReference
>>> /openejb/DeployerBusinessRemote
>>> org.apache.openejb.core.ivm.naming.BusinessRemot
>>> eReference
>>> ...and then other contexts created by my MDB/SB.
>>>
>>> I don't see any /openejb/TransactionManager there.
>>>
>>>        /Zog
>>>
>>>
>>> David Blevins wrote:
>>>>
>>>>
>>>> On Oct 8, 2008, at 12:37 PM, Zog wrote:
>>>>
>>>>> I installed the openejb.war in tomcat-6.0.18 and my ear as a
>>>>> collapsed ear.
>>>>> When I lookup objects in the JNDI tree, I realized that I can  
>>>>> freely
>>>>> look up
>>>>> injected resources (I use the <resource-ref> in ejb-jar.xml for ex
>>>>> for data
>>>>> sources),
>>>>> but non injected are failing - is this normal ?
>>>>> Specifically, one of my ejb is doing
>>>>> InitialContext ic = new InitialContext(); // Properly initialized
>>>>> with the
>>>>> OpenEJB ICfactory
>>>>> ic.lookup("openejb/TransactionManager");
>>>>> and this always throws a NameNotFoundException.
>>>>
>>>> Hmm.  If it was created with the LocalInitialContextFactory as so..
>>>>
>>>>  Properties properties = new Properties();
>>>>  properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>>>> "org.apache.openejb.client.LocalInitialContextFactory");
>>>>
>>>>  InitialContext initialContext = new InitialContext(properties);
>>>>
>>>> Then it should definitely work.  If it was done as so...
>>>>
>>>>  InitialContext initialContext = new InitialContext();
>>>>
>>>> Then I'm not as confident that it will work.  We have code in the
>>>> integration to add the "openejb" subcontext into the webapp's jndi
>>>> context, or so I thought.  I added code along these lines, but it's
>>>> been while and I can't recall the details.  Maybe in this second  
>>>> case
>>>> you have to lookup "java:openejb/TransactionManager".
>>>>
>>>> Can you verify which technique you are using?
>>>>
>>>>
>>>> -David
>>>>
>>>>
>>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/JNDI-lookup-in-Tomcat-tp19883726p21383331.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/JNDI-lookup-in-Tomcat-tp19883726p21562354.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JNDI lookup in Tomcat

Posted by David Blevins <da...@visi.com>.
Hi Guys,

We don't currently expose the full internal JNDI tree via the  
LocalInitialContextFactory.  Basically the LocalInitialContextFactory  
and the RemoteInitialContextFactory are designed to be identical with  
the exception that the RemoteInitialContextFactory doesn't have local  
interface objects in it.  They both serve ejbs only.

We can certainly hook up more functionality to get at the internal  
JNDI tree.  What entries do you need specifically?

-David

On Jan 9, 2009, at 4:51 PM, JensToerber wrote:

>
> Hi,
>
> i can confirm this behaviour. Is it really the intention to use
> org.apache.openejb.client.LocalInitialContextFactory. I thought this  
> is only
> for standalone local testing.
>
> Any news about looking from Web-Tier via IntialContext()?
>
> Best regards,
>
> Jens
>
> Zog wrote:
>>
>> In a servlet listener for my webapp, I'm using this:
>>
>>    public void contextInitialized(ServletContextEvent aArg0)
>>    {
>>        System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>>            "org.apache.openejb.client.LocalInitialContextFactory");
>>        System.err.println(">>>>>>> FULL JNDI TREE FROM STARTUP");
>>        try {
>>            InitialContext ic = new InitialContext();
>>            listContext("",ic);
>>        } catch (NamingException e) {
>>            System.err.println("Could not list tree."+e);
>>        }
>>        System.err.println("<<<<<<< FULL JNDI TREE FROM STARTUP");
>>    }
>>
>>    private static final void listContext(String s, Context c) throws
>> NamingException
>>    {
>>        NamingEnumeration<NameClassPair> pairs = c.list("");
>>        for (; pairs.hasMoreElements();)
>>        {
>>            NameClassPair p = pairs.next();
>>            System.err.println(s+"/"+p.getName() + " " +
>> p.getClassName());
>>            Object o = c.lookup(p.getName());
>>            if (o instanceof Context)
>>            {
>>                Context child = (Context) o;
>>                listContext(s+"/"+p.getName(), child);
>>            }
>>        }
>>    }
>>
>> And here's what I get:
>> /. java.lang.String
>> /openejb org.apache.openejb.core.ivm.naming.IvmContext
>> /openejb/ConfigurationInfoBusinessRemote
>> org.apache.openejb.core.ivm.naming.Busi
>> nessRemoteReference
>> /openejb/DeployerBusinessRemote
>> org.apache.openejb.core.ivm.naming.BusinessRemot
>> eReference
>> ...and then other contexts created by my MDB/SB.
>>
>> I don't see any /openejb/TransactionManager there.
>>
>>        /Zog
>>
>>
>> David Blevins wrote:
>>>
>>>
>>> On Oct 8, 2008, at 12:37 PM, Zog wrote:
>>>
>>>> I installed the openejb.war in tomcat-6.0.18 and my ear as a
>>>> collapsed ear.
>>>> When I lookup objects in the JNDI tree, I realized that I can  
>>>> freely
>>>> look up
>>>> injected resources (I use the <resource-ref> in ejb-jar.xml for ex
>>>> for data
>>>> sources),
>>>> but non injected are failing - is this normal ?
>>>> Specifically, one of my ejb is doing
>>>> InitialContext ic = new InitialContext(); // Properly initialized
>>>> with the
>>>> OpenEJB ICfactory
>>>> ic.lookup("openejb/TransactionManager");
>>>> and this always throws a NameNotFoundException.
>>>
>>> Hmm.  If it was created with the LocalInitialContextFactory as so..
>>>
>>>  Properties properties = new Properties();
>>>  properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>>> "org.apache.openejb.client.LocalInitialContextFactory");
>>>
>>>  InitialContext initialContext = new InitialContext(properties);
>>>
>>> Then it should definitely work.  If it was done as so...
>>>
>>>  InitialContext initialContext = new InitialContext();
>>>
>>> Then I'm not as confident that it will work.  We have code in the
>>> integration to add the "openejb" subcontext into the webapp's jndi
>>> context, or so I thought.  I added code along these lines, but it's
>>> been while and I can't recall the details.  Maybe in this second  
>>> case
>>> you have to lookup "java:openejb/TransactionManager".
>>>
>>> Can you verify which technique you are using?
>>>
>>>
>>> -David
>>>
>>>
>>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/JNDI-lookup-in-Tomcat-tp19883726p21383331.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>


Re: JNDI lookup in Tomcat

Posted by JensToerber <je...@juwimm.com>.
Hi,

i can confirm this behaviour. Is it really the intention to use
org.apache.openejb.client.LocalInitialContextFactory. I thought this is only
for standalone local testing.

Any news about looking from Web-Tier via IntialContext()?

Best regards,

Jens

Zog wrote:
> 
> In a servlet listener for my webapp, I'm using this:
> 
>     public void contextInitialized(ServletContextEvent aArg0)
>     {
>         System.setProperty(Context.INITIAL_CONTEXT_FACTORY,   
>             "org.apache.openejb.client.LocalInitialContextFactory");
>         System.err.println(">>>>>>> FULL JNDI TREE FROM STARTUP");
>         try {
>             InitialContext ic = new InitialContext();
>             listContext("",ic);
>         } catch (NamingException e) {
>             System.err.println("Could not list tree."+e);            
>         }
>         System.err.println("<<<<<<< FULL JNDI TREE FROM STARTUP");                
>     }
> 
>     private static final void listContext(String s, Context c) throws
> NamingException
>     {
>         NamingEnumeration<NameClassPair> pairs = c.list("");
>         for (; pairs.hasMoreElements();)
>         {
>             NameClassPair p = pairs.next();
>             System.err.println(s+"/"+p.getName() + " " +
> p.getClassName());
>             Object o = c.lookup(p.getName());
>             if (o instanceof Context)
>             {
>                 Context child = (Context) o; 
>                 listContext(s+"/"+p.getName(), child);
>             }
>         }
>     }
> 
> And here's what I get:
> /. java.lang.String
> /openejb org.apache.openejb.core.ivm.naming.IvmContext
> /openejb/ConfigurationInfoBusinessRemote
> org.apache.openejb.core.ivm.naming.Busi
> nessRemoteReference
> /openejb/DeployerBusinessRemote
> org.apache.openejb.core.ivm.naming.BusinessRemot
> eReference
> ...and then other contexts created by my MDB/SB.
> 
> I don't see any /openejb/TransactionManager there.
> 
>         /Zog
> 
> 
> David Blevins wrote:
>> 
>> 
>> On Oct 8, 2008, at 12:37 PM, Zog wrote:
>> 
>>> I installed the openejb.war in tomcat-6.0.18 and my ear as a  
>>> collapsed ear.
>>> When I lookup objects in the JNDI tree, I realized that I can freely  
>>> look up
>>> injected resources (I use the <resource-ref> in ejb-jar.xml for ex  
>>> for data
>>> sources),
>>> but non injected are failing - is this normal ?
>>> Specifically, one of my ejb is doing
>>> InitialContext ic = new InitialContext(); // Properly initialized  
>>> with the
>>> OpenEJB ICfactory
>>> ic.lookup("openejb/TransactionManager");
>>> and this always throws a NameNotFoundException.
>> 
>> Hmm.  If it was created with the LocalInitialContextFactory as so..
>> 
>>   Properties properties = new Properties();
>>   properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,  
>> "org.apache.openejb.client.LocalInitialContextFactory");
>> 
>>   InitialContext initialContext = new InitialContext(properties);
>> 
>> Then it should definitely work.  If it was done as so...
>> 
>>   InitialContext initialContext = new InitialContext();
>> 
>> Then I'm not as confident that it will work.  We have code in the  
>> integration to add the "openejb" subcontext into the webapp's jndi  
>> context, or so I thought.  I added code along these lines, but it's  
>> been while and I can't recall the details.  Maybe in this second case  
>> you have to lookup "java:openejb/TransactionManager".
>> 
>> Can you verify which technique you are using?
>> 
>> 
>> -David
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/JNDI-lookup-in-Tomcat-tp19883726p21383331.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JNDI lookup in Tomcat

Posted by Zog <jo...@gmail.com>.
In a servlet listener for my webapp, I'm using this:

    public void contextInitialized(ServletContextEvent aArg0)
    {
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY,   
            "org.apache.openejb.client.LocalInitialContextFactory");
        System.err.println(">>>>>>> FULL JNDI TREE FROM STARTUP");
        try {
            InitialContext ic = new InitialContext();
            listContext("",ic);
        } catch (NamingException e) {
            System.err.println("Could not list tree."+e);            
        }
        System.err.println("<<<<<<< FULL JNDI TREE FROM STARTUP");                
    }

    private static final void listContext(String s, Context c) throws
NamingException
    {
        NamingEnumeration<NameClassPair> pairs = c.list("");
        for (; pairs.hasMoreElements();)
        {
            NameClassPair p = pairs.next();
            System.err.println(s+"/"+p.getName() + " " + p.getClassName());
            Object o = c.lookup(p.getName());
            if (o instanceof Context)
            {
                Context child = (Context) o; 
                listContext(s+"/"+p.getName(), child);
            }
        }
    }

And here's what I get:
/. java.lang.String
/openejb org.apache.openejb.core.ivm.naming.IvmContext
/openejb/ConfigurationInfoBusinessRemote
org.apache.openejb.core.ivm.naming.Busi
nessRemoteReference
/openejb/DeployerBusinessRemote
org.apache.openejb.core.ivm.naming.BusinessRemot
eReference
...and then other contexts created by my MDB/SB.

I don't see any /openejb/TransactionManager there.

        /Zog


David Blevins wrote:
> 
> 
> On Oct 8, 2008, at 12:37 PM, Zog wrote:
> 
>> I installed the openejb.war in tomcat-6.0.18 and my ear as a  
>> collapsed ear.
>> When I lookup objects in the JNDI tree, I realized that I can freely  
>> look up
>> injected resources (I use the <resource-ref> in ejb-jar.xml for ex  
>> for data
>> sources),
>> but non injected are failing - is this normal ?
>> Specifically, one of my ejb is doing
>> InitialContext ic = new InitialContext(); // Properly initialized  
>> with the
>> OpenEJB ICfactory
>> ic.lookup("openejb/TransactionManager");
>> and this always throws a NameNotFoundException.
> 
> Hmm.  If it was created with the LocalInitialContextFactory as so..
> 
>   Properties properties = new Properties();
>   properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
> 
>   InitialContext initialContext = new InitialContext(properties);
> 
> Then it should definitely work.  If it was done as so...
> 
>   InitialContext initialContext = new InitialContext();
> 
> Then I'm not as confident that it will work.  We have code in the  
> integration to add the "openejb" subcontext into the webapp's jndi  
> context, or so I thought.  I added code along these lines, but it's  
> been while and I can't recall the details.  Maybe in this second case  
> you have to lookup "java:openejb/TransactionManager".
> 
> Can you verify which technique you are using?
> 
> 
> -David
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/JNDI-lookup-in-Tomcat-tp19883726p19898308.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JNDI lookup in Tomcat

Posted by David Blevins <da...@visi.com>.
On Oct 8, 2008, at 12:37 PM, Zog wrote:

> I installed the openejb.war in tomcat-6.0.18 and my ear as a  
> collapsed ear.
> When I lookup objects in the JNDI tree, I realized that I can freely  
> look up
> injected resources (I use the <resource-ref> in ejb-jar.xml for ex  
> for data
> sources),
> but non injected are failing - is this normal ?
> Specifically, one of my ejb is doing
> InitialContext ic = new InitialContext(); // Properly initialized  
> with the
> OpenEJB ICfactory
> ic.lookup("openejb/TransactionManager");
> and this always throws a NameNotFoundException.

Hmm.  If it was created with the LocalInitialContextFactory as so..

  Properties properties = new Properties();
  properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");

  InitialContext initialContext = new InitialContext(properties);

Then it should definitely work.  If it was done as so...

  InitialContext initialContext = new InitialContext();

Then I'm not as confident that it will work.  We have code in the  
integration to add the "openejb" subcontext into the webapp's jndi  
context, or so I thought.  I added code along these lines, but it's  
been while and I can't recall the details.  Maybe in this second case  
you have to lookup "java:openejb/TransactionManager".

Can you verify which technique you are using?


-David