on 01-30-2005 3:07 PM
Hi everyone,
I am trying to access a stateless EJB from a java standalone class.
This class is not on the same machine than the WAS 6.40.
Here is the code :
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl" );
props.put(Context.PROVIDER_URL,"server:50004");
props.put(Context.SECURITY_PRINCIPAL, "myuser");
props.put(Context.SECURITY_CREDENTIALS, "mypassword");
Context ctx = new InitialContext(props);
Object ob = ctx.lookup("sap.com/HelloWorld1EAR");
PortableRemoteObject.narrow(ob, HelloWorldHome.class).getClass().getName();
How I creaqted the EJB:
I created a new EJB module project.
I create a stateless EJB.
I added a very simple code.
I created an enterprise application project and added my EJB to it.
I didn't do any changes in the xml files.
I deployed the ear file.
If I execute the code that Detlev gave me to enumerate all the objects bound in my JNDI, I do see the EAR file that I deployed. If I look inside the ear directory, I do see the bean.
I get a class cast exception.
Thanks.....please help!!!
Hi David,
I think your JNDI name is wrong or the name is not used in the wright way.
further more you need these liberies on your classpaht
sapj2eeclient.jar
exception.jar
logging.jar
And the trace log gives my the impression that your methods are not on the remote interface.
Also look at the JNDI definition in the
ejb-j2ee-engine.xml
There must be a line with your jndi name. This is the name you can use in your client application.
example
<jndi-name>helloworld</jndi-name>
Retrieving your EJB Home interface is simulair to this
HelloWorldHome home = (HelloWorldHome)
PortableRemoteObject.narrow(
context.lookup( "helloworld" ),
HelloWorldHome.class );
Good luke
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Edward,
I gave a jndi name...it figures in the visual admin tool.
But I get exactly the same exception.
Just to remind the scenario:
I am trying to call an EJB from outside of the J2EE server (WAS 6.40).
I created the remote interface of the EJB.
Did I miss something in my xml files ?
Is there a problem maybe with the port 50004 ?
Thanks!
I hope your JNDI definition in your ejb-j2ee-engine.xml
file i in the way i described. In that case you can put your EJB on the classpath of your client application. This is not the done in real life but for the moment of testing it is oke.
Port 5004 is normally the port to use for IIOP, P4 trafic. check if this port is open for LISTENING on the remote server.
Can you tell me if the error is a
NamingException
CreateException
or a
RemoteException
and i have question Why do you use in your fist ejb call security credentials?
Give it a try without these credentials
Hi Eedward,
I did put a jndi name thus I could look up for it.
I asked my IT team to check if the port 50004 is opened for listening.
I remove the credentials....and I get the same exception.
The exception pasted a a previous message on this page.
Little question : The IT team doesn't really know how to check if port 50004 is ready for listening. How can I check it ?
Thanks.
Hi David,
The problem should not be with the port, otherwise you could not even get InitialContext, i.e. the
new InitialContext(props);
would fail.
You must not remove the credentials, they are needed in order to connect the server. This is always necessary when connecting from a remote (standalone) client.
Are you using exactly the same jndi-name as specified in the ejb-j2ee-engine.xml to perform the lookup? Have you put all required client libraries (sapj2eeclient.jar, exception.jar, logging.jar) in the classpath?
Best regards,
Vladimir
Hi Vladimir,
Yes I have these jars. I get the same exception.
Using this little code, I know what is bound to my JNDI tree.
NamingEnumeration enum = ctx.list("");
while(enum.hasMore()) {
NameClassPair pair = (NameClassPair)enum.next();
System.out.println(">> " + pair.getName());
}
I see the been and the JNDI name that I specified in the ejb-j2ee-engine.xml file.
Just to be sure....here are my EJB files under the package "com.j2ee" :
HelloWorld.java
HelloWorldBean.java
HelloWorldHome.java
HelloWorldLocal.java
HelloWorldLocalHole.java
By the way, my IT team told me that the port 50004 is open.
I telnet this port....and I got some gibrish...so it seems to be ok.
If you have any solution....it could help me.
Thanks a lot.
So,
now we know that you don't get a naming exception. There are two possible problems that can create the problem
Your remote interface in your case HelloWorld.java does not have the method. doSomething(). But that will give a compile error.
So check if your EJB jar file is on your classpath on only on your build path.
Put your EJB as as libary to your client project and check your code again.
And tell us if the problem is a creation exeption or a Remote exception
by the way. It is not needed to set credentials by default. You CAN access EJB's without credentials.
The port is not the problem.
Hi Edward,
That's not right! When you connect from a remote client you always <b><u>HAVE TO</u></b> set the JNDI credentials (see my reply above). You access EJB's <b><u>without</u></b> setting credentials only if you are already on the server, i.e. when you do the lookup from another EJB, servlet, JSP, or any other server-side component.
Hope this clarifies the issue.
Best regards,
Vladimir
Hi David,
Yes, the problem is not with the lookup string, neither it is with the port. But it seems to be connected with the libraries you are using at the client side. Can you tell us all the libraries that are in your client's classpath? Also, please paste again the whole stack trace of the exception you get now - it might look the same but maybe there is something different with the new situatuion.
Best regards,
Vladimir
Hi Vladimir,
Here is the exception:
java.lang.NoSuchMethodError: com.sap.engine.interfaces.cross.ObjectReference.toObject(Ljava/lang/ClassLoader;Ljava/lang/Object;)Ljava/lang/Object;
at com.sap.engine.services.jndi.persistent.CPOInputStream.resolveObject(CPOInputStream.java:99)
at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1321)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at java.util.Hashtable.readObject(Hashtable.java:841)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:838)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at com.sap.engine.services.jndi.persistent.RemoteSerializator.toObject(RemoteSerializator.java:70)
at com.sap.engine.services.jndi.implclient.ClientContext.deserializeObject(ClientContext.java:3324)
at com.sap.engine.services.jndi.implclient.ClientContext.deserializeDirObject(ClientContext.java:3278)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:385)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:614)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at Test1.main(Test1.java:49)
Exception in thread "main"
Here are my libraries (I am working with WAS 6.40) :
aii_proxy_rt.jar
aii_util_misc.jar
appclient.jar
bytecode.jar
cross_api.jar
epcftoolboxapi.jar
exception.jar
frame.jar
htmlb.jar
htmlbbridge.jar
iq-lib.jar
jaxrpc-api.jar
jcoapi.jar
jcoclientapi.jar
landscapeapi.jar
logging.jar
log_api.jar
naming.jar
p4.jar
sapj2eeclient.jar
sapjco.jar
sapjco_new.jar
SAPmdi.jar
sapxmltoolkit.jar
security.jar
security_api.jar
servlet.jar
Thanks Vladimir,
Best Regards
Hi David,
Probably the cross_api.jar is older than the naming.jar and this causes the above error. You should remove the following jars from your classpath (they are all part of the client lib sapj2eeclient.jar and it's always better to have this single library in the classpath instead of multiple, probably not consistent with each other, jars):
appclient.jar
cross_api.jar
frame.jar
iq-lib.jar
log_api.jar
naming.jar
p4.jar
security.jar
security_api.jar
and try again.
Hope this will be of help to you.
Best regards,
Vladimir
Hi Vladimir,
It's getting better.
I removed all of the jars you told me...except the p4.jar.
I do success looking up a jnd-name.
This time I don't get exception.
But when I try to get the home I get an exception:
Here is the code:
Object ob = ctx.lookup("helloworld2");
HelloWorld2Home remoteHome = (HelloWorld2Home)PortableRemoteObject.narrow(ob, HelloWorld2Home.class);
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at Test3.main(Test3.java:51)
I notice that I cannot put the p4.jar anywhere in the classpath order.
If I put it at the end, the program seems to search for the jndi-name "helloworld" for a long time...maybe infinit.
But if I put the p4.jar before sapj2eeclient.jar, it works better.
I think we are getting to the solution....
If you have an idea about the last exception...it could be helpfull.
Thanks,
Best Regards.
Hi,
I added the ejb20.jar and removed the p4.jar.
I get this exception when trying to get a context.
code:
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl" );
props.put(Context.PROVIDER_URL,"mrpiep03:50004");
InitialContext ctx = new InitialContext(props);
exception:
com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception while trying to get InitialContext. [Root exception is java.lang.NullPointerException]
I remember calling EJBs with other Web AS were more easy.
Notice that I remove the security authentication.
Thanks
Hi David,
like Vladimir already said, it's <b>not</b> recommended to remove the security credentials doing the JNDI lookup. This only works, if everybody (not already being "inside the server" like other EJBs or JSPs... residing on the same server) is allowed to lookup EJBs remotely on the corresponding server and this is (or should be) never the case.
Please try to add the credentials you used before and check what's the next error I don't think, this will eliminate your NullPointerException, but removes another possible error source.
Hope that helps.
Regards
Stefan
Message was edited by: Stefan Klensch
I added the principal and the credentials.
I get this exception:
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.]
Maybe my user is not enough to get a context.
But my IT team told that my user has administrator rights..so it shouldn't be a problem.
I tried many ways...I only get exceptions.
Hi David,
this seems to be a regression. When you EJB...ClassNotFound Exception occured, you have been further. Try to get there again, now with the j2ee or ejb.jar, anyhow, the interfaces within your classpath.
You also have been successful to run my program, haven't you? So, you must have changed something within the last hours to fail already on getting the InitialContext...
Best regards
Detlev
Hi David,
Since you succeeded to get InitialContext and even lookup the bean home before (when you got the java.lang.NoClassDefFoundError: javax/ejb/EJBHome) it seems that your user has enough permissions to do this operations (of course, if it is the same user). So I would suppose now the problem is that your server isn't running. You should check this, e.g. by trying to connect with the Visual Administrator tool (even with the same user).
Best regards,
Vladimir
Message was edited by: Vladimir Pavlov
Hi,
Back again.
If I add the ejb20.jar and remove the p4jar, I get the following exception:
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.]
If I put the p4.jar and remove the ejb20.jar, I success listing the objects bound in JNDI.
I success doing a lookup by writing:
Object ob = ctx.lookup("helloworld2");
I do not success geting the home by writing:
HelloWorld2Home remoteHome = (HelloWorld2Home)PortableRemoteObject.narrow(ob, HelloWorld2Home.class);
The 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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at Test8.main(Test8.java:52)
Exception in thread "main"
There seems to be a conflict between jars.
Here are the jars used in my project:
bytecode.jar
exception.jar
HelloWorld2EJB.jar
logging.jar
p4.jar
sapj2eeclient.jar
Here is what I notice...maybe it will help.
I am using the p4.jar and removed the ejb20.jar.
Scenario 1:
I add the HelloWorld2EJB.jar to the library project.
code:
Object ob1 = ctx.lookup("helloworld2");
System.out.println(ob1.getClass().getName());
output:
com.sap.engine.services.jndi.persistent.UnsatisfiedReferenceImpl
Scenario 2:
I remove the HelloWorld2EJB.jar from the library project.
code:
Object ob1 = ctx.lookup("helloworld2");
System.out.println(ob1.getClass().getName());
output:
com.sap.engine.interfaces.cross.ObjectReferenceImpl
Thanks for the help guys.
Message was edited by: David Fryda
Hi David,
> add the ejb20.jar and remove the p4jar
==>
> Exception while trying to get InitialContext
And
> put the p4.jar and remove the ejb20.jar
==>
> NoClassDefFoundError: javax/ejb/EJBHome
The third possibility, which cries loudly to be tried, is using P4 (for being able to access InitialContext) <i>and</i> ejb20.jar! What's the result with them both together?
Hope it helps
Detlev
Hi David,
I think I could help you if you provided me with the following info:
1) Print the whole stack trace of the exception that you get with the ejb20.jar and without the p4.jar (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.]).
2) In Scenario 1 (I add the HelloWorld2EJB.jar to the library project) try to do the following:
Object ob1 = ctx.lookup("helloworld2");
com.sap.engine.services.jndi.persistent.UnsatisfiedReferenceImpl ref =
(com.sap.engine.services.jndi.persistent.UnsatisfiedReferenceImpl) ob1;
System.out.println(ref);
System.out.println(ref.getStackTrace());
Best regards,
Vladimir
Hi Vladimir,
Here are the outputs.
1) Project using ejb20.jar without p4.jar
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.]
at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:538)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at Test8.main(Test8.java:35)
Caused by: com.sap.engine.services.security.exceptions.BaseLoginException: Cannot create new RemoteLoginContext instance.
at com.sap.engine.services.security.remote.login.RemoteLoginContext.<init>(RemoteLoginContext.java:98)
at com.sap.engine.services.jndi.implclient.LoginHelper.clientSideLogin(LoginHelper.java:78)
at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:402)
... 5 more
Caused by: java.lang.NullPointerException
at com.sap.engine.services.security.remote.RemoteSecurity_Stub.getRemoteLoginContext(RemoteSecurity_Stub.java:678)
at com.sap.engine.services.security.remote.login.RemoteLoginContext.<init>(RemoteLoginContext.java:93)
... 7 more
2) Project using p4.jar without ejb20.jar
2 situations:
a) In the properties of the project, in the "Java Build Path", in the "Order and Export",
<u>the p4.jar is at the last position</u> (at the bottum).
I get this exception when only trying to lookup (not narrowing).
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.]
at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:538)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at Test8.main(Test8.java:35)
Caused by: com.sap.engine.services.security.exceptions.BaseLoginException: Cannot create new RemoteLoginContext instance.
at com.sap.engine.services.security.remote.login.RemoteLoginContext.<init>(RemoteLoginContext.java:98)
at com.sap.engine.services.jndi.implclient.LoginHelper.clientSideLogin(LoginHelper.java:78)
at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:402)
... 5 more
Caused by: java.lang.NullPointerException
at com.sap.engine.services.security.remote.RemoteSecurity_Stub.getRemoteLoginContext(RemoteSecurity_Stub.java:678)
at com.sap.engine.services.security.remote.login.RemoteLoginContext.<init>(RemoteLoginContext.java:93)
... 7 more
b) In the properties of the project, in the "Java Build Path", in the "Order and Export",
<u>the p4.jar is at first position</u>.
The lookup seems to success.
>> Object ob1 = ctx.lookup("helloworld2");
>> com.sap.engine.services.jndi.persistent.UnsatisfiedReferenceImpl ref =
>> (com.sap.engine.services.jndi.persistent.UnsatisfiedReferenceImpl) ob1;
>> System.out.println(ref);
>> System.out.println(ref.getStackTrace());
The ouput is:
com.sap.engine.services.jndi.persistent.UnsatisfiedReferenceImpl@6bade9
Returned because an Exception occured in deserialization process: [java.lang.NoClassDefFoundError: javax/ejb/EJBHome]
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at com.sap.engine.services.rmi_p4.server.P4ServerObjectInfo.toObject(P4ServerObjectInfo.java:23)
at com.sap.engine.services.jndi.persistent.CPOInputStream.resolveObject(CPOInputStream.java:99)
at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1321)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at java.util.Hashtable.readObject(Hashtable.java:841)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:838)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at com.sap.engine.services.jndi.persistent.RemoteSerializator.toObject(RemoteSerializator.java:70)
at com.sap.engine.services.jndi.implclient.ClientContext.deserializeObject(ClientContext.java:3324)
at com.sap.engine.services.jndi.implclient.ClientContext.deserializeDirObject(ClientContext.java:3278)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:385)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:614)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at Test8.main(Test8.java:50)
Hi David,
It's now clearer - you're using an old sapj2eeclient.jar. When putting a newer p4.jar in the classpath in front of it, this solves the issue with getting the InitialContext, but obviously induces inconsistency between some of the used jars (most probably these are exactly the sapj2eeclient.jar and the p4.jar).
The solution is to get an up-to date sapj2eeclient.jar - you can find it in the following directory on the machine where the server is installed
/usr/sap/<SID>/<INSTANCE>/j2ee/j2eeclient
- and remove the p4.jar from the classpath. Don't forget also to add the ejb20.jar there.
Hope this will be of help now,
Vladimir
Hi Vladimir,
I do use the correct sapj2eeclient.jar.
I did a search and I found this jar in 2 locations:
a) where you told me: at /usr/sap/<SID>/<INSTANCE>/j2ee/j2eeclient
This is what I use.
The size of the jar is 9,088 KB.
I tell you the size just to be sure that I have the correct one.
b) at /usr/sap/<SID>/<INSTANCE>/j2ee/j2eeclient/signed
I always use that jar....
Maybe the ejb20.jar is not the correct one:
I found this jar in a few locations:
a) at /usr/sap/<SID>/<INSTANCE>/j2ee/j2eeclient
The size of the jar is 14 KB.
b) at /usr/sap/<SID>/<INSTANCE>/j2ee/admin/lib
The size of the jar is 14 KB.
b) at /usr/sap/<SID>/<INSTANCE>/j2ee/deploying/lib
The size of the jar is 14 KB.
c) at /usr/sap/<SID>/<INSTANCE>/j2ee/j2eeclient/signed
The size of the jar is 17 KB.
d) at /usr/sap/<SID>/<INSTANCE>/j2ee/cluster/server0/bin/extejb20
The size of the jar is 14 KB.
e) at /usr/sap/<SID>/<INSTANCE>/j2ee/cluster/server1/bin/extejb20
The size of the jar is 14 KB.
f) at /usr/sap/<SID>/<INSTANCE>/j2ee/cluster/server2/bin/extejb20
The size of the jar is 14 KB.
Maybe the WEB AS is not 6.40 ?
The IT team told me that it is 6.40...I am starting to have doubts.
Thanks Vladimir.
Hi David,
it's definitely 6.30 or above (probably 6.40), this can be seen from the dir stucture you gave.
Maybe -- if there's a problem with inconsistencies between J2EEClient.jar and the rest -- you should go back and use only the running implementations on the server, ie the list of JARs I listed in the other thread where I gave the JNDI access example.
Even if such a all-in-one-JAR is nice to have, it's always the question if this JAR is really up to date. For I have different experiences concerning SAP & API maintenance, I do not really trust in processes which lead to such a delivery of a packed JAR but would generally prefer to pack it on my own. Maybe I'm wrong here, maybe not, just give it a try.
For the ejb20.jar, in the end an alternative would be to use the Sun interfaces as said a number of postings above.
Hope it helps
Detlev
PS: A colleague of mine is just doing the same thing, if he successes, I hope to be able to give short infos about it.
Hi David,
oh no, you are too fast for SAP
6.40 is J2EE 1.3 compliant (see http://help.sap.com/saphelp_nw04/helpdata/en/de/791c7f03ea1844abe72a666bf853e3/content.htm ) and that is EJB 2.0 (see http://java.sun.com/j2ee/j2ee-1_3-fr-spec.pdf ).
So for this you should download J2EE 1.3.1 and use j2ee.jar from the lib dir.
"Hope it helps"
Detlev
Hi David,
With SAP WebAS it's also very simple but I think there's something wrong with your configuration that we still cannot find what it is However, I still believe that the problem is with the sapj2eeclient.jar you are using and not with the ejb20.jar.
What is the SP number of your J2EE Engine? If you don't know how to check it, have a look at .
What is the date of the sapj2eeclient.jar, p4.jar, naming.jar, cross_api.jar, ejb20.jar? Or it's even better to know the date of the class files in these jars? Sorry, I couldn't tell if you're using the correct (up-to date) one only by its size. I could tell you the size of the newest one but this doesn't matter as you might be running an older J2EE Engine and it wouldn't match. That's why it's important also to know the SP number.
Best regards
Vladimir
Hi Vladimir,
Here is the data in version.txt:
Cluster-Version: 6.30 PatchLevel 66061.37
Build-On:Sunday, January 11, 2004 21:06 GMT
Perforce-Server: perforce3300.wdf.sap.corp
Project-Dir:JKernel/630_SP3_REL
JKernel Change-List:66061
Build machine:PWDFM027
Build java version:1.3.1_09-b03 Sun Microsystems Inc.
Here are the dates of the files:
sapj2eeclient.jar 19/10/2004
p4.jar ...\j2ee\cluster\server0\bin\services\p4 17/11/2004
...\j2ee\cluster\server2\bin\services\p4 24/11/2004
naming.jar ...\j2ee\cluster\server0\bin\services\naming 17/11/2004
...\j2ee\cluster\server2\bin\services\naming 24/11/2004
cross_api.jar ...\j2ee\cluster\server0\bin\interfaces\cross 17/11/2004
...\j2ee\cluster\server2\bin\interfaces\cross 24/11/2004
ejb20.jar ...\j2ee\j2eeclient 20/10/2001
...\j2ee\admin\lib 20/10/2001
...\j2ee\deploying\lib 20/10/2001
...\j2ee\cluster\server0\bin\ext\ejb20 14/11/2004
...\j2ee\cluster\server1\bin\ext\ejb20 14/11/2004
...\j2ee\cluster\server2\bin\ext\ejb20 24/11/2004
Hoping it is what you wanted.
Thanks a lot.
Hi David,
The version.txt says that your J2EE Engine initially was SP3. Then it must have been upgraded to SP9 and/or SP10 but probably some of the upgrades were not fully successful, otherwise the version.txt would have been updated - but it's not. What we know for sure is that the sapj2eeclient.jar is from <b><u>SP9</u></b>! But the other jars are newer - probably from SP10.
Now, how can we proceed? You can try to find the real SP number of the Engine e.g. by looking in the /usr/sap/<SID>/<INSTANCE>/work/std_server0.out file. There you should find the text
SAP J2EE Engine Version 6.30 PatchLevel <XXXXX.XX> is starting...
Look for its last occurrence in the file.
Sorry, I can't think of another option right now...
Best regards,
Vladimir
PS: Can you also tell us the exact size of the p4.jar (in bytes) and the date of the class files inside?
Message was edited by: Vladimir Pavlov
Hi Vladimir,
Thanks again for your precious help.
The file contains the line : "SAP J2EE Engine Version 6.40 PatchLevel 87037.313 is starting..."
About the p4.jar file:
a) p4.jar at ...\j2ee\cluster\dispatcher\bin\services\
287,174 bytes 17/11/2004
date of files is 19/10/2004.
b) p4.jar at ...\j2ee\cluster\server0\bin\services\
287,174 bytes 17/11/2004
date of files is 19/10/2004.
c) p4.jar at ...\j2ee\cluster\server1\bin\services\
287,174 bytes 17/11/2004
date of files is 19/10/2004.
d) p4.jar at ...
j2ee\cluster\server2\bin\services\
287,174 bytes 24/11/2004
date of files is 19/10/2004.
I hope it will help ....
Thanks a lot.
Hi David,
Hmm... Seems that your J2EE Engine is really SP9 and the p4.jar is exactly from SP9... Then it's really-really strange that without the p4.jar in the classpath you can't get InitialContext and with the p4.jar you can.
I just asked a colleague who has already seen that NullPointerException before to have a look at the topic. Just to summarize: if you use the sapj2eeclient.jar (exactly the one from 19.10.2004!) plus only bytecode.jar, exception.jar, logging.jar, ejb20.jar, and HelloWorld2EJB.jar, you receive this exception at the bottom of the stacktrace when doing new InitialContext():
Caused by: java.lang.NullPointerException
at com.sap.engine.services.security.remote.RemoteSecurity_Stub.getRemoteLoginContext(RemoteSecurity_Stub.java:678)
at com.sap.engine.services.security.remote.login.RemoteLoginContext.<init>(RemoteLoginContext.java:93)
... 7 more
Is this still valid?
One more question: Does the machine on which the J2EE Engine is running have more than one IP address? This could be the source of the NullPointerException.
Best regards,
Vladimir
Hi Vladimir,
I checked the IP question : IT team says that we have only one IP for our J2EE server.
About the null pointer exception, it is <u>still</u> valid (using the sapj2eeclient.jar from 19.10.2004).
So now we are only trying to do a connection to the JNDI using the jars specified in your last post.
Just in case, here is again the code.
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl" );
props.put(Context.PROVIDER_URL,<server:<port>);
props.put(Context.SECURITY_PRINCIPAL, myuser);
props.put(Context.SECURITY_CREDENTIALS, mypassword);
InitialContext ctx = new InitialContext(props);
Thanks Vladimir.
Hi David,
your JNDI lookup seems to reference the ear and not a specific bean (HelloWorldBean) inside the ear. This results in a remote reference which cannot be casted to the desired remote home interface.
Assuming you have a bean HelloWordBean with corresponding remote home interface HelloWorldHome, deployed in ear named HelloWorld1EAR the following code works (in general):
// Init context like you've done it already, code omitted
Context ctx = new InitialContext(props);
// Begin lookup
Object remoteRef = ctx.lookup("sap.com/HelloWorld1EAR/HelloWorldBean");
HelloWorldHome remoteHome = (HelloWorldHome) PortableRemoteObject.narrow(remoteRef, HelloWorldHome.class);
HelloWorld helloWorld = (HelloWorld) remoteHome.create();
// From this point you can call the methods the HelloWord interface provides
helloWord.doSomething();
I've written this from scratch, so i hope there isn't a hidden syntax error.
Hope that helps.
Regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
I've done only the lookup and I got this exception:
java.lang.NoSuchMethodError: com.sap.engine.interfaces.cross.ObjectReference.toObject(Ljava/lang/ClassLoader;Ljava/lang/Object;)Ljava/lang/Object;
at com.sap.engine.services.jndi.persistent.CPOInputStream.resolveObject(CPOInputStream.java:99)
at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1321)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at java.util.Hashtable.readObject(Hashtable.java:841)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:838)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at com.sap.engine.services.jndi.persistent.RemoteSerializator.toObject(RemoteSerializator.java:70)
at com.sap.engine.services.jndi.implclient.ClientContext.deserializeObject(ClientContext.java:3324)
at com.sap.engine.services.jndi.implclient.ClientContext.deserializeDirObject(ClientContext.java:3278)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:385)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:614)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at Test1.main(Test1.java:43)
Exception in thread "main"
I do not success calling any of the EJBs I created....
Maybe the port 50004 is problematic ?
Thanks for the help.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.