Dynamic way to get the server name in the lookup


EJB programming & troubleshooting: Dynamic way to get the server name in the lookup

  1. Here is the query


    this is how u get the InitialContext for doing the jndi lookup.
    here we have hard coded the url as "t3://localhost:7001"

    is there any way to know abt the server name dynamically

  2. hello Karthikeyan,

    In the case of a servlet that is invoking the bean, the following code shows how you can get the url from the incoming Context structure.

    String initCtxFactory = getInitparamter(Context.Initial_context_Factory);

    String ProviderURL = getInitparamter(Context.provider_url);

    // ADD JNDI init paramter to a properties object.

    properties env = new properties();
    evn.put(Context.INITIAL_CONTEXT_FACTORY, initCtxFactory);

    The other way is for the Deployer to specify this when deploying the beans. In that situation you would just use
    the default InitialContext in your code thus:

    InitialContext inictx = new InitialContext();

    The above picks up the initial context information from whatever the deployer specified during bean deployment.