tosha Shah
tosha Shah

Reputation: 1217

jboss 7.1 call ejb to jboss 4.2

So my application is developed on Jboss-server 7.1.1 final but need to reference Ejb on Jboss-server 4.2.3. My code for calling EJB is

String IP = "X.X.X.X";
String Port = "1234";
String Lookup = "dummy/dummy/dummy";

    Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
    props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
    String ejbServiceURL = "jnp://"+IP +":"+Port; 
    props.put("java.naming.provider.url", ejbServiceURL);

    try {
        log.debug("looking up ejb by servie url:"+ejbServiceURL);
        remoteEjb = (EjbRemote) new InitialContext(props).lookup(Lookup);            
        log.debug("found ejb from context returning it.");
    } catch (NamingException e) {
        log.error("exception operating on ejb bean:" + e, e);
    }

which works perfectly fine in Jboss-4.2.3 application environment but remoteEjb always return null return on Jboss-7.1.1 Final

so can u suggest me what i am doing wrong?

Upvotes: 2

Views: 1272

Answers (1)

Duy Nguyen
Duy Nguyen

Reputation: 236

EJB JNDI look up is different from JBoss 4.2.3 and Jboss 7.1. The code which you have posted above is correct for JBoss 4.2.3, but not for JBoss 7.1. In Jboss 7.1, you have to set up the following thing:

Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

Context context = new InitialContext(jndiProperties);

Now, you can do the look up by calling:

context.lookup("ejb-jndi-name-here");

Additionally, naming context is also different in JBoss 4.2.3 and JBoss 7.1. In Jboss 7.1, the jndi will be: For stateless bean:

ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>

For stateful bean:

ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>?stateful

You can also check the mapping name when ejb service is deployed to JBoss 7.1 in the log file.

Upvotes: 6

Related Questions