You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Kest <so...@mail.ru> on 2007/11/20 15:10:29 UTC

java.lang.ClassCastException while getting the home-interface!

Hi, everybody. I’m new to J2EE™-applications development. At this moment I’m
trying to get started with Enterprise JavaBeans™. I’ve made, packed into
JAR-file, and successfully deployed on Geronimo 2.0 a very simple EJB™
called first.jar. It just takes two integer numbers, adds them, and then
prints the result to the console. I’d like to make it work along with my
application client (standalone, not servlet or Java Server Page; I run it
from a command line). After I had deployed my JavaBean™, I looked through
Geronimo log-file and found this string:

11:50:14,968 INFO  [OpenEJB] Auto-deploying ejb First:
EjbDeployment(deployment-id=first/First, container-id=null)


I assumed that I should specify the name for my EJB™ as “first/First”. That
is why I put those pieces of code in my application client:

...
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
properties.put(Context.PROVIDER_URL, "rmi://localhost:4201");
try{
  System.out.println("Starting Client...");
  InitialContext initialContext = new InitialContext(properties);
  if(initialContext != null) System.out.println("Got context!");
  Object objRef = initialContext.lookup("first/First");
  System.out.println("Got home EJB-object reference!");
  FirstHome firstHome = (FirstHome)PortableRemoteObject.narrow(objRef,
FirstHome.class);
  First first = firstHome.create();
  System.out.println("2 + 5 = " + first.add(2, 5));
}
...

When I try to “narrow” the object reference and to get my EJB’s
home-interface, I receive this error message: java.lang.ClassCastException.

Could anyone tell me what I’m doing wrong? Thanks a lot. Looking forward to
hearing from you.

-- 
View this message in context: http://www.nabble.com/java.lang.ClassCastException-while-getting-the-home-interface%21-tf4843726s134.html#a13857671
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.

Re: java.lang.ClassCastException while getting the home-interface!

Posted by Viet Nguyen <vh...@gmail.com>.
You are right. Does first FirstHome have the @Remote annotation?

On Nov 20, 2007 11:23 AM, Kest <so...@mail.ru> wrote:
>  I DO have all the classes, actually! I mean, the client "sees" them all! I
> can write, for example: FirstHome firstHome;
>  firstHome = (FirstHome)PortableRemoteObject.narrow(objRef,
> FirstHome.class);
>
>  If the client couldn't "see" FirstHome.class, it would never allow the
> first string where I declare the reference to FirstHome. I receive the
> exception exactly when I try to make class casting with (FirstHome)...
> Defining a class-path won't help. Sorry.
> ________________________________
>  View this message in context: Re: java.lang.ClassCastException while
> getting the home-interface!
>
>
>  Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>

Re: java.lang.ClassCastException while getting the home-interface!

Posted by Kest <so...@mail.ru>.
Jarek, thanks a lot! Your post was very useful for me. But I used a little
bit other JNDI name: “first/First/full class name of EJB’s remote
interface”. (Perhaps, you’ve made a misprint). Thank you very much!
-- 
View this message in context: http://www.nabble.com/java.lang.ClassCastException-while-getting-the-home-interface%21-tf4843726s134.html#a13877667
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.

Re: java.lang.ClassCastException while getting the home-interface!

Posted by Jarek Gawor <jg...@gmail.com>.
I think your JNDI name is not quite correct. It should be something
like: "first/First/<full class name of home interface>"

Jarek

On Nov 20, 2007 11:23 AM, Kest <so...@mail.ru> wrote:
>  I DO have all the classes, actually! I mean, the client "sees" them all! I
> can write, for example: FirstHome firstHome;
>  firstHome = (FirstHome)PortableRemoteObject.narrow(objRef,
> FirstHome.class);
>
>  If the client couldn't "see" FirstHome.class, it would never allow the
> first string where I declare the reference to FirstHome. I receive the
> exception exactly when I try to make class casting with (FirstHome)...
> Defining a class-path won't help. Sorry.
> ________________________________
>  View this message in context: Re: java.lang.ClassCastException while
> getting the home-interface!
>
>
>  Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>

Re: java.lang.ClassCastException while getting the home-interface!

Posted by Kest <so...@mail.ru>.
I DO have all the classes, actually! I mean, the client “sees” them all! I
can write, for example:

  FirstHome firstHome;
  firstHome = (FirstHome)PortableRemoteObject.narrow(objRef,
FirstHome.class);

If the client couldn’t “see” FirstHome.class, it would never allow the first
string where I declare the reference to FirstHome. I receive the exception
exactly when I try to make class casting with (FirstHome)... Defining a
class-path won’t help. Sorry.

-- 
View this message in context: http://www.nabble.com/java.lang.ClassCastException-while-getting-the-home-interface%21-tf4843726s134.html#a13860024
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.

Re: java.lang.ClassCastException while getting the home-interface!

Posted by Viet Nguyen <vh...@gmail.com>.
I think that you are not having the FirstHome class in your client's
classpath. Try running the client with something like

java <ClientClassName> -cp=<path_to_FirstHome.class>

--Viet

On Nov 20, 2007 9:10 AM, Kest <so...@mail.ru> wrote:
>  Hi, everybody. I'm new to J2EE™-applications development. At this moment
> I'm trying to get started with Enterprise JavaBeans™. I've made, packed into
> JAR-file, and successfully deployed on Geronimo 2.0 a very simple EJB™
> called first.jar. It just takes two integer numbers, adds them, and then
> prints the result to the console. I'd like to make it work along with my
> application client (standalone, not servlet or Java Server Page; I run it
> from a command line). After I had deployed my JavaBean™, I looked through
> Geronimo log-file and found this string:
>
>  11:50:14,968 INFO [OpenEJB] Auto-deploying ejb First:
> EjbDeployment(deployment-id=first/First, container-id=null)
>
>
>  I assumed that I should specify the name for my EJB™ as "first/First". That
> is why I put those pieces of code in my application client: ...
> Properties properties = new Properties();
> properties.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.RemoteInitialContextFactory");
> properties.put(Context.PROVIDER_URL, "rmi://localhost:4201");
> try{
>  System.out.println("Starting Client...");
>  InitialContext initialContext = new InitialContext(properties);
>  if(initialContext != null) System.out.println("Got context!");
>  Object objRef = initialContext.lookup("first/First");
>  System.out.println("Got home EJB-object reference!");
>  FirstHome firstHome = (FirstHome)PortableRemoteObject.narrow(objRef,
> FirstHome.class);
>  First first = firstHome.create();
>  System.out.println("2 + 5 = " + first.add(2, 5));
> }
> ...
>
>
>  When I try to "narrow" the object reference and to get my EJB's
> home-interface, I receive this error message: java.lang.ClassCastException.
>  Could anyone tell me what I'm doing wrong? Thanks a lot. Looking forward to
> hearing from you.
> ________________________________
>  View this message in context: java.lang.ClassCastException while getting
> the home-interface!
>  Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>