10 Replies Latest reply: May 13, 2012 2:53 PM by sixtdeu RSS

global jndi names for remote ejb lookup possible?

sixtdeu Newbie

Hi @ll,

 

is it possible to lookup an ejb remote using the java:global... jndi name? How to do this?

Normally I do not know if an ejb is stateful or stateless. Using the "ejb:..." lookup name I have to set "?stateful" for a stateful ejb lookup. This information is not visible on the (remote) interface, so my factory class cannot create the lookup name properly. Any Ideas?

 

Thanks

  • 1. Re: global jndi names for remote ejb lookup possible?
    Prasad Deshpande Expert

    is it possible to lookup an ejb remote using the java:global... jndi name? How to do this?

    In EE6,  It's not allowed to have java:global namespace outside JVM due to security issues.

     

     

    Normally I do not know if an ejb is stateful or stateless. Using the "ejb:..." lookup name I have to set "?stateful" for a stateful ejb lookup. This information is not visible on the (remote) interface, so my factory class cannot create the lookup name properly. Any Ideas?

    You mean to say you have a remote interface that is implemented by both stateless & stateful?

  • 2. Re: global jndi names for remote ejb lookup possible?
    sixtdeu Newbie

    Sorry, maybe I expressed inaccurate...

    I meant I would like to lookup in an other way than "ejb:..", could be java:app or java:module. My problem is I can see the lovely jndi name of the ejb's deployed to the server, but I'm to incompetent to make a lookup

    I was able to lookup a stateless ejb with something like this:

     

    String JBOSS_CONTEXT =
    "org.jboss.naming.remote.client.InitialContextFactory";

     

    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, JBOSS_CONTEXT);
    props.put(Context.PROVIDER_URL, "remote://MyIP:4447");
    props.put(Context.SECURITY_PRINCIPAL, "user");
    props.put(Context.SECURITY_CREDENTIALS, "useruser");
    Context context = new InitialContext(props);
    return (RemoteCalculator) context
      .lookup("/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator");

     

    But I couldn't lookup a sfsb... I hope it is possible to lookup it without that "?stateful" suffix in the lookup name, isn't it?

    Additional info, not knowing if it is important: I'm on cluster/domain.

  • 3. Re: global jndi names for remote ejb lookup possible?
    Wolf-Dieter Fink Master

    No,

    ATM there are only two ways to lookup, the 'ejb:' and that what you used (but this is deprecated).

    So you need to hace ?stateful in the name.

     

    But what about (my prefered way) an 'Interface class' which provide all Beans of the application and hide the names.

    Create with PROVIDER_URL or default to jboss-ejb-client.properties. Maybe you add also the EAR/JAR name and use a default for your app.

     

    Each interface will be cached in here and the user get easy the Interface back.

  • 4. Re: global jndi names for remote ejb lookup possible?
    sixtdeu Newbie

    Hi Wolf-Dieter,

     

    thanks for your answer. Your tip sounds nice. Could you explain what you meant with "Create with PROVIDER_URL or default to jboss-ejb-client.properties. Maybe you add also the EAR/JAR name and use a default for your app.". I would try it out and give you feedback this wednesday.

    With "ATM" you mean there is another way for lookup planned for the future as7 releases or we schould wait for what happens in future jee releases?

     

    Best regards

     

    Chris

  • 5. Re: global jndi names for remote ejb lookup possible?
    Wolf-Dieter Fink Master

    Simple Constructor lets call the class AppApi:

    {code}

    final Hashtable jndiProperties = new Hashtable();

    final InitialContext iCtx;

    String earName = "mydefault";  // fill with the default names

    String jarName = "mydefault";

    AppApi() { // all default, use jboss-ejb-client.properies

      jndiProperties.put(InitialContext.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

      iCtx = new InitialContext(jndiProperties);

    }

    AppApi(String host) { // use JNDI

      jndiProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

      jndiProperties..put(InitialContext.PROVIDER_URL, "remote://"+ host +":4447");

      iCtx = new InitialContext(jndiProperties);

    }

    }

    AppApi(String host, int port) {}

    AppApi(String ear, String jar) {

      this();

      earName = ear;

      jarName = jar;

    }

     

    MyRemote getMyRemote() {

      return iCtx.lookup("ejb:"+myEar+"/"+myJar+"//MyRemoteBean:com.my.app.MyRemote?stateful");

    }

    {code}

     

    For the moment there is no way to change/custimoze  the JNDI name. In AS6/5 there was an JBoss annotation for this. So I'm not sure whether there will be a posibility later.

  • 6. Re: global jndi names for remote ejb lookup possible?
    sixtdeu Newbie

    Thanks Wolf-Dieter. Sounds good. I'll try it out, if this is applicable for my project.

  • 7. Re: global jndi names for remote ejb lookup possible?
    sixtdeu Newbie

    Hi all,

     

    sorry for reopening this old thread, but I'm a litte bit concerned about Prasad's answer....

     

    Could you explain or give me a hint, where in the jee6 spec I can find something about you said:

    "In EE6, It's not allowed to have java:global namespace outside JVM due to security issues."

     

    I know a tutorial is not the spec, but I see something like that:

    "

    The java:global JNDI namespace is the portable way of finding remote enterprise beans using JNDI lookups. JNDI addresses are of the following form:

    java:global[/application name]/module name/enterprise bean name[/interface name]

    Application name and module name default to the name of the application and module minus the file extension. Application names are required only if the application is packaged within an EAR. The interface name is required only if the enterprise bean implements more than one business interface.

    "

    found here

    http://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html

     

    I understand it, I could lookup my ejb remote interface from remote (standalone) client using "java:global" jndi name. Am I right?

     

     

    Thanks in advance

     

    Chris

  • 8. Re: global jndi names for remote ejb lookup possible?
    Prasad Deshpande Expert

    Could you explain or give me a hind, where in the jee6 spec I can find something about you said:

    "In EE6, It's not allowed to have java:global namespace outside JVM due to security issues."

     

    Well, it doesn't clearly say that access is not allowed, infact, EE6 doesn't talk about access in the remote clients, but if you look at section 5.2.2 last paragraph, "A Java EE product may impose security restrictions on access of resource in the shared namespace"

     

    I understand it, I could lookup my ejb remote interface from remote (standalone) client using "java:global" jndi name. Am I right?

    with AS 7.1, not everything hooked to java:global is exportable, so it's not allowed to export entire java:global namespace to remote client.

     

    Besides, I've also tried in Websphere v8, & got the error saying java:global is not allowed to access outside JVM. It might be due to above statement in the spec. However, I may be wrong here..

  • 9. Re: global jndi names for remote ejb lookup possible?
    jaikiran pai Master

    Here's a more detailed previous discussion about this https://community.jboss.org/message/637563#637563

  • 10. Re: global jndi names for remote ejb lookup possible?
    sixtdeu Newbie

    Hi guys,

     

    thanks for your answer. It's funny Prasad asked the same question few months ago...

    One thing is still not clear for me. After deploying my ejb.jar the server says:

    server.png

    Why I can not use

    "java:jboss/exported/JBOSS_JEE_SERVICE/CalculatorBean!de.....jboss7.stateless.RemoteCalculator"

    for jndi lookup from remote?

     

    Thanks