1 2 Previous Next 22 Replies Latest reply: Jun 13, 2012 5:50 PM by shadowcreeper RSS

How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?

shadowcreeper Apprentice

When doing remote JNDI lookup of EJB on JBoss AS 7.1.1.Final it appears that you are not able to specify the host/port for lookup.

 

Using jboss-ejb-client.properties you can specify a list of connections (host/port/username/etc) but all lookups seem to do some sort of round-robin approach as to which server to connect to, stopping at the first server which has the bean registered. I have found no way to specify which connection to use for a particular lookup.

 

I have found some people claiming that the "old way" of specifying Context.PROVIDER_URL "remote://host:port" in your InitialContext(properties) should work as of 7.1.1, but it always gives me: "java.lang.IllegalStateException: No EJB receiver available for handling ...".

 

Are those people lying? Or is there a way to specify the host/port to use for a remote ejb?

  • 1. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    shadowcreeper Apprentice

    Assumed answer: This cannot be done because JBoss 7.1 is broken by design.

  • 2. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    Wolf-Dieter Fink Master

    This behaviour of the ejb-client is subject to change.

    I would not say "broken by design" but I aggree that there are some functional differences.

    The main issue was the standartization of the JNDI name.

     

    First the EJB is identified by its name

    * application name (i.e. ear name)

    * module name (i.e. name of the ejb-jar inside the ear)

    * distinct name

    * Bean name

    * Bean Interface

     

    See the documentation

     

    There are many different approaches to achieve the wanted behaviour.

    Could you describe a bit what you want and how your deployment topology is?

  • 3. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    shadowcreeper Apprentice

    We have an application (EAR) which connects to several other services (EJBs within EARs on other JBoss servers).

     

    EJB 1 may be on Server A, while EJB 2 may be on Server B (there are several EJBs on several different servers).

     

    In JBoss 5 we just told the app which servers each EJB was located on. It would then only check Server B for EJB 2, and would not use EJB 2 on Server A even if one existed.

     

    This is the behavior I am trying to replicate. Always use Server B for EJB 2 (and ignore EJB 2 on any server but Server B). EJB 1 may be an optional service, so that if Server A is down, we run with limited functionality, but we do not need to keep trying to connect to Server A when trying to get/use EJB 2 which we already know exists on Server B.

  • 4. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    Wolf-Dieter Fink Master

    At the moment the EJB is identified by its name. If you have a client-context which contains different servers you can not decide which server is taken if you have an EJB with the same identifier depoyed on each.

    The only way to do it for the moment is to have a 'distinct' name in the jboss-ejb3.xml inside the application or defined in the server configuguration (ejb3 subsystem).

     

    But this behaviour is subject to change.

  • 5. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    jaikiran pai Master

    Wolf-Dieter Fink wrote:

     

    The only way to do it for the moment is to have a 'distinct' name in the jboss-ejb3.xml inside the application or defined in the server configuguration (ejb3 subsystem).

     

    But this behaviour is subject to change.

    Just to be clear - the distinct name behaviour is not going to change.

  • 6. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    Wolf-Dieter Fink Master

    Sorry for confusion and thanks to  Jaikiran for clarify it.

    I meant that the behaviour of the client context, regarding the selection and influence what server handle the request, is subject to change.

     

    The JNDI names and the distinct name are not part of that as Jakiran mentioned.

  • 7. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    shadowcreeper Apprentice

    When you say "the distinct name behavior is not going to change"...

     

    Do you mean that if you fix this later and allow us to determine which server to connect to per EJB, that it will fail to work if it finds another EJB with that same "distinct name" on another server that it knows about event though I told it specifically to use a different server?

     

    Or do you mean that the way we specify "distinct name" (ear/jar/class!interface) is not going to change?

  • 8. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    Wolf-Dieter Fink Master

    I'm not sure what you exactly mean.

    But the distinct name can be used to differencing two deployed application with the same name.

     

    If the client-context allows you to decide which server you mean this is only another option.

    If you use the distinct name as workaround for the moment, sure you have to change the name if you decide to use the server-selection instead of distinct name.

  • 9. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    shadowcreeper Apprentice

    I was asking for clarification on your previous post: What may change? What may not?

     

    You used the phrases "distinct name" and "JNDI names" in ways that I did not understand.

     

    I had incorrectly assumed the following definitions:

    JNDI name (when looking up remote EJBs): java:jboss/exported/ear-name/jar-name/EJB-name!interface-class

    distinct name: the part  of "JNDI name" following "jboss:/jboss/exported/"

     

    Thanks

  • 10. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    Wolf-Dieter Fink Master

    From client side the bean is identified by its name.

    There are different options how to setup the client see [1]

    * InitialContext without a property file (using PROVIDER_URL  remote:/host:4447)

    * InitialContext with jboss-ejb-client.property file

    * Using the JBoss specific API

     

    The identifier of the Bean is

    ejb:/ear/jar/distinct name/beanname!Interface

    or

    ear/jar/beanname!interface

     

    so the distinct name is part of the identifier and can be set in the META-INF/jboss-ejb3.xml of the application or global in the ejb subsystem for all applications of the server.

    This behaviour will not change as Jaikiran mentioned.

    Only the method how the client side select the server is subject to change.

     

    [1] https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

  • 11. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    shadowcreeper Apprentice

    Are you saying that we can still use "remote:/host:4447" to determine where to lookup the bean?

     

    If so, how? I have found no examples anywhere. Nor have I been the least bit successful in my attempts to figure it out. I have never gotten the JBoss 7.1.1.Final server to recognize PROVIDER_URL.

     

    When I leave the servers out of the jboss-ejb-client properties file (or remove the file entirely) I get failure no matter what is in the PROVIDER_URL. When I add in all servers to the properties file, it checks all servers no matter what I put into PROVIDER_URL (and if multiple servers have the same bean, then both are used in a sort of load-balancing/sharing way).

  • 12. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    Wolf-Dieter Fink Master

    This should work:

     

    {code}

    import javax.naming.Context;

    import javax.naming.InitialContext;

    import javax.naming.NamingException;

     

       final Hashtable<Object,Object> jndiProperties = new Hashtable<Object,Object>();

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

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

       final Context context = new InitialContext(jndiProperties);

       slsb = (StatelessSession) context.lookup(EJB3SLSB/ejb/StatelessSessionBean!"+StatelessSession.class.getName());

    {code}

  • 13. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    jaikiran pai Master

    Wolf-Dieter Fink wrote:

     

    This should work:

     

     

    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    
       final Hashtable<Object,Object> jndiProperties = new Hashtable<Object,Object>();
       jndiProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
       jndiProperties.put(InitialContext.PROVIDER_URL, "remote://localhost:4447");
       final Context context = new InitialContext(jndiProperties);
       slsb = (StatelessSession) context.lookup("ear/jar/StatelessSessionBean!"+StatelessSession.class.getName());
    

     

    Wolf is right, although that code is missing an (important) property. Don't forget to add the following property if you want to do EJB invocations, using the  same connection that was established via PROVIDER_URL:

     

    jndiProperties.put("jboss.naming.client.ejb.context", true);
    


  • 14. Re: How to specify host/port in remote JNDI lookup on JBoss 7.1.1.Final?
    Wolf-Dieter Fink Master

    Yes, Jaikiran you're right, normally I add this.

     

    But I took this from a working code example. Is there a difference between the AS7 versions?

    Other thing is that it looks like this is working by accident if you have a valid jboss-ejb-client.properties in the classpath, maybe this force the behaviour also ?!

     

    If I remove it you definitly need this property!

1 2 Previous Next