• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Ed Roman - Mastering EJB's

 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Ed Roman's book Mastering EJB's to learn EJB's and I have JBoss installed and working (I ran the template example just fine) but I can't get the client programs from his book to run. Firstly, I can't get an InitialContext using his examples, so I have to create an InitialContext by passing a HashMap that has all the properties set.
After doing this, my client programs will run, but I always get an error that the Home interface is not bound. I'm using the examples in Chapter 3 and 4 from his book.
Has anyone had any experience with this? If so, what were your solutions?
 
Jim Bedenbaugh
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, let me ask my question this way:
When I attempt to call my remote object from the client, I get a not bound exception. What does it take to get the remote bound to JNDI?
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, Hi, I was having very similar problems for ages and solved it through brute force.
I don't know the book your talking about, so the initial context code could be wrong AFAIK. The code I use is thus:
private static Properties props = null;
props = new Properties();
props.setProperty( "java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty( "java.naming.provider.url","localhost:1099");
props.setProperty( "java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
InitialContext jndiContext = new InitialContext( props );
And the code I use to retrieve an EJB from a remote client is thus:
Object ref = jndiContext.lookup( "java:"+jndiName );
System.out.println("EXTERNAL LOOKUP");
// Get a reference from this to the Bean's Home interface
return (EJBHome)PortableRemoteObject.narrow( ref, homeRefClass );
And the following is for retrieving an EJB from within another EJB hosted on the same EAP (JBoss in this case, of course):
Object ref = jndiContext.lookup( "java:comp/env/"+jndiName );
System.out.println("INTERNAL LOOKUP");
// Get a reference from this to the Bean's Home interface
return (EJBHome)PortableRemoteObject.narrow( ref, homeRefClass );
Please note that the jndiName variable above will be whatever was entered into the <jndi-name></jndi-name> tag for the first code block and whatever was entered into the <ejb-ref-name></ejb-ref-name> inside the ejb-jar.xml of the session bean's <ejb-ref></ejb-ref> block for the second code block above.
In brief, binding takes place with no amendment if you are a remote client, but the value 'comp/env/' is added for retrieval within beans.
And lastly, if you place a simple
jndi.properties
file, in the root directory within your output jar of the remote client, which contains the three lines from the Properties or hash object you are passing into the constructor of the InitialContext, you will no longer have to create that Properties or hash object.
If you are writing a servlet you will still have to pass in the Properties object because I haven't figured out where the servlet is supposed to read the jndi.properties file from. If anyone finds out I would love to know.
Good luck, hope that wasn't too congealed for you,
Best regards everyone,
Matt.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting, are you using XDoclet or anything like that?
I am doing just what you are, which version of jboss are you using? I have it working now.

as for the jndi stuff. I can bind from a remote client using ejb/beanName. Actually it just a seperate jvm on same computer.
but comp/env/ejb/beanName does not work. any idea why?
i posted same question in j2ee forum just a sec ago.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I got it licked.
The "recommended" practice is to use comp/env, so somehow I guess xdoclet is generating that. nevertheless the key is in the descriptor.
any "references" in your descriptor will require java:comp/env/xxx
so if you are accessing your object locally through a java:comp/env/ejb/xxx construct you must have something like this in your descriptor

you can still access the object through its remote JNDI name (even locally) which is "ejb/xxx". The only reason for the different local name I think is for some sort of portability which I have yet to discern.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I almost got it but i am a little confused. it seems as if he is saying references are good because it lets the deployer change the location of the object in jndi. maybe because references are in the ejb-jar file this is good since it is common. but of course jboss has its JNDI names in its own descriptor, so it seems all the same to me. I dont think I really need to use the comp/env area. Just dont see why.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I had a similar problem but setting the JNDI properties as suggested above got me half the way.
The other half of the solution was to stop using "ejb" at the beginning of the bean's JNDI name (got the "idea" from an example -- cut-and-paste strikes again...). Apparently JBoss didn't take this well.
I am using JBoss 3.0.3 and Tomcat 4.1.18-LE running in separate JVM's.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic