A third way of invoking a method on a custom MBean is to actually embed the call within a Java method.
I already have a web application with EJB tier behind it so decided to enable a button on the web app which would call through to the EJB and then lookup the custom MBean and call the initialise method on it.
Within the EJB container you can get a default InitialContext using the authenticated user's credentials:
Context ctx = new InitialContext();
Then lookup WebLogic's runtime MBean Server as follows:
MBeanServer server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");
Call to retrieve all MBeans: Set names = server.queryNames(null, null);
Loop through to find your desired bean and call invoke the on the WebLogic server runtime object:
This is a very quick knock up of how to do this programmatically. I believe you can improve your search results from the server by modiying the method: server.queryNames(null, null); and passing details of the MBean you require. Haven't got that to work yet though.
Update from last blog...it looks like you can invoke custom MBean methods using the Java JDK's JConsole GUI. Instructions as follows... In order to connect to the server via the jconsole GUI, you must configure both your application server and the jconsole client.
The following command-line options should be added to the WebLogic startup script. As an example they can be added to the JAVA_OPTIONS variable within the setDomainEnv script:
Additionally the following two options should be added – these refer to the keystore which is used by the server – usually located within the JDK shipped with WebLogic:
-Djavax.net.ssl.keyStore=C:\bea_9_2_3\jdk150_12\jre\lib\security\cacerts
-Djavax.net.ssl.keyStorePassword=changeit
The certificate generated above should now be exported from the keystore and imported to the keystore where the jconsole GUI is running. Export as follows:
There is now a SSL trust established between the WebLogic server and the jconsole client. The jconsole client can now connect to the server to monitor JMX MBeans securely.
Once both server and client have been configured, connect to the server via the jconsole GUI with a URL as follows (replacing with the correct IP Address of the server):
Navigate to the WFEngineMBean within the server hierarchy as follows:
Invoke the forceEngineInitialisation() method. A dialog box will appear confirming that the process was completed successfully.
I've spent the last few days looking at setting up a custom MBean within a Weblogic (9.2) server so that I have a way of calling a method and forcing initialisation of a service which is deployed as part of an ear file.
I followed the blog on the oracle site here: http://blogs.oracle.com/WebLogicServer/2009/10/developing_custom_mbeans_to_ma.html
This works fine up to the point of deployment. However there is then the issue of actually calling the MBean and invoking the operation... I've tried to follow the blog's instructions of using jconsole with no success. I then moved on to trying to do it via the weblogic WLST command-line tool. So far as I can see the command-line tool only recognises attributes NOT operations!
After another hunt around the web I've cobbled together the instructions to do it via jconsole.
The changes can be made via the Admin console found at http://localhost:7001/console (assuming the server is on localhost and using port 7001).
To login you will need the username/password configured during the domain creation.
Click on the server you wish to edit, then the protocol tab then IIOP. Ensure enable IIOP is selected and also add in a username and password. It doesn't matter what these values are but it needs them to be set even when using anonymous access!
Save and activate changes.
Restart the server.
Now load jconsole and enter the following URL into the advanced tab:
I'm a software consultant at BT. I've been designing and developing complex OO systems for the past 10 years with the company. My main language is Java although I'm currently trying to branch out a little and try out other technologies.