1

这是我的代码:

domainService = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");

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

ObjectName[] servers = (ObjectName[]) mBeanServer.getAttribute(domainService, "ServerRuntimes");

但我收到了这个错误。我在这里做错了什么?

javax.management.InstanceNotFoundException: com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean^M
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)^M
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)^M
        at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)^M
        at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase$12.run(WLSMBeanServerInterceptorBase.java:326)^M
        at java.security.AccessController.doPrivileged(Native Method)^M
        at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.getAttribute(WLSMBeanServerInterceptorBase.java:324)^M
        at weblogic.management.mbeanservers.internal.JMXContextInterceptor.getAttribute(JMXContextInterceptor.java:157)^M
        at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase$12.run(WLSMBeanServerInterceptorBase.java:326)^M
        at java.security.AccessController.doPrivileged(Native Method)^M
        at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.getAttribute(WLSMBeanServerInterceptorBase.java:324)^M
        at weblogic.management.mbeanservers.internal.SecurityInterceptor.getAttribute(SecurityInterceptor.java:299)^M
        at weblogic.management.jmx.mbeanserver.WLSMBeanServer.getAttribute(WLSMBeanServer.java:279)^M
        at com.motive.smp.femto.deploy.wl.utils.WLUtilities.getListMServers(WLUtilities.java:105)^M
        at com.motive.smp.femto.deploy.utils.DeploymentUtilsServlet.doGet(DeploymentUtilsServlet.java:58)^M
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)^M
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)^M
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)^
4

2 回答 2

1

尝试这个:

Context context = new InitialContext();
MBeanServer domain = (MBeanServer) context.lookup("java:comp/env/jmx/domainRuntime");
DomainRuntimeServiceMBean domainRuntimeService = (DomainRuntimeServiceMBean) MBeanServerInvocationHandler.newProxyInstance(domain, 
    new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME));
于 2014-11-27T00:45:06.540 回答
0

如果您连接到 AdminServer,sonnykwe 的回答是可以的。就我而言,我连接到域中的许多托管服务器之一。

这就是我所做的:

public static Map<String, String> getAdminServerInfo() {
    MBeanServer mBeanServer = null;
    InitialContext ctx = null;
    String administrationURL = null;
    String listenAddress = null;
    String domainName = null;
    String httpProtocol = null;
    Map<String, String> serverInfo = new HashMap<String, String>();
    int adminPort = 0;
    try {
        ctx = new InitialContext();
        mBeanServer = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");

        // Get Admin Server and Port
        String managedServerName = (String) mBeanServer.getAttribute(
                runtimeService, "ServerName");
        ObjectName msServerRuntime = new ObjectName("com.bea:Name="
                + managedServerName + ",Type=ServerRuntime");
        administrationURL = (String) mBeanServer.getAttribute(
                msServerRuntime, "AdminServerHost");
        listenAddress = (String) mBeanServer.getAttribute(msServerRuntime,
                "ListenAddress");
        adminPort = (Integer) mBeanServer.getAttribute(msServerRuntime,
                "AdminServerListenPort");
        Boolean isSecure = (Boolean) mBeanServer.getAttribute(
                msServerRuntime, "AdminServerListenPortSecure");
        httpProtocol = (isSecure) ? "https" : "http";
        ObjectName domainMBean = (ObjectName) mBeanServer.getAttribute(
                runtimeService, "DomainConfiguration");
        domainName = (String) mBeanServer.getAttribute(domainMBean, "Name");
        logger.debug("AdminURL= " + administrationURL + " ,Port= "
                + adminPort + " Domain= " + domainName + " ManagedServer= "
                + managedServerName + " ListenAddress= " + listenAddress
                + " AdminServerListenPortSecure?= " + isSecure);
        serverInfo.put("administrationURL", administrationURL);
        serverInfo.put("managedServerName", managedServerName);
        serverInfo.put("adminPort", Integer.toString(adminPort));
        serverInfo.put("domainName", domainName);
        serverInfo.put("listenAddress", listenAddress.substring(0, listenAddress.indexOf("/")));
        serverInfo.put("httpProtocol", httpProtocol);
    } catch (Exception ex) {
        logger.error(
                "Caught Exception while fetching Admin Server information : ",
                ex);
        throw new RuntimeException(
                "Caught Exception while fetching Admin Server information : ",
                ex);
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    return serverInfo;
}
于 2014-12-24T17:14:29.163 回答