Skip to main content

Accessing Glassfish configuration values from domain.xml

Please note these forums are being decommissioned and use the new and improved forums at
7 replies [Last post]
Joined: 2010-06-11

I want to create an application-server-agnostic configuration service which provides common configuration values to our applications and services.

In JBoss I managed to do so using their Model Controller service; executing appropriate cli commands in order to obtain the values; host name, http port, https port, etc.

I see some of the Glassfish values are accessible as System properties in Glassfish, but still some important ones, like http port, https port, jms port, and clustering bind address are not.

Is there a service available at runtime which I can use to query such values ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-06-11

Having looked into the details of the response, I was lucky enough to find a way of bypassing the REST interface and going direct to the org.glassfish.embeddable.CommandRunner HK2 Service.

To get hold of it I needed to first get hold of the org.glassfish.hk2.api.ServiceLocator from the OSGi Registry. I'm doing that part with blueprint.

Then with the locator, I can get the CommandRunner, and execute a get operation with any relevant dotted property
name (I used asadmin get * to find out the whole list)

<br />
            CommandRunner cr = locator.getService(CommandRunner.class, new Annotation[0]);<br />
            // get the https port<br />
            final CommandResult response ="get", "");</p>
<p>            ExitStatus outcome = null;<br />
            if (response != null) {<br />
                        outcome = response.getExitStatus();<br />
<p>            if (outcome == ExitStatus.SUCCESS) {<br />
                        // parse the response output to get the actual value<br />
                        String[] lines = response.getOutput().split("\\n");<br />
                        String[] kvPair = lines[1].split("=");<br />
                        // Obtain the value in the K=V pair<br />
                        return kvPair[1];<br />
            }<br />

I got the formatting help from this link

Joined: 2005-03-30

Bear in mind that this approach relies on numerous unpublished, internal, and undocumented techniques that are not guaranteed to work in the future.

It's also fairly heavyweight to create a new CommandRunner, submit a command to it, have it parse and process the command, etc.

Another possibility would be to build your code as an OSGi module that depends on the config API module in GlassFish. Your module would then be able to use @Inject one or more configuration items of interest, from which it could either directly get the values you need or navigate from those to the values you need. For example,

private Domain domain

gives the code access to the top-level element, from which it can navigate anywhere it needs to.

Now, having said that, the config API is itself not an officially supported interface any more than CommandRunner, but realistically it's probably less likely to change (since it directly reflects the structure of domain.xml).

And this approach will be much more efficient. If you're going to use one unpublished interface or another you might as well consider the faster one!

- Tim

Joined: 2010-06-11

Hi Tim,

Valid point.

Currently I am deploying my configuration service OSGi bundle to the Felix FileInstall location domain1/autodeploy/bundles.

Are you saying that by simply deploying my OSGi bundle to the modules/autostart folder, I then have an OSGi module and can start to use the @inject annotation ?



Joined: 2012-01-02

perhaps with the REST admin interfaces ?

Joined: 2010-06-11


Thanks for the quick response. It's much appreciated.

I knew of the REST interface, I just didn't consider it for the task as an appropriate inVM option.

Is there a surefire way of knowing when the Glassfish server is fully started and ready ? Would I mark my service as a Life Cycle Module to get the notification events, or is there another inVM mechanism ?

Joined: 2007-01-03


You can use the get, list and set subcommands to navigate the GlassFish
Server configuration data and access configuration data values.

For details, see:

* How Dotted Names Work for Configuration

in the GlassFish Server Administration Guide
* get

in the GlassFish Server Reference Manual
* list

in the GlassFish Server Reference Manual
* set

in the GlassFish Server Reference Manual

Hope this helps.
-Paul Davies

On 8/5/2013 9:47 AM, wrote:
> Hi, perhaps with the REST admin interfaces ?
> --
> [Message sent by forum member 'usul_']
> View Post:

Joined: 2010-06-11

Thanks Paul. I'll have a look...