1 Reply Latest reply: Jan 16, 2012 11:14 AM by Wolf-Dieter Fink RSS

Get ejb3 from remote host (jboss 5.1) to jboss 4.x

Michael Lanf Newbie

Hi,

I'm trying to get an ejb3 from a remote host (that uses jboss 5.1) inside jboss 4.x. The code I use is the following:

 

public void myFunction() {

        Properties jndiProps = new Properties();

        jndiProps.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

        jndiProps.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interface");

        jndiProps.setProperty(Context.PROVIDER_URL, "jnp://{host-ip}:{host-jndi-port}");

        try {

            FooInterface foo = (FooInterface)(new InitialContext(jndiProps)).lookup("{jndi-name}");

            foo.doSomething();

        } catch (Exception e) {

            e.printStackTrace();

        }

       

    }

 

But doing that, I get a ClassCastException here "FooInterface foo = (FooInterface)(new InitialContext(jndiProps)).lookup("{jndi-name}");":

 

java.lang.ClassCastException: javax.naming.Reference cannot be cast to my.package.FooInterface

   at com.phi.phirxportal.SecondOpinionRequestBean.myFunction(SecondOpinionRequestBean.java:272)

   at com.phi.phirxportal.SecondOpinionRequestBean.checkExam(SecondOpinionRequestBean.java:170)

   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

     at java.lang.reflect.Method.invoke(Method.java:597)

     at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)

 

Host ip, jndi name and host jndi port are correct. I can't figure out how to get my FooInterface from a javax.naming.Reference object.

The Reference object toString method returns something like:

 

Reference Class Name: Proxy for: my.package.FooInterface

Type: ProxyFactoryKey

Content: ProxyFactory/.....

Type: EJB Container Name

Content: jboss.j2ee:ear=xxx.ear,jar=xxx.jar,name=FooBean,service=EJB3

Type: Proxy Factory is Local

Content: false

Type: Remote Business Interface

Content: my.package.FooInterface

Type: Remoting Host URL

Content: socket://hostpcname:3873/?

 

Is there a way to do that or does it depends on something else (libraries, configuration, jboss version...)?

Thanks in advance.