File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes New to EJB, advice please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "New to EJB, advice please" Watch "New to EJB, advice please" New topic
Author

New to EJB, advice please

Blikkies Marais
Ranch Hand

Joined: Jun 12, 2003
Posts: 50
Hi,

I am new to EJB, so please can someone help. I am trying to access a stateless session EJB from a class but am having some problems. I am using Rational Application Developer 6 with Websphere Application Server 6.

I have been trying a number of different ways to do a JNDI lookup on the session EJB. Whic I will give examples of below. I am using a class with a main method to test this. I have an EJB Project that contins a session EJB called "Manager". Then I have a Web Project that has a class with a main method which is trying to access the EJB in the EJB Project.

I have 'Run Validation' over the EJB project successfully. I then did a 'Deploy' over the EJB Project.I have modified the Web Projects web.xml file to contain the Manager EJB (see below). I make sure the WAS6 server is running. Then I invoke the test class with the main method:


(1) When I try the following:
<pre>

Properties prop = new Properties();
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
prop.setProperty(Context.PROVIDER_URL, "iiop://localhost:2809/");
javax.naming.InitialContext ctx = new InitialContext(prop);
Object obj = ctx.lookup("cell/nodes/localhost/servers/server1/ejb/Manager");
ManagerHome ejbHome = (ManagerHome)
PortableRemoteObject.narrow(obj,ManagerHome.class);

</pre>

I get the folowing Exception:

<pre>
javax.naming.NameNotFoundException: Context: your-ky2idxv32cNode01Cell/nodes/your-ky2idxv32cNode01/servers/server1, name: cell/nodes/localhost/servers/server1/ejb/Manager: First component in name localhost/servers/server1/ejb/Manager not found. Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL mg.org/CosNaming/NamingContext/NotFound:1.0
at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:85)
at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve_complete_info(Unknown Source)
at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:4045)
....

</pre>

(2) When I try:
<pre>

Properties prop = new Properties();
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
prop.setProperty(Context.PROVIDER_URL, "iiop://localhost:2809/");
javax.naming.InitialContext ctx = new InitialContext(prop);
Object obj = ctx.lookup("java:comp/env/ejb/org/omg/stub/javax/ejb/manager/ManagerHome");
ManagerHome ejbHome = (ManagerHome)
PortableRemoteObject.narrow(obj,ManagerHome.class);
</pre>

I get the following Exception:
<pre>

06-Aug-2005 10:48:05 com.ibm.ws.naming.java.javaURLContextFactory
SEVERE: javaAccessorNotSet
javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
at com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:98)
at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:73)
at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:592)
....
</pre>

(3) When I try:
<pre>

Object obj = ctx.lookup("java:comp/env/ejb/Manager");
or:
Object obj = ctx.lookup("java:comp/env/ejb/org/omg/stub/javax/ejb/manager/Manager");
or:
Object obj = ctx.lookup("java:comp/env/ejb/manager/Manager");
or:
Object obj = ctx.lookup("java:comp/env/ejb/manager/ManagerHome");
or:
Object obj = ctx.lookup("java:comp/env/ejb/ManagerHome");

I have also tried all of the above without setting the the properties in the InitialContext() constructor.

javax.naming.InitialContext ctx = new InitialContext();

</pre>

I get the same Exception:

<pre>
06-Aug-2005 10:50:42 com.ibm.ws.naming.java.javaURLContextFactory
SEVERE: javaAccessorNotSet
javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
at com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:98)
at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:73)
at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:592)


</pre>

My ejb-jar.xml in the EJB Project is the following:

