Monday February 13, 2006 My previous blog entry,"JMX to manage JAX-WS 2.0 service using NetBeans" created an interest in the aquarium community. I have been contacted from underneath the water in order to address the same use case in GlassFish.
I want to say first that it has been a real pleasure to make JMX and JConsole work in the context of GlassFish. Configuring Tomcat to allow JMX remote access by updating the catalina script to enable remote management is quick but a little dirty too.
Let's see what are the necessary steps to achieve the scenario in my previous blog entry.
GlassFish NetBeans integration (if needed)
Simply follow this GlassFish NetBeans IDE integration. Then make the JAX-WS20Project to use the GlassFish installed server.Grant the required permissions to the JAX-WS20Project application to deal with JMX
When dealing with J2EE containers, something that makes a big difference is the security aspect. GlassFish enables Java security by default. All GlassFish deployed applications run with a very limited set of permissions. When management is in the picture, this is really a must.Management can't be understood outside of a secured context. Management actions are generally so critical that they make sense only in a fully secured context.
This being said, let's grant the application code base the required permissions. In order to find out your application's codebase, start the Glassfish Management console, select the JAX-WS20Project application. The code base is the value of the Location property.
The following picture shows you the administration view of the JAX-WS20Project application.
Granting permission in GlassFish, is explained very well in the Securing GlassFish applications article.
A single step is needed :
grant codeBase "file:In this grant block we listed the set of required permissions in order to access the platform MBeanServer, register an MBean instance of class/-" { // Allow access to ManagementFactory.getPlatformMBeanServer() permission javax.management.MBeanServerPermission "createMBeanServer"; //Permission to register our MBean permission javax.management.MBeanPermission "my.sample.server.HelloPrefixProvider#-[server.sample.my:type=HelloPrefixProvider]", "registerMBean"; //Permission to get HelloPrefix attribute permission javax.management.MBeanPermission "my.sample.server.HelloPrefixProvider#HelloPrefix[server.sample.my:type=HelloPrefixProvider]", "getAttribute"; };
my.sample.server.HelloPrefixProvider, named server.sample.my:type=HelloPrefixProvider. We also granted the permission to get the MBean attribute HelloPrefix. (If you want to learn more about JMX permissions, see MBeanPermission and MBeanServerPermission
javadoc)
Need to restart GlassFih?
No, you don't need to. The server.policy file will be loaded when your app will be deployed. That is really really cool!Deploy JAX-WS20Project
Simply run the project and send a first request to theHelloService (thanks to the NetBeans Web Service Registry) in order to register the HelloPrefixProvider MBean.
Connecting JConsole
This is my favorite part. It is very simple and very well integrated with the GlassFish management framework. A few years ago I had a really bad time trying to remotely access some JMX MBeans running in AppServer 7...I can tell you that this is now history!
toolbar icon.
HelloPrefixProvider MBean. You can start playing with HelloPrefix attribute.
You noticed the existence of new JMX management domains (amx, amx-support, ias, com.sun.appserver). These nodes contain the set of MBeans that form the GlassFish JMX based management and monitoring framework.
Here we are, we acheived exactly what we did in Tomcat. My feeling is that we did it in a better/cleaner way. We didn't start any new components or hack any scripts. We just reused what was there, ready to serve our needs. Our management solution is also more secure.
Stacking the "Java 2 Somethings"
I hope that you also noticed that not a line of JMX code was changed from theServiceImpl JAX-WS 2.0 service.
When GlassFish is running on top of JDK 5.0 it uses the platform MBeanServer. Deploying your own MBeans in this MBeanServer helps you reuse upper layers (such as J2EE servers) management infrastructure for free. In my first blog entry I tried to explain the power that is brought to your application when relying on a Standard JMX framework. I think that this case helps you understand all the benefits.
Jean-Francois Denise
Just in case you want some more, I added a little chapter in order to optimize your JConsole connection task from NetBeans
Adding a default URL to JConsole
When starting/stopping a GlassFish server, you will need to reconnect JConsole. The NetBeans integration of JConsole comes with a set of Options. One of them allows you to provide a URL to which JConsole will connect when starting.service:jmx:rmi://localhost:28732/jndi/rmi://localhost:28732/jmxrmi
You will notice that credentials are not stored in properties. It is not recommanded that you store such critical information. Each time you will relaunch JConsole, JConsole will connect to the Glassfish server and you will be prompted for user name and password. Posted by jeanfrancoisdenise ( Feb 13 2006, 01:04:07 PM GMT+02:00 ) Permalink
A. Sundararajan
Alan Bateman
Daniel Fuchs
Éamonn McManus
Joël Féraud
Mandy Chung
Luis-Miguel Alventosa