繁体   English   中英

如何访问 weblogic 集群中管理服务器的 JNDI 树?

[英]how to access the JNDI tree of the adminserver in a weblogic cluster?

我有一个带有管理服务器、服务器 1 和服务器 2 的集群,该应用程序部署到服务器 1 和 2 的集群。

如果我将应用程序部署在本地单个服务器中,则以下代码工作正常

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

但是一旦部署到集群它就会失败(NamingException)

查看 JNDI 树,我看到 jmx/domainRuntime 仅在管理服务器中可用。

所以基本上这就是我的问题的原因,如果应用程序在服务器 1 或 2 中,如何访问管理服务器中的资源。

提前致谢。

根据https://docs.oracle.com/middleware/1213/wls/WJNDI/wls_jndi.htm#i473354,您应该采用以下方法:

示例 2-7 在 WebLogic 集群中使用命名服务

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
  }
}

您还应该参考: 如何在 WebLogic 上查找 JNDI 资源?

以及其中包含的最佳答案,即

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).........

只需从您的代码中更改代码块,这将要求您导入包就这样做,这将起作用:

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();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM