GlassFish : Managing JAX-WS 2.0 services with JMX

In Netbeans 5.0 obviously...

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 :

  • Edit <your domain>/config/server.policy and add the following grant block

    grant codeBase "file:/-" {
    // Allow access to ManagementFactory.getPlatformMBeanServer()
    permission "createMBeanServer";
    //Permission to register our MBean
    permission "my.sample.server.HelloPrefixProvider#-[]", "registerMBean";
    //Permission to get HelloPrefix attribute
    permission "my.sample.server.HelloPrefixProvider#HelloPrefix[]", "getAttribute";
    In this grant block we listed the set of required permissions in order to access the platform MBeanServer, register an MBean instance of class my.sample.server.HelloPrefixProvider, named 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 the HelloService (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!
  • Launch GlassFish Admin Console.
  • Select Configuration/Admin Service/System nodes
  • The JMX Connector configuration is displayed. Among other things, you can see the address, port and protocol that are used in order to establish a connection.

  • Note the port number. 28732 in this example.
  • Launch JConsole from NetBeans. Click on the toolbar icon.
  • In the JConsole Connection Dialog, select the Remote tab.
  • Type in the port number, the admin user and password (admin, adminadmin are default glassfish values)

  • Select the MBeans Tab. Tree node contains 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 the ServiceImpl 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.
NetBeans Options are located under menu Tools > Options . The following window is displayed.

To access the JConsole options, click on the Advanced Options button in the bottom left corner, then select IDE Configuration > Server and External Tools Setting > JConsole. In the Default URL property, provide the full JMXServiceURL. In our case it is :


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.

Post a Comment:
Comments are closed for this entry.



« July 2016