Hi Kit,
I'm not sure that I tell you for SURE why it failed, but here are a few
thoughts.
Firstly, I think that some of the code you write is unnecessary. What I
would have written is:
Context context = new InitialContext(); // No properties required
Object homeObject = context.lookup("java:comp/env/MyCart"); // Note the
required "java:comp/env/" prefix
CartHome home =
(CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
Cart cart = home.create(); // No cast required - home.create() returns a Cart
But that probably didn't cause your problem. I would guess that it was
caused by a discrepancy between the class types specified in the XML and in
the code.
Firstly note that in the WEB-INF/web.xml you should have a section looking
something like the following:
<ejb-ref>
<ejb-ref-name>MyCart</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.acme.MyCartHome</home>
<remote>com.acme.MyCart</remote>
</ejb-ref>
(If you don't, the "lookup" will fail, even though it may have worked
without the "java:comp/env/" prefix.)
Then the error you have seems to be saying that what is in the <home> part
of the xml doesn't match the CartHome class that is being used in your Java
code.
Hope this helps!
Nick
At 03:05 PM 9/14/00 -0400, you wrote:
>
>
>Hi all
>
>I am trying to build a servlet client to look up an ejb.
>
>But, i got the following error.
>
>
>500 Internal Server Error
>
>java.lang.ClassCastException: CartHome_StatefulSessionHomeWrapper1
> at
>javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java, Compiled
>Code)
> at testCart.doGet(testCart.java, Compiled Code)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java,
>Compiled Code)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java,
>Compiled Code)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java,
>Compiled Code)
> at com.evermind.server.http.du.rr(JAX, Compiled Code)
> at com.evermind.server.http.du.forward(JAX, Compiled Code)
> at com.evermind.server.http.d5.rx(JAX, Compiled Code)
> at com.evermind.server.http.d5.rw(JAX)
> at com.evermind.util.f.run(JAX, Compiled Code)
>
>
>
>this is what i did to do the look up.
>
>
>final Properties properties = new Properties();
>
>properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.
>ApplicationClientInitialContextFactory");
>
>properties.setProperty(Context.PROVIDER_URL,"ormi://localhost/ejbsamples");
>
>properties.setProperty(Context.SECURITY_PRINCIPAL,"username");
>
>properties.setProperty(Context.SECURITY_CREDENTIALS, "password");
>
>
>Context context = new InitialContext(properties);
>
>
>Object homeObject = context.lookup("MyCart");
>
>
>CartHome home =
>(CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
>
>
>Cart cart = (Cart)PortableRemoteObject.narrow(home.create(), Cart.class);
>
>
>
>Can anyone tell me why it failed ?
>
>Thanks a lot.
>
>-kit
>