Weblogic ALSBConfigurationMBean 初始化

发布于 2024-12-07 12:05:04 字数 885 浏览 16 评论 0原文

我正在尝试使用 Java 进行 OSB (ESB) 自动构建过程。为此,我需要执行以下操作:

  1. 连接到 weblogic - 这正在工作 //weblogic 版本是 10.3.0.0
  2. 使用连接创建一个 DomainRuntimeServiceMBean 对象 - 这也正在工作
  3. 使用之前创建的 DomainRuntimeServiceMBean 对象创建 ALSBConfigurationMBean 对象 -这是我的问题。

我使用以下代码来创建 ALSBConfigurationMBean 对象:

DomainRuntimeServiceMBean domainService = ConnectionUtil
            .createDomainService(mHost, mPort, mUsername, mPassword,
                    connector);

    ALSBConfigurationMBean alsbSession = (ALSBConfigurationMBean) domainService
            .findService(ALSBConfigurationMBean.NAME,
                    ALSBConfigurationMBean.TYPE, null);

我得到的错误是:

Exception in thread "main" java.lang.ClassCastException: $Proxy1 cannot be cast to weblogic.management.mbeanservers.Service
at $Proxy0.findService(Unknown Source)

I'm trying to make an OSB (ESB) automated build process using Java. For that purpose I need to do the following things:

  1. Connect to weblogic - this is working //The weblogic version is 10.3.0.0
  2. Make a DomainRuntimeServiceMBean object using the connection - this is also working
  3. Make a ALSBConfigurationMBean object using the previously created DomainRuntimeServiceMBean object - here is my problem.

I use the following code for making the ALSBConfigurationMBean object:

DomainRuntimeServiceMBean domainService = ConnectionUtil
            .createDomainService(mHost, mPort, mUsername, mPassword,
                    connector);

    ALSBConfigurationMBean alsbSession = (ALSBConfigurationMBean) domainService
            .findService(ALSBConfigurationMBean.NAME,
                    ALSBConfigurationMBean.TYPE, null);

The error that I get is:

Exception in thread "main" java.lang.ClassCastException: $Proxy1 cannot be cast to weblogic.management.mbeanservers.Service
at $Proxy0.findService(Unknown Source)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国产ˉ祖宗 2024-12-14 12:05:04

我正在研究类似的东西,@Rich 提供的解决方案对我有用。但是,我最终采用了一种稍微不同的方法,不需要使用 weblogic.management.jmx.MBeanServerInvocalHandler (至少直接使用)。

以下是一些应该执行您要查找的操作的代码:

package scratch;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Hashtable;

import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean;

import com.bea.wli.sb.management.configuration.ALSBConfigurationMBean;
import com.bea.wli.sb.management.configuration.SessionManagementMBean;

public class TestOSB_JMX {

    public static void main(String[] args) throws Throwable {

        // Provide connection information for OSB WebLogic AdminServer on command line
        String host = args[0];
        int    port = Integer.parseInt(args[1]);
        String user = args[2];
        String password = args[3];

        JMXConnector conn = initJmxConnection(host, port, user, password);
        try {
            System.out.println("Opened JMX connection to " + host + ":" + port + " as " + user);

            // get mbean connection
            MBeanServerConnection mbconn = conn.getMBeanServerConnection();

            // Get SessionmanagementMBean
            SessionManagementMBean sm = 
                JMX.newMBeanProxy(mbconn, ObjectName.getInstance(SessionManagementMBean.OBJECT_NAME), SessionManagementMBean.class);

            // Create a session
            String sessionName = "MySession";           
            sm.createSession(sessionName);

            // Get the configuration MBean for the session, do stuff, and then discard the session.
            try
            {
                System.out.println("Session exists? : " + sm.sessionExists(sessionName));

                ALSBConfigurationMBean configMBean = 
                    JMX.newMBeanProxy(
                        mbconn, 
                        ObjectName.getInstance("com.bea:Name=" +ALSBConfigurationMBean.NAME + "." + sessionName +",Type=" + ALSBConfigurationMBean.TYPE), 
                        ALSBConfigurationMBean.class
                    );

                System.out.println("Got the config MBean for session: " + configMBean.getSession());

                // Do stuff in the session here....
            }
            finally
            {
                // use activateSession to commit session changes instead
                sm.discardSession(sessionName);
            }
        } finally {
            conn.close();
            System.out.println("Closed JMX connection");
        }
    }

    public static JMXConnector initJmxConnection(String hostname, int port,String username, String password) 
    throws IOException, MalformedURLException 
    {
        JMXServiceURL serviceURL = new JMXServiceURL("t3", hostname, port, "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME);

        Hashtable<String, String> h = new Hashtable<String, String>();
        h.put(Context.SECURITY_PRINCIPAL, username);
        h.put(Context.SECURITY_CREDENTIALS, password);
        h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");

        return JMXConnectorFactory.connect(serviceURL, h);
    }
}

以下是有关我的解决方案的一些注意事项:

  1. 我的类路径直接引用以下 WebLogic 和 OSB JAR 文件:alsb.jar、osb-server-modules-ref.jar、wlfullclient .jar
  2. 这些 JAR 将通过清单文件中的类路径条目引用(许多)其他 JAR。
  3. 您可能需要按照此处所述生成 wlfullclient.jar 文件: http://docs.oracle.com/cd/E17904_01/web.1111/e13717/jarbuilder.htm
  4. 对于这种类型,最好使用 wlfullclient.jar 而不是 weblogic.jar客户端应用程序。我首先使用 weblogic.jar,它给我带来了许多类加载的麻烦。
  5. 我正在使用 Oracle Service Bus 版本:11.1.1.4 WebLogic 版本:10.3.4 和 Java 1.6.0_29。

I am working on something similar, and the solution that @Rich gave worked for me. However, I have ended up with a slightly different approach that doesn't require using the weblogic.management.jmx.MBeanServerInvocationHandler (directly at least).

Here is some code that should do what you are looking for:

package scratch;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Hashtable;

import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean;

import com.bea.wli.sb.management.configuration.ALSBConfigurationMBean;
import com.bea.wli.sb.management.configuration.SessionManagementMBean;

public class TestOSB_JMX {

    public static void main(String[] args) throws Throwable {

        // Provide connection information for OSB WebLogic AdminServer on command line
        String host = args[0];
        int    port = Integer.parseInt(args[1]);
        String user = args[2];
        String password = args[3];

        JMXConnector conn = initJmxConnection(host, port, user, password);
        try {
            System.out.println("Opened JMX connection to " + host + ":" + port + " as " + user);

            // get mbean connection
            MBeanServerConnection mbconn = conn.getMBeanServerConnection();

            // Get SessionmanagementMBean
            SessionManagementMBean sm = 
                JMX.newMBeanProxy(mbconn, ObjectName.getInstance(SessionManagementMBean.OBJECT_NAME), SessionManagementMBean.class);

            // Create a session
            String sessionName = "MySession";           
            sm.createSession(sessionName);

            // Get the configuration MBean for the session, do stuff, and then discard the session.
            try
            {
                System.out.println("Session exists? : " + sm.sessionExists(sessionName));

                ALSBConfigurationMBean configMBean = 
                    JMX.newMBeanProxy(
                        mbconn, 
                        ObjectName.getInstance("com.bea:Name=" +ALSBConfigurationMBean.NAME + "." + sessionName +",Type=" + ALSBConfigurationMBean.TYPE), 
                        ALSBConfigurationMBean.class
                    );

                System.out.println("Got the config MBean for session: " + configMBean.getSession());

                // Do stuff in the session here....
            }
            finally
            {
                // use activateSession to commit session changes instead
                sm.discardSession(sessionName);
            }
        } finally {
            conn.close();
            System.out.println("Closed JMX connection");
        }
    }

    public static JMXConnector initJmxConnection(String hostname, int port,String username, String password) 
    throws IOException, MalformedURLException 
    {
        JMXServiceURL serviceURL = new JMXServiceURL("t3", hostname, port, "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME);

        Hashtable<String, String> h = new Hashtable<String, String>();
        h.put(Context.SECURITY_PRINCIPAL, username);
        h.put(Context.SECURITY_CREDENTIALS, password);
        h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");

        return JMXConnectorFactory.connect(serviceURL, h);
    }
}

Here are some things to note about my solution:

  1. My classpath directly references the following WebLogic and OSB JAR files: alsb.jar, osb-server-modules-ref.jar, wlfullclient.jar
  2. These JARs will reference (many) other JARs through the Class-Path entries in the Manifest files.
  3. You may need to generate the wlfullclient.jar file as described here: http://docs.oracle.com/cd/E17904_01/web.1111/e13717/jarbuilder.htm
  4. It is better to use wlfullclient.jar instead of weblogic.jar for this type of client application. I was using weblogic.jar first and it caused many class loading headaches for me.
  5. I am using Oracle Service Bus Version: 11.1.1.4 WebLogic version: 10.3.4, and Java 1.6.0_29.
も让我眼熟你 2024-12-14 12:05:04

如果有人遇到同样的错误,请使用
weblogic.management.jmx.MBeanServerInvocalHandler 而不是 javax.management.MBeanServerInvocalHandler:

https://forums.oracle.com/forums/thread.jspa?threadID=817973&tstart=420

In case that anyone gets the same error then use
weblogic.management.jmx.MBeanServerInvocationHandler instead of javax.management.MBeanServerInvocationHandler:

https://forums.oracle.com/forums/thread.jspa?threadID=817973&tstart=420

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文