Hello,
I have a simple Hello World bean and remote, but I cant get it to work.
I keep on getting a ClassCastException in my client with
PortableRemoteObject.narrow
What am I missing here??
| package nl.mkoopman.helloworld;
|
| import java.util.Properties;
|
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
| import javax.rmi.PortableRemoteObject;
|
| public class HelloWorldClient {
|
| public static void main(String[] args) throws NamingException {
| InitialContext context = getInitialContext();
| java.lang.Object ref = context.lookup("HelloBean/remote");
| HelloRemote helloRemote= (HelloRemote)
PortableRemoteObject.narrow(ref, HelloRemote.class);
| System.out.println("Hello World says: "+helloRemote.sayHello());
|
| }
|
| private static InitialContext getInitialContext() throws NamingException
| {
| Properties properties = new Properties();
| properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
| properties.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
| properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
| return new InitialContext(properties);
| }
|
| }
| package nl.mkoopman.helloworld;
|
| import javax.ejb.Remote;
|
| @Remote
| public interface HelloRemote {
|
| public String sayHello();
| }
|
| package nl.mkoopman.helloworld;
|
| import javax.ejb.Stateless;
|
| @Stateless
| public class HelloBean implements HelloRemote {
|
| @Override
| public String sayHello() {
| return "Hello!";
| }
| }
|
| 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
nl.mkoopman.helloworld.HelloWorldClient.main(HelloWorldClient.java:22)
| Caused by: java.lang.ClassCastException: javax.naming.Reference cannot be
cast to org.omg.CORBA.Object
| at
com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
| ... 2 more
|
| 16:30:17,257 INFO [SessionSpecContainer] Starting
jboss.j2ee:jar=helloWorld.jar,name=HelloBean,service=EJB3
| 16:30:17,257 INFO [EJBContainer] STARTED EJB:
nl.mkoopman.helloworld.HelloBean ejbName: HelloBean
| 16:30:17,269 INFO [JndiSessionRegistrarBase] Binding the following Entries
in Global JNDI:
|
| HelloBean/remote - EJB3.x Default Remote Business Interface
| HelloBean/remote-nl.mkoopman.helloworld.HelloRemote - EJB3.x Remote
Business Interface
|
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4244668#4244668
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4244668
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user