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 "]")