0

I have a cluster with an admin server, server 1 and server 2 the application is deployed to the cluster to server 1 and 2.

the following code works fine if I deploy the application in a local, single server

InitialContext ctx = new InitialContext(); (MBeanServer) ctx.lookup("java:comp/env/jmx/domainRuntime");

but once deployed to cluster it fails ( NamingException)

looking at the JNDI tree, I see that jmx/domainRuntime is available only in the adminserver.

so basically that is the reason of my question, how that access that resource in the adminserver if the application is in server 1 or 2.

thanks in advance.

Leo
  • 1,829
  • 4
  • 27
  • 51
  • Have you tried to specify `Context.PROVIDER_URL` as a property passed to `InitialContext` ? – slwk Sep 19 '18 at 09:08
  • since this code is server side ( it is a WAR application deployed to weblogic), I do not need to add the Provider. here the documentation https://docs.oracle.com/cd/E13222_01/wls/docs100/jndi/jndi.html#wp467267 – Leo Sep 19 '18 at 19:00
  • I have not used Weblogic for years so I can't help you with a solution. However I managed to locate the current docs for you at [Oracle® Fusion Middleware Developing Custom Management Utilities Using JMX for Oracle WebLogic Server](https://docs.oracle.com/middleware/1212/wls/JMXCU/toc.htm). – Steve C Jan 30 '19 at 12:52

2 Answers2

0

According to https://docs.oracle.com/middleware/1213/wls/WJNDI/wls_jndi.htm#i473354 you should take the following approach :

Example 2-7 Using the Naming Service in a WebLogic Cluster

Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
       "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://acmeCluster:7001");
try {
  Context ctx = new InitialContext(ht);
  // Do the client's work
}
catch (NamingException ne) {
  // A failure occurred
}
finally {
  try {ctx.close();}
  catch (Exception e) {
    // a failure occurred
  }
}

You should also refer to : How to lookup JNDI resources on WebLogic?

and the top answer contained therein i.e.

Hashtable<String, String> h = new Hashtable<String, String>(7);
h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, pURL); //For example "t3://127.0.0.1:7001"
h.put(Context.SECURITY_PRINCIPAL, pUsername);
h.put(Context.SECURITY_CREDENTIALS, pPassword);

InitialContext context = new InitialContext(h).........
mkane
  • 880
  • 9
  • 16
  • Updated the answer and the link even though the information contained therein is the same... – mkane Jan 30 '19 at 14:26
-1

Just change the block of code from your code and this will ask you to import package just do it, this will work:

Environment env = new Environment();
env.setProviderUrl("localhost");
env.setSecurityPrincipal("username");
env.setSecurityCredentials("password");``
if(ctx == null) {
    try {
        ctx = env.getInitialContext();
    } catch (NamingException e) {
        System.out.println("SAML2IdentityAsserterProviderImpl: Exception " );
        e.printStackTrace();
    }
}
Taazar
  • 1,545
  • 18
  • 27
  • I think this is not wanswering the question, the question is about domain with multiple servers, thank you – Leo Mar 02 '20 at 22:17