cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Remote EJB in Remote Server

Former Member
0 Kudos

I'm developing in Netweaver 2004s, EJB 2.0.

I'm trying to access my EJB that located at another server using the remote EJB method. It is a EJB 2.0. Here are my code.


...
try{

Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
props.put(Context.PROVIDER_URL, "192.0.0.1:50004");
props.put(Context.URL_PKG_PREFIXES, "com.sap.engine.services");   
InitialContext ctx = new InitialContext(props);
Object obj = ctx.lookup("sap.com/HelloWorldEAR/HelloWorldBean");
HelloWorldHome helloHome = (HelloWorldHome) PortableRemoteObject.narrow(obj, HelloWorldHome.class);
HelloWorld hRef = helloHome.create();

String msg = hRef.printMsg();
.......
}

When i tried to run it, it printout this error.


com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at HelloWorldEAR, the whole lookup name is sap.com/HelloWorldEAR/HelloWorldBean

I'm not sure is it connected to the remote server and try to find my EJB or it unable to connect at all as both is different issue.

I tried access to the local EJB that i deployed in the same server using this method.


Context ic = new InitialContext();
HelloWorldHome home = (HelloWorldHome)ic.lookup("OUTBOUND");
helloLocal = home.create();	

It is working fine. My Stateless Session Bean i register the JNDI as OUTBOUND. So am wondering i need to do it this way for my remote EJB also?


Object obj = ctx.lookup("sap.com/HelloWorldEAR/HelloWorldBean");

Change to

Object obj = ctx.lookup("sap.com/HelloWorldEAR/OUTBOUND");

I tried by seem not working also. Anyone can englight me. Appreciate the help.

Accepted Solutions (1)

Accepted Solutions (1)

ravindra_bollapalli2
Active Contributor

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Following code may be of use for you



Properties props =new Properties();
		props.put (Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl");
		props.put(Context.PROVIDER_URL,"localhost:50004");
		InitialContext context = new InitialContext(props);

		Object obj = context.lookup("com.sap/CalculatorServiceEAR/REMOTE/CalculatorBean/com.bcone.test.CalculatorRemote");

		
		CalculatorRemote helloRef = (CalculatorRemote)
		PortableRemoteObject.narrow(obj, CalculatorRemote.class);
		System.out.println(helloRef.add(10, 20));

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

The same error as previous. It seem that it always unable to get my EJB.


com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at HelloWorldEAR, the whole lookup name is sap.com/HelloWorldEAR/HelloWorldBean

Thanks.

Former Member
Former Member
0 Kudos

Hello Adrian,

I am having the same problem like you. That means, I'd like to debug on a server and it just won't work. I solved the problems you're having, though. I implemented a client proxy which calls PI then. Coding is as follows:


Hashtable<String, String> prop = new Hashtable<String, String>();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
prop.put("force_remote", "true");
prop.put(Context.PROVIDER_URL, "servername:50004");
prop.put(Context.SECURITY_PRINCIPAL, "username");
prop.put(Context.SECURITY_CREDENTIALS, "password");
InitialContext ic = new InitialContext(prop);
TestClassLocal tcb = (TestClassLocal) ic.lookup("sap.com/DistributeMasterDataEAR/LOCAL/TestClassBean/com.mt.pi.bo.gl.mdm.testbean.TestClassLocal");
try {
	File f = new File("C:\Temp\crm_quote.JPG");
	FileInputStream fin = new FileInputStream(f);
	byte[] image = new byte[(int)f.length()];
	for(int i = 0; i<f.length(); i++) {
		image<i> = (byte)fin.read();
	}
int size = tcb.callPi(image);

(I am sending an image to PI)

I found the correct URL like this:

- Go to JNDI Browser in the NWA

- Search for context objects

- Search for the entry including the deployed EAR file and the Bean name in the folder name

- Take the entry below and copy the "Object Name" to the code

This worked for me.

However, I don't manage to do the remote debug. I follow the documentation here:

http://help.sap.com/saphelp_nwpi71/helpdata/en/46/c2a1e4e4cc0e5ce10000000a1553f7/frameset.htm

But the steps described there don't happen in our environment. Deploying works fine, but switching to debug mode just doesn't have any effect. In the console the NWDS is busy telling me "Enabling debug mode" and it just won't finish. I checked the server configuration, it said "debuggable = yes" and "debug = false". But even switching it to "true" in the management console and then restarting it doesn't help. Of course, if I change to debug in the NWDS this parameter doesn't change to "true", either

Could anyone help me on that?

Regards,

Jörg

Edited by: Joerg Thiesmann on Mar 27, 2009 10:30 AM

ravindra_bollapalli2
Active Contributor
0 Kudos

hi chan,

what is the error is getting

bvr

Former Member
0 Kudos

Hi bvr,

Thanks for your help.

From the info, the first one is running in EJB 3.0. I think the lookup is slighty different than in EJB 2.0.

I tried added the login to my code.


...
try{
 
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
props.put(Context.PROVIDER_URL, "192.0.0.1:50004");
props.put(Context.SECURITY_PRINCIPAL, "J2EE_ADMIN");
props.put(Context.SECURITY_CREDENTIALS, "password");
props.put(Context.URL_PKG_PREFIXES, "com.sap.engine.services");   
InitialContext ctx = new InitialContext(props);
Object obj = ctx.lookup("sap.com/HelloWorldEAR/HelloWorldBean");
HelloWorldHome helloHome = (HelloWorldHome) PortableRemoteObject.narrow(obj, HelloWorldHome.class);
HelloWorld hRef = helloHome.create();
 
String msg = hRef.printMsg();
.......
}

If i enter the wrong password it showed that Cannot authenticate the user which mean is correct since i entered the wrong password. Which mean i able to connect to the server and unable to locate my EJB. Then i tried with the correct password and it still showing me the error which is unable to locate my EJB. I already followed the path that i saw in the J2EE_Engine.

In the EJB Container this is how it look like.

Beans - sap.com/HelloWorldEAR/HelloWorld.jar/HelloBean

And the JNDI Name is sap.com/HelloWorldEAR/HelloBean

Which mean is the correct lookup that i set in my program. But still wondering why it unable to lookup.

Thanks.