WebSphere Application Server - ClassCastException while referencing EJBs (WAS 6)

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Application Server > September 2006 > ClassCastException while referencing EJBs (WAS 6)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author ClassCastException while referencing EJBs (WAS 6)

2006-09-16, 1:48 pm

Hello all!

We are facing a problem with EJB JNDI searching in WAS 6. Here is an approximate snippet that is used:

Object nsObject = initialContext.lookup("java:comp/env/ejb/CustomFacade");
EJBHome ejbHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object)nsObject, EJBHome.class);
return (CustomFacadeHome)ejbHome;

This is done from another EJB, this EJB has a reference to CustomFacade EJB, the name of the reference is ejb/CustomFacade.

Error occurs in the last line of this snippet. CORBA error is reported to the batch process that called the first EJB. What is useful is the following part of the reported error:

Caused by: java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBHome_Stub
at <the last line of the provided snippet>

What is really bad is that this error sometimes happen, but sometimes this code works correctly (using the same usecase). This code was already working for several years in previous WAS versions with no problems... It started to periodically happen in the
last few days and dissapered after another deployment today (so cannot be reproduced at the moment). But I fear that it may again come up later.

And there is no idea in which direction to dig - code, deployment/configuration or WAS 6 bugs... Maybe anybody has a clue what can it be related with?

Many thanks in advance
Randy Schnier

2006-09-16, 1:48 pm

Your PortableRemoteObject.narrow() should be passing
CustomFacadeHome.class, not EJBHome.class. The type passed as the 2nd
argument of the narrow should be the same as the type you're doing to
cast the result to. This is standard JavaEE / RMI-IIOP procedure,
nothing specific to WAS.

trofimov@de.ibm.com wrote:
> Hello all!
>
> We are facing a problem with EJB JNDI searching in WAS 6. Here is an approximate snippet that is used:
>
> Object nsObject = initialContext.lookup("java:comp/env/ejb/CustomFacade");
> EJBHome ejbHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object)nsObject, EJBHome.class);
> return (CustomFacadeHome)ejbHome;
>
> This is done from another EJB, this EJB has a reference to CustomFacade EJB, the name of the reference is ejb/CustomFacade.
>
> Error occurs in the last line of this snippet. CORBA error is reported to the batch process that called the first EJB. What is useful is the following part of the reported error:
>
> Caused by: java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBHome_Stub
> at <the last line of the provided snippet>
>
> What is really bad is that this error sometimes happen, but sometimes this code works correctly (using the same usecase). This code was already working for several years in previous WAS versions with no problems... It started to periodically happen in t

he last few days and dissapered after another deployment today (so cannot be reproduced at the moment). But I fear that it may again come up later.
>
> And there is no idea in which direction to dig - code, deployment/configuration or WAS 6 bugs... Maybe anybody has a clue what can it be related with?
>
> Many thanks in advance

2006-09-18, 1:31 pm

Many thanks for the tip! But it will take some time to implement it and quick retesting will not give 100% confidence because the problem is not constantly happening.

So a few small questions regarding the tip:
1. CustomFacadeHome is a subclass of EJBHome... Is it still wrong to narrow to EJBHome class?
2. May this deviation from the standard really result in the behaviour when the problem is not constantly happening and most of the time the code works correctly?

Thanks in advance
[vbcol=seagreen]
Randy Schnier

2006-09-18, 1:31 pm

The type that you specify on the narrow must be the same as or lower (in
the inheritance hierarchy) than the level of any type that you intend to
cast the result of the narrow to. Thus, it is incorrect to narrow to
EJBHome if you plan to cast the result to something lower than EJBHome.

The actual internal type of the remote reference returned by the server
on the wire will vary. The purpose of the narrow is to ask the server
"Please give me a type that is at least this low in the hierarchy." If
the internal type of the object being narrowed is already low enough, no
action is required by the server. But if the internal type is not low
enough, the client ORB makes a request to the server ORB for another
object lower in the hierarchy. That is why an incorrect narrow will
sometimes work, and other times not work.

trofimov@de.ibm.com wrote:[vbcol=seagreen]
> Many thanks for the tip! But it will take some time to implement it and quick retesting will not give 100% confidence because the problem is not constantly happening.
>
> So a few small questions regarding the tip:
> 1. CustomFacadeHome is a subclass of EJBHome... Is it still wrong to narrow to EJBHome class?
> 2. May this deviation from the standard really result in the behaviour when the problem is not constantly happening and most of the time the code works correctly?
>
> Thanks in advance
>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com