Well, we just changed the code in that particular EJB to do the lookup 
without
the "java:comp/env/" namespace and it works fine.  But what is strange is 
that
it works from the JSP side, but not from within an EJB. 

The main advantage, FYI, that I've seen of the ejb-refs is that it keeps 
everything
within the .ear file.  In other words, without them, we'd be copying .jar 
files into
common "lib" folders of the appserver or explicitly adding in the .jar 
files onto the
classpath.  (So the app server could "see" them)

Mainly just wondering why it works just fine in one circumstance, but not 
in the
other.

Robert




"Mark Phelps" <[EMAIL PROTECTED]>
04/12/2001 12:25 PM
Please respond to jrun-talk

 
        To:     JRun-Talk <[EMAIL PROTECTED]>
        cc: 
        Subject:        RE: java:comp/env/ To be or not to be?


I am not an expert on ejb-ref and why you would use it in web.xml or
ejb-jar.xml.  As I understand it the benefit is to make it easy to change
the bean information at deploy time without recompiling. We have never
needed to do that.

We do access EJBs easily from JSPs and from other EJBs, however.  The code
sample shown below is an example of how we do it.  We always use the 
bean's
home name, which is the classname of the implementation class by default.

This code assumes an EJB with MySampleBean as the implementation class,
MySampleHome as the home interface, and MySample as the remote interface.

        System.setSecurityManager( new RMISecurityManager() );

        /** The properties that will be used to build m_ctx. */
        Properties props = new Properties();

        /** The InitialContext which will be used when talking to the JNDI
server. */
        props.setProperty( "java.naming.factory.initial",
"allaire.ejipt.ContextFactory" );
        props.setProperty( "java.naming.provider.url",
"ejipt://127.0.0.1:2323" );

        InitialContext ctx =  new InitialContext(props);

                   MySampleHome home = 
(MySampleHome)ctx.lookup("MySampleBean");
                   MySample bean = (MySample)home.create();

The important parts are the declaration of properties as shown, and the
setting of the RMISecurityManager. This code works in JSP and in an EJB. 
We
have no ejb-ref tags in our web.xml or ejb-jar.xml files. We never use
"java:comp/env/" in any of our lookups.

If this code doesn't work, check your bean's home name in the JMC to see 
if
it has been set to something different.

I hope this helps.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 12, 2001 11:38 AM
To: JRun-Talk
Subject: java:comp/env/ To be or not to be?


In my web.xml descriptor, I have an ejb-ref for one of my jsp/servlets.
When that jsp
does a lookup on the EJB, it finds it just fine.

In my ejb-jar.xml descriptor, I have a similar ejb-ref from EJB to EJB
(exact in all ways
except I'm making a reference to a totally different bean).

>From the "web" side of things, using the java:comp/env/ prefix to do the
lookup for
the reference in my web.xml file works just fine (appending the JNDI name
of the EJB
of course).

>From the "ejb" side of things, using that same prefix and the JNDI name 
of
the EJB
fails.  Why?

I'm getting an initial context in exactly the same way in both cases.  Can
someone
shed some light on this?

Robert
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to