<pre>
[?xml version="1.0" encoding="UTF-8"?]
[ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"]
[display-name]MyProjectEJB[/display-name]
[enterprise-beans]
[entity id="Album"]
[ejb-name]Album[/ejb-name]
[home]org.omg.stub.javax.ejb.album.AlbumHome[/home]
[remote]org.omg.stub.javax.ejb.album.Album[/remote]
[local-home]org.omg.stub.javax.ejb.album.AlbumLocalHome[/local-home]
[local]org.omg.stub.javax.ejb.album.AlbumLocal[/local]
[ejb-class]org.omg.stub.javax.ejb.album.AlbumBean[/ejb-class]
[persistence-type]Container[/persistence-type]
[prim-key-class]java.lang.Integer[/prim-key-class]
[reentrant]false[/reentrant]
[cmp-version]2.x[/cmp-version]
[abstract-schema-name]Album[/abstract-schema-name]
[cmp-field id="CMPAttribute_1122977976160"]
[field-name]id[/field-name]
[/cmp-field]
[cmp-field id="CMPAttribute_1122977967979"]
[field-name]title[/field-name]
[/cmp-field]
[cmp-field id="CMPAttribute_1122977968069"]
[field-name]artist[/field-name]
[/cmp-field]
[primkey-field]id[/primkey-field]
[ejb-local-ref id="EJBLocalRef_1123062875138"]
[description]
[/description]
[ejb-ref-name]ejb/Album[/ejb-ref-name]
[ejb-ref-type]Entity[/ejb-ref-type]
[local-home]org.omg.stub.javax.ejb.album.AlbumLocalHome[/local-home]
[local]org.omg.stub.javax.ejb.album.AlbumLocal[/local]
[ejb-link]Album[/ejb-link]
[/ejb-local-ref]
[/entity]
[entity id="Track"]
[ejb-name]Track[/ejb-name]
[home]org.omg.stub.javax.ejb.track.TrackHome[/home]
[remote]org.omg.stub.javax.ejb.track.Track[/remote]
[local-home]org.omg.stub.javax.ejb.track.TrackLocalHome[/local-home]
[local]org.omg.stub.javax.ejb.track.TrackLocal[/local]
[ejb-class]org.omg.stub.javax.ejb.track.TrackBean[/ejb-class]
[persistence-type]Container[/persistence-type]
[prim-key-class]java.lang.Integer[/prim-key-class]
[reentrant]false[/reentrant]
[cmp-version]2.x[/cmp-version]
[abstract-schema-name]Track[/abstract-schema-name]
[cmp-field id="CMPAttribute_1122978061723"]
[field-name]id[/field-name]
[/cmp-field]
[cmp-field id="CMPAttribute_1122978061743"]
[field-name]fkalbumid[/field-name]
[/cmp-field]
[cmp-field id="CMPAttribute_1122978061783"]
[field-name]song[/field-name]
[/cmp-field]
[primkey-field]id[/primkey-field]
[ejb-local-ref id="EJBLocalRef_1123062875148"]
[description]
[/description]
[ejb-ref-name]ejb/Track[/ejb-ref-name]
[ejb-ref-type]Entity[/ejb-ref-type]
[local-home]org.omg.stub.javax.ejb.track.TrackLocalHome[/local-home]
[local]org.omg.stub.javax.ejb.track.TrackLocal[/local]
[ejb-link]Track[/ejb-link]
[/ejb-local-ref]
[/entity]
[session id="Manager"]
[ejb-name]Manager[/ejb-name]
[home]org.omg.stub.javax.ejb.manager.ManagerHome[/home]
[remote]org.omg.stub.javax.ejb.manager.Manager[/remote]
[local-home]org.omg.stub.javax.ejb.manager.ManagerLocalHome[/local-home]
[local]org.omg.stub.javax.ejb.manager.ManagerLocal[/local]
[service-endpoint]org.omg.stub.javax.ejb.manager.ManagerService[/service-endpoint]
[ejb-class]org.omg.stub.javax.ejb.manager.ManagerBean[/ejb-class]
[session-type]Stateless[/session-type]
[transaction-type]Container[/transaction-type]
[ejb-local-ref id="EJBLocalRef_1123065469238"]
[description]
[/description]
[ejb-ref-name]ejb/Manager[/ejb-ref-name]
[ejb-ref-type]Session[/ejb-ref-type]
[local-home]org.omg.stub.javax.ejb.manager.ManagerLocalHome[/local-home]
[local]org.omg.stub.javax.ejb.manager.ManagerLocal[/local]
[ejb-link]Manager[/ejb-link]
[/ejb-local-ref]
[/session]
[/enterprise-beans]
[/ejb-jar]
</pre>


My web.xml in the Web Project is the following:
<pre>

[?xml version="1.0" encoding="UTF-8"?]
[web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"]
[display-name]
MyProjectWeb[/display-name]
[welcome-file-list]
[welcome-file]index.html[/welcome-file]
[welcome-file]index.htm[/welcome-file]
[welcome-file]index.jsp[/welcome-file]
[welcome-file]default.html[/welcome-file]
[welcome-file]default.htm[/welcome-file]
[welcome-file]default.jsp[/welcome-file]
[/welcome-file-list]
[ejb-ref]
[ejb-ref-name]ejb/Manager[/ejb-ref-name]
[ejb-ref-type]Session[/ejb-ref-type]
[home]org.omg.stub.javax.ejb.manager.ManagerHome[/home]
[remote]org.omg.stub.javax.ejb.manager.Manager[/remote]
[/ejb-ref]
[/web-app]

</pre>


Please can some one give me some advice. Thanks

(Sorry that I have lost the xml tags when I pasted this here. I have tried to use escape characters, but they do not seem to work. I have replaced the "<" with "]")
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30531
    
150

Blikkies,
Are you using WSAD or WebSphere server? If WSAD, the easiest thing to do is test the EJB using the Universal Test Client. This will tell you whether the error is in the EJB configuration or your client code/configuration.

To get to the Universal Test Client, right click the server when it is running. Then just drill down to your bean.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Blikkies Marais
Ranch Hand

Joined: Jun 12, 2003
Posts: 50
Thansk Jeanne,

I am using IBM Rational Application Developer 6 with WebSphere 6 server.

Do you know how I can invoke the test client n this tool?
Blikkies Marais
Ranch Hand

Joined: Jun 12, 2003
Posts: 50
I managed to get the Universal Test Client to run my session EJB. But oly once I changed the 'Server Connection Type and Admin port' in the server overview from RMI(Better performance) to SOAP(More firewall compatable)? - I guess the firewall must have been affecting it. But it does not expln wht I could not do local lookups, but the client work now.

However, I cannot seem to invoke the session EJB from outside the client still. How do I testt what the JNDI name is?

In the Universal Test Clienrt, when I expand the JNDI Explorer, I can see my EJB there (Method visibility, create()). But how do I know what the JNDI names? (The name I should put in the ctx.lookup("xxx")?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30531
    
150

Blikkies,
You can't do local lookups from the client by default because it runs in a separate JVM. Note that the local and remote JNDI names are different. The local adds "local:ejb/" to the name. You can test the remote JNDI name by typing it into the Universal Test Client. To get it in the first place, you can see what is defined on your EJB in the J2EE perspective or see what the path is that you drilled down to in the Universal Test Client.

Note: I am not yet using RAD 6, so this procedure is for WSAD 5.1.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New to EJB, advice please