cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

JNDI InitialContext Error

Former Member
0 Likes
2,265

Hello Experts,

I have a little problem with my Java programm:

Test remote = null;

* try {*

// Create a new intial context, which loads from jndi.properties file.

* *

* Context ctx = new InitialContext();*

* System.out.println("Context:" + ctx);*

// Look up the home interface using the JNDI name.

// This JNDI lookup returns a reference to an EJBHome instance.

* TestHome home = (TestHome) ctx.lookup("sap.com/TestWorldEar/TestBean");*

* System.out.println("TestHome:" + home);*

// Create a session object.

* remote = home.create();*

* System.out.println("Remote:" + remote);*

// Invoke the remote EJB methods, test and debug.

* System.out.println("Result:" + remote.getWert());*

* } catch (Exception e) {*

* System.out.println("Exception: " + e.getLocalizedMessage());*

* }*

I always get the following error and I don't know how to solve the problem.

Exception: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

I hope anybody of you can help me solving this problem.

Additional information:

The Java program is running on a XI (Netweaver 7.0).

I want to get information from a deployed EJB. The Bean still works.

Thank you for your answers in advance!!!

Greetings, Alexander

View Entire Topic
Vlado
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Alexander,

Are you sure that your client app is running on the same server instance as the EJB? You don't pass any properties to the new InitialContext(), neither can I get where you expect the jndi.properties file to be loaded from.

Regards,

\-- Vladimir

P.S.: Moving to the AS Java forum since this question is about NetWeaver 7.0.

Edited by: Vladimir Pavlov on Aug 8, 2008 4:03 PM

Former Member
0 Likes

Hi Vladimir,

yes I am sure the client app is runing on the same server as the ejb. I have deployed both within the same package.

I also get a value at this point:

  • *

  • Context ctx = new InitialContext();*

  • System.out.println("Context:" + ctx);*

The value is: Context:javax.naming.InitialContext@cdfc9c

My problem first starts here:

// Look up the home interface using the JNDI name.

// This JNDI lookup returns a reference to an EJBHome instance.

  • TestHome home = (TestHome) ctx.lookup("sap.com/TestWorldEar/TestBean");*

  • System.out.println("TestHome:" + home);*

I think I do not have the right path to the Bean but I don't know.

Greetings, Alexander

Vlado
Product and Topic Expert
Product and Topic Expert
0 Likes

OK, so you pass through the new InitialContext. Do you get now a NameNotFoundException or what?

If so, this [article|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/0736159e-0301-0010-9ea4-c63d83d0797b] might be helpful. You can also use the JNDI browser in the Visual Admin tool to locate your EJB.

HTH!

-- Vladimir

Former Member
0 Likes

Hi Vladimir,

thank you for the Link. I still got this Exception:

Exception: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

Greetings, Alexander

Vlado
Product and Topic Expert
Product and Topic Expert
0 Likes

I'm afraid I'm lost now. This exception is thrown during new InitialContext(). However, in your previous post you say that you get

> The value is: Context:javax.naming.InitialContext@cdfc9c

but you have a problem with the EJB lookup. So, which one is true? What is the complete stack trace?

Former Member
0 Likes

Hi,

this Exception is thrown after this result: Context:javax.naming.InitialContext@cdfc9c and before the lookup.

The complete Stack Trace is:

Exception thrown [Mon Aug 11 10:48:10,187]:Exception thrown by application running in JCo Server

com.sap.engine.services.rfcengine.RFCException: Bean ZEJB_TEST_ZUGRIFF not found

at com.sap.engine.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:123)

at com.sap.engine.services.rfcengine.RFCJCOServer.handleRequest(RFCJCOServer.java:156)

at com.sap.mw.jco.JCO$Server.dispatchRequest(JCO.java:7701)

at com.sap.mw.jco.MiddlewareJRfc$Server.dispatchRequest(MiddlewareJRfc.java:2376)

at com.sap.mw.jco.MiddlewareJRfc$Server.listen(MiddlewareJRfc.java:1700)

at com.sap.mw.jco.JCO$Server.listen(JCO.java:8061)

at com.sap.mw.jco.JCO$Server.work(JCO.java:8181)

at com.sap.mw.jco.JCO$Server.loop(JCO.java:8128)

at com.sap.mw.jco.JCO$Server.run(JCO.java:8044)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)

Caused by: com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Object not found in lookup of ZEJB_TEST_ZUGRIFF.

at com.sap.engine.services.jndi.implserver.ServerContextImpl.lookup(ServerContextImpl.java:649)

at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:344)

at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:639)

at javax.naming.InitialContext.lookup(InitialContext.java:347)

at javax.naming.InitialContext.lookup(InitialContext.java:347)

at com.sap.engine.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:115)

... 12 more

Vlado
Product and Topic Expert
Product and Topic Expert
0 Likes

This is not the exception from your lookup. This is an exception from the RFC Provider service failing to look up an EJB named ZEJB_TEST_ZUGRIFF in response to a RFC call from the ABAP system. Please clarify your scenario and outcome, because so far you've stated the following:

1) Exception during new InitialContext (no initial context factory specified).

2) InitialContext obtained, but exception during lookup of "sap.com/TestWorldEar/TestBean".

3) Goto 1.

4) InitialContext obtained, some other lookup exception.

Former Member
0 Likes

Hi Vladimir,

my scenario is that I want to transfer data from Java Stack to Abap Stack via RFC connection.

Therefore I first establish via JCO an RFC connection. Then I send an request from Abap which is handled within my Java program. In this program I also establish a connection to the EJB to get the data from the database.

Within my Netweaver Developer Studio everything works fine. I can send data from Java to Abap. But when I deploy my client application to the J2EE Server I have the problems as described before.

Greetings, Alexander

Former Member
0 Likes

Hi,

java.util.Hashtable env = new java.util.Hashtable();

javax.naming.Context initialContext;

env.put(Context.INITIAL_CONTEXT_FACTORY,

"com.ibm.websphere.naming.WsnInitialContextFactory");

env.put(Context.PROVIDER_URL,

"corbaloc:iiop:localhost:2809");

initialContext = new javax.naming.InitialContext(env);

Try to use the above sample code.

InitialContext can be created by passing environment properties via a hashtable object.

Check out for the values of the Context.INITIAL_CONTEXT_FACTORY,Context.PROVIDER_URL related to EP.

Rama Murthy

Vlado
Product and Topic Expert
Product and Topic Expert
0 Likes

Alexander,

Since you get the result

> Context:javax.naming.InitialContext@cdfc9c

and have also said

> My problem first starts here:

> // Look up the home interface using the JNDI name.

>

> // This JNDI lookup returns a reference to an EJBHome instance.

>

> TestHome home = (TestHome) ctx.lookup("sap.com/TestWorldEar/TestBean");

> System.out.println("TestHome:" + home);

>

> I think I do not have the right path to the Bean but I don't know.

I assume that you have overcome the new InitialContext issue. Question now is, what's wrong during the EJB lookup? In order to resolve it, please refer to my posts above (exception stack trace, SDN article, JNDI browser).

Vlado
Product and Topic Expert
Product and Topic Expert
0 Likes

Rama Murthy,

I don't understand how examples referring to Sun or IBM specific configurations could be handy here.

Have you read the other answers in the thread before posting? Setting up properties for the InitialContext has already been discussed and also references provided. It doesn't seem to be at issue here.