I am running
JBoss 4.2 and JDK 1.5. I try to run the following client class below I receive the error . Exception in
thread Exception in thread "main" java.lang.ClassCastException
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at simplebean.client.SimpleBeanClient.createBean(SimpleBeanClient.java:44)
at simplebean.client.SimpleBeanClient.main(SimpleBeanClient.java:37)
Caused by: java.lang.ClassCastException: $Proxy0
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
JAVA CLASS
/**
*
*/
package simplebean.client;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import simplebean.interfaces.Simple;
import simplebean.interfaces.SimpleHome;
/**
* @author owner
*
*/
public class SimpleBeanClient {
Properties properties;
public SimpleBeanClient() {
properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming
rg.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
}
public static void main(
String[] args) {
SimpleBeanClient beanClient = new SimpleBeanClient();
beanClient.createBean();
}
public void createBean() throws EJBException {
try {
InitialContext context = new InitialContext(properties);
Object object = context.lookup("ejb/SimpleBeanHome");
SimpleHome simpleHome = (SimpleHome) PortableRemoteObject.narrow(
object, SimpleHome.class);
Simple simple = simpleHome.create();
simple.setName("Gunter");
System.out.println(simple.getId());
System.out.println(simple.getName());
} catch (NamingException e) {
throw new EJBException(e);
} catch (RemoteException e) {
throw new EJBException(e);
} catch (CreateException e) {
throw new EJBException(e);
}
}
}