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 の回答は問題ありません。私の場合、ドメイン内の多くの管理対象サーバーの 1 つに接続していました。

これは私がしたことです:

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 に答える