This is a little step by step guide on how to create and register custom service with JMX interface on WebSphere:
[java]
com.ibm.websphere.runtime.CustomService
com.ibm.websphere.management.JMXManageable
[/java]
This method has a parameter, Properties, which will contain properties defined via WS Administration console. We are interested in one property: externalConfigURLKey. This property contains path to external configuration file (if any is needed).
This is how to get the path:
[java]
public void initialize(Properties configProperties) throws Exception { readConfig(configProperties.getProperty(externalConfigURLKey)); }
[/java]
shutdown() method may be left blank.
implement getType() method (inherited from JMXManageable):
[java]
public String getType() { return "MyMBean"; }
[/java]
Remember the name you returned here!
[java]
public Properties getMBeanProperties() { Properties props = new Properties(); props.put("SpecialProperty", "value"); return props; }
[/java]
I think this will return a list of properties, not declared in MBean descriptor. Read only, of course, since there is no setMBeanProperties() method.
[java]
public String getUserName() { return this.userName; }
public void setUserName(String param) { this.userName = param; }
[/java]
[xml]
[/xml]
IMPORTANT: Make sure that type matches the value you remembered on the step 4!
Compile and package. Create .jar, having descriptor in the root. Place .jar somewhere accesible for WebSphere.
Start WebSphere and open Administration console.
Go to Servers - Application Servers - yourserver - Server Infrastructure - Administration - Administration Services
Click on "Extension MBean providers"
Click on "New"
In the "Classpath" entry type the full path and name of your jar (created on step 8)
Type something memorable in two other fields and click Apply.
Click on "Extension MBeans" (on the left)
Click on "New"
Enter the name of MBean descriptor file (see step 7.)
for example:
myTest.xml
Enter the type name of your MBean. IMPORTANT: must be the same name as it was on steps 4 and 7.
Click Apply.
Go to Servers - Application Servers - yourserver - Server Infrastructure - Administration - Custom Services
Click New
Place check on "Enable service at server startup".
Enter full class name (with package) of your MBean class (the one we created on step 1) into "Classname" field.
Enter something memorable in "Display Name"
Enter fill path and file name of the jar file (step 8) into "Classpath".
If your service requires configuration file (step 2) enter full path to it into " External Configuration URL"
Click on Apply.
Click on Save (on top)
Click Save.
Restart the server.
Here are the commands, used to verify MBean from admin console:
To run console:
wsadmin.bat -conntype SOAP -port 8881
To make sure that MBean started:
$AdminControl queryNames :,type=>
Store MBean in Tcl variable:
set mybean [$AdminControl queryNames :,type=MBeanName]
See MBean description:
$Help all $mybean
See MBean attributes and values:
$AdminControl getAttributes $mybean
Set specific attribute:
$AdminControl setAttribute $mybean UserName mike