• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

why did't cast the object to TestHome type?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.
I have written a Session EJB by jbuilder7.0 and deloyed it into the weblogic6.1.but when I test the EJB at client,the test program throwed a error,how can I do it?
the source:
import java.util.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;

public class testejb
{
public static void main(String args[])
{
try
{
Properties p=System.getProperties();

p.setProperty(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.setProperty(Context.PROVIDER_URL,"t3://127.0.0.1:7001");

Context ctx=new InitialContext(p);
Object ref=ctx.lookup("TestBean");
TestHome data=(TestHome) PortableRemoteObject.narrow(ref, TestHome.class);

if(data instanceof TestHome)
{
System.out.println("yes.");
}else{
System.out.println("no.");
}


}catch(Exception ex){
ex.printStackTrace();
}

}
}
error:
E:\java>java testejb
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unkno
wn Source)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at testejb.main(testejb.java:20)
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Interface does TestHome implement ?
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"gagagohst",
Welcome to JavaRanch and thanks for joining us, but your publically displayed name must meet the JavaRanch naming policy.
You can edit your profile here.
Thanks in advance,
Simon, Bartender "J2EE and EJB" forum
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try to write out the result of the lookup? (ref) Isn't it null?
What is the JNDI name of the bean (TestHome)?
Ban
 
Andras Nemeth
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant of course TestBean instead of TestHome!
Cheers,
Ban
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic