on 05-06-2006 6:32 AM
hi,
i have written remote client for ejb.
Context ctx = null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialReplicatingContextFactoryImpl");
env.put(Context.PROVIDER_URL, "192.168.1.100:50000");
// env.put("force_remote", true);
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");
try {
ctx = new InitialContext(env);
} catch (NamingException ne) {
System.out.println(ne);
<b>exception is</b>
javax.naming.NoInitialContextException: Cannot instantiate class: com.sap.engine.services.jndi.InitialReplicatingContextFactoryImpl [Root exception is java.lang.ClassNotFoundException: com.sap.engine.services.jndi.InitialReplicatingContextFactoryImpl]
java.lang.NullPointerException
please help me to do this
regards
Guru
<b></b><b></b><b></b><b></b><b></b><b></b><b></b><b></b><b></b>
Hi Guru,
You can refer to the following article for getting InitialContext to the J2EE Engine:
http://help.sap.com/saphelp_nw04/helpdata/en/b5/3f48e02b2e8e4d9272ee63819bba80/frameset.htm
I see two problems in your coding:
You use InitialReplicatingContextFactoryImpl and you are trying to connect to the http port of the Engine, while you should connect to the p4 service port. By default the p4 service port on this system should be 50004.
The exception that you get is because you are missing sapj2eeclient.jar in the classpath of the client.
Best Regards
Vyara
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
i have changed my programm as you told.But it giving same exception.Please help me to do this.
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
hi, i have changed progrmm but it giving same exception.please help me.
p.put(Context.PROVIDER_URL, "localhost:50004");
p.put(Context.SECURITY_PRINCIPAL, "admin");
p.put(Context.SECURITY_CREDENTIALS, "admin");
Hi Guru,
ClassNotFoundException means that the sapj2eeclient.jar file is not in the classpath of the client. Add /usr/sap/<SID>/<InstanceId>/j2ee/j2eeclient/sapj2eeclient.jar:/usr/sap/<SID>/<InstanceId>/j2ee/j2eeclient/exception.jar:/usr/sap/<SID>/<InstanceId>/j2ee/j2eeclient/logging.jar files to the classpath of your client. You might need more jars as well.
Regards
Vyara
I HAVE WEITTEN THE CODE
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
p.put(Context.PROVIDER_URL, "192.168.1.100:50004");
p.put(Context.SECURITY_PRINCIPAL, "admin");
p.put(Context.SECURITY_CREDENTIALS, "admin");
try {
ctx = new InitialContext(p );
GetStatusSessionHome objGetStatusSessionHome=null;
Object obj=ctx.lookup("GetStatusSessionBean");
objGetStatusSessionHome=(GetStatusSessionHome)obj;
System.out.println(ctx);
} catch (NamingException ne) {
System.out.println(ne);
EXCEPTION IS
java.lang.NoClassDefFoundError: javax/ejb/EJBHome
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"
I HAVE ADDED JARS:SAPJ2EECLIENT.JAR,LOGGING.JAR,EXCEPTION.JAR AND INTERFACES
Hi
Add ejb20.jar also in the classpath , Hence forth please rememember if you are running any stand alone client SAP web AS provides all the reqd jars in
/usr/sap/<SID>/<InstanceId>/j2ee/j2eeclient/
folder which needs to be in the classpath.
Hope this helps , please do not forget to reward points
regards
rajeshkr
IT IS GIVING ANOTHER EXCEPTION PLEASE HELP ME
com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception while trying to get InitialContext. [Root exception is com.sap.engine.services.security.exceptions.BaseLoginException: Cannot create new RemoteLoginContext instance.]
java.lang.NullPointerException
please check my code once
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
p.put(Context.PROVIDER_URL, "192.168.1.100:50004");
p.put(Context.SECURITY_PRINCIPAL, "admin");
p.put(Context.SECURITY_CREDENTIALS, "admin");
try {
ctx = new InitialContext(p );
GetStatusSessionHome objGetStatusSessionHome=null;
GetStatusSession objGetStatusSession=null;
Object obj=ctx.lookup("java:comp/env/ejb/GetStatusSessionBean");
objGetStatusSessionHome=(GetStatusSessionHome)obj;
objGetStatusSession= objGetStatusSessionHome.create();
objGetStatusSession.getStatus("MAS000002");
} catch(Exception ne) {
System.out.println(ne);
} finally {
try {
ctx.close();
} catch (Exception e) {
System.out.println(e);
}
i have solved all exception by adding jar files.
still it is giving exception
please help me
<b>exception is</b>
com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at java:comp, the whole lookup name is java:comp/env/ejb/GetStatusSessionBean.
Hi,
When you use a remote client and when you get a context you can lookup objects from the root element of the tree. and there are no such subcontexts in the root as java:comp/env/.
So you need to lookup the EJB with its application name and EJB name. Refer to the second paragraph of this article:
http://help.sap.com/saphelp_nw04/helpdata/en/38/3e5a4201301453e10000000a155106/frameset.htm
Hi Guru ,
the exception is because, the given JNDI name is not present in the JNDI registry of the WAS. to avoid this , u have to give the exact JNDI name u have given while deploying ur application .
If u follow like this , u can avoid that type of exception.
U can try this..
In the EJB project double click the ejb-j2ee-engine.xml file . Then in the Enterprise Beans Tab , u can see the EJBs in ur EJB project in 3 sessions like session bean , entity bean and message driven bean.
From this select ur particular bean . then in the right pane , u can give the JNDI name for that ejb.
Give like this..
<u><b>for example...</b></u>
JNDI Name = testJNDI
then u can look up like this in ur code...
<u>a) for Remote Home Object</u>
Object ref =ctx.lookup("testJNDI");
For remote object , u have to type cast this object to Remote Home Object.
<b><u>b) For Local Home object</u></b>
<b>Object ref =ctx.lookup("localejbs/testJNDI");</b>
<b>from ur code given , i could realize that , u r looking for Local Home Object .. so u can use like mentiond above</b>
use like this in ur code...
U can see the JNDI names in the JNDI registry of hur WAS.
This JNDI registry u can see through ,
Visual Administrator or Web Admin ..
ur JNDI name will come under the EAR project ,in which ur EJB is present.
Regards
Kishor Gopinathan
Hi
No you dont have to add any jars , remeember these jars are only for standalone java .
to access other beans u can do a local JNDI look up to the other session bean from the bean class which wants to access that ejb.
For this the other bean class should have the local iterfaces defined as well
Hope this helps .
regards
rajeshkr
hi,
for standalone java program i have to set username,password,and url etc...
{
p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
p.put(Context.PROVIDER_URL, "192.168.1.219:50004");
p.put(Context.SECURITY_PRINCIPAL, "admin");
p.put(Context.SECURITY_CREDENTIALS, "admin");
}
is it require for session beans(if both are living in <u><i><b>same server</b></i></u>)
regards
Guru
hi
none of teh setting is required.
Have a look at the code below :
Context ctx = new InitialContext();
2. Look up the bean. To look up the bean locally, use:
MyExampleLocalHome myExampleLocalHome = (MyExampleLocalHome) ctx.lookup(localejbs/sap.com/MyEAR/MyExampleBean);
hope this helps .
regards
rajeshkr
Message was edited by: Rajesh K. R.
Hi
You can check your deployed EJb's jndi name through visal admin . FOr this go to the JNDI registery node & on the right hand screen scroll down and click on the <i>localejbs</i> node(blue clolor) . check for ur deployed ejb context in that node .
for ex if u see <i>ejb</i> as the next node which has one more child node <i>MyLocalEjb</i>
then your jndi name will be <b><i>localejbs/ejb/MyLocalEjb</i></b>
Hope this helps
regards
rajeshkr
hi,
have you included the client jar .
you need to obtain the client JAR in order to run the beans from within the client application.
the procedure for obtaining client jar is:
http://help.sap.com/saphelp_nw04/helpdata/en/5f/2dd984b5d1304b9155f161568f2f64/frameset.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi guru
1)If you are accessing the ejb from a standalone client (java program) check whether sapj2eeclient.jar is your classpath ,since the context factory impl class is in this jar.
2) In your code the please check the p4 port is 50000 . you can check this from visual admin .The default port is 50004.
hope this helps , please do not forget to reward points if helpful.
regards
rajeshkr
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.