cancel
Showing results for 
Search instead for 
Did you mean: 

ClassCastException in EJB lookup

Former Member
0 Kudos

Hi,

I developed an EJB in Netweaver and it is running fine together with my WebDynPro. Now i'm using the EJB as library file in my another Java standalone program that running using eclipse. I import it as External JAR into my application. When i try to run it, it will hit java.lang.ClassCastException. Here is my code.


...
try {
      Properties props = new Properties();
      props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
      props.put(javax.naming.Context.PROVIDER_URL, "localhost:50000");
      Context ctx = new InitialContext(props);
      TestHome home = (TestHome)ctx.lookup("SENDER");
      test = home.create();
}....

I got the error java.lang.ClassCastException error when i try to run it and the problem is in the TestHome home = (TestHome)ctx.lookup("SENDER");

I tried to change the code to


TestHome home = (TestHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("SENDER"), TestHome.class);

And also this way


Object obj = ctx.lookup("SENDER");
TestHome home = (TestHome)javax.rmi.PortableRemoteObject.narrow(obj, TestHome.class);

And i got this error which i think is the similar as both way is different syntax but same function type.


java.lang.ClassCastException
	at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
	at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
	at net.model.proxy.NewProxyClient$Polling.run(NewProxyClient.java:78)
	at java.util.TimerThread.mainLoop(Timer.java:432)
	at java.util.TimerThread.run(Timer.java:382)

I tried to google and check out SDN. Some said bout the classloader that cause this. I go through this document [How To ... EJB: Accessing EJB Applications using JNDI|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/0736159e-0301-0010-9ea4-c63d83d0797b] and follow it, but still having the problem ClassCastException. Any help for this? Appreciate for the helps. Thanks..

-


I tried to create a new Session Bean in my EJB application. Test it out, to my surprise it able to connect and create in my Java program. The session bean is empty. Then i tried to create a new Session bean with another name and JNDI, then copy the code into the new session bean. The same problem is occurs. So which mean some problem with my session bean. Will try to figure it out.

Edited by: Adrian Chan on May 5, 2009 12:32 PM

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I did a terrible mistake.

As i debugging the program then i realize that one of the JAR which is included in the EJB as reference project is not included in my Java program. After i include it then no problem with the program.

Sorry for my big mistake and thanks for all the helps.

ravindra_bollapalli2
Active Contributor
0 Kudos

hi,

is u r home object is located in local or remote

if u keep in local -- as u refering one document u have to follow the

example 3 on words

let me know u need any futher info

bvr

Former Member
0 Kudos

Hi,

My home object located in another server. So is remote rite.

I run my Java program in another server.

Sorry I think my code had lead your confuse as i put localhost:50000. I'm connecting to another server for the EJB.

Thanks for your help.

ravindra_bollapalli2
Active Contributor
0 Kudos

hi,

are u able to get the home object ur application -- located at different server ??(just put a dummy message so that you can get the control movement where u r application reaches or not

)

you want to say that u r home object located at different server

u r java application is in u r local pc

instead of localhost:50000

you better to use the ipno or system name of the different server

because localhost refer to localsystem only

bvr

Former Member
0 Kudos

Hi,

Maybe i elaborate the EJB location and my Java program. My EJB is located in Server A and my Java program is located at Server B. My Java program need to lookup Server A JNDI.

My EJB have 2 Session Bean. I tried with another Session Bean. It won't hit the ClassCastException error. It able to lookup. It only happen to this Session bean. If i simply put a lookup name it will say Unable to locate the following lookup name. This mean is correct since there is no such JNDI in the server.

In my Java program I'm using <ip:port>.

Thanks.

ekaterinamitova
Advisor
Advisor
0 Kudos

Hi Adrian,

Which version of the SAP NetWeaver are you using? There is a different lookup format in SAP NetWeaver CE 7.1.

Best regards,

Ekaterina

Former Member
0 Kudos

Hi Ekaterina,

I'm using SAP Netweaver 2004s (7.0)

In my Java program is using Java SDK 1.4.2_08.

Thanks

adrian

ravindra_bollapalli2
Active Contributor
Former Member
0 Kudos

Thanks for the info.

Will try out and see it work or not. But this is for EJB 3.0 as the EJB that i developed in NWDS 7.0 is EJB 2.0. There is some different between both if i not mistaken. Anywhere no harm for a try rite.

Realized the only diff is this.


Session.HelloWorldRemote ans=(Session.NewSessionRemote) ctx.lookup("HelloWorld/HelloWorldBean/remote"); 

Thanks.

-


I had try to implement the code in. But am wondering the Session come from as is not clear in the example. Try out with the SessionContext but seem is not the same.

I think this is probably the Java ClassLoader problem also. Trying to get more info for this.

Thanks.

Edited by: Adrian Chan on May 11, 2009 8:37 AM

Former Member
0 Kudos

Hi,

Actually now i'm debugging my Java application.

I created another entity bean with a JNDI name. The entitybean don't have any function. It able to run the lookup function without any problem. I'm wonder this is java casting problem or my entitybean code?

Thanks.