cancel
Showing results for 
Search instead for 
Did you mean: 

JNDI InitialContext Error

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (5)

Answers (5)

siddharth_jain
Active Contributor
0 Kudos

Hi,

Updated:

i think You are trying to lookup the Remote home interface using the procedure of Local home Interface lookup,For local home interface lookup you have to prefix localejbs before the default Jndi name of the Bean.

Check the default name under Visual Admin.

And rest of the lookup code is fine.

But in case of Remote home lookup the lookup syntex will be different:

<BeanHome Home = (<Bean>Home) javax.rmi.PortableRemoteObject.narrow(ctx.lookup(<Default Jndi Name without localejbs prefix>),<Bean>Home.class);

Check the Following link Also See the last reply.

Regards,

Siddharth

Edited by: Siddharth Jain on Sep 4, 2008 6:36 AM

siddharth_jain
Active Contributor
0 Kudos

Hi,

if you are accessing the EJB instance from your standalone java application you can try the following:-

String url = server + ":" + port;

Properties properties = new Properties();

properties.put(Context.INITIAL_CONTEXT_FACTORY,

"com.sap.engine.services.jndi.InitialContextFactoryImpl");

properties.put(Context.PROVIDER_URL, url);

//properties.put (Context.SECURITY_PRINCIPAL, "Administrator");

//properties.put(Context.SECURITY_CREDENTIALS, "password_here");

properties.put("force_remote", "true");

intialcontext = new InitialContext(properties);

You can try without force_remote property as well i think it should work.

by doing this you can get the initial context now you have to look up your ejb accordingly .

Check this SAP help on how to Look UP Remote and Local interfaces of EJB.

http://help.sap.com/saphelp_nw04/helpdata/en/38/3e5a4201301453e10000000a155106/frameset.htm

See the "Lookup from a Non-J2EE Java Application " section of the above link i think you should lookup your EJB using the approaches given in this section .

Hope This will help.

Regards,

Siddharth

Former Member
0 Kudos

Hi Siddarth,

I already tested all of your answers but nothing of that work. But I am now sure that I won't get the JNDI context. But I dont know why.

My code is actually looking like this:

String contextFactory = "com.sap.engine.services.jndi.InitialContextFactoryImpl";

System.out.println ("contextfactory" + contextFactory );

Properties properties = new Properties();

properties.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);

//properties.put("force_remote", "true");

properties.put(Context.PROVIDER_URL, "server_url");

properties.put(Context.SECURITY_PRINCIPAL, "user");

properties.put(Context.SECURITY_CREDENTIALS, "password");

Context ctx = new InitialContext(properties);

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();

siddharth_jain
Active Contributor
0 Kudos

Hi Alexander,

If you are not sure about the JNDI name of the Bean ,You should check its JNDI Name fom the ejb-j2ee-engine.xml file and if the JNDI name is not there you can specify any valid name,deploy the EJB Proj again.

Then try to lookup the EJB with its JNDI name instead of its Path on server.

Regards,

Siddharth

Vlado
Advisor
Advisor
0 Kudos

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 Kudos

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
Advisor
Advisor
0 Kudos

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 Kudos

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
Advisor
Advisor
0 Kudos

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 Kudos

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
Advisor
Advisor
0 Kudos

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 Kudos

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 Kudos

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
Advisor
Advisor
0 Kudos

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
Advisor
Advisor
0 Kudos

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.

Former Member
0 Kudos

Hi Alexander,

For accessing the EJBs with a Java Client you can refer to the following [link.|http://help.sap.com/saphelp_nwce10/helpdata/en/45/e692b2cfaa5591e10000000a1553f7/frameset.htm]

Though the link is for the CE Version, you can use the information to set up your Initial Context.

Regards,

Alka.

Former Member
0 Kudos

Hello Alka,

thank you for the link. I still know that link but it doesn't work.

I still have problems to register to the JNDI. And I have also read that I will not need these parameters if my application is running on the same instance.

Greetings, Alexander