Skip to main content

How do I programmatically access the Glassfish domain from a webapplication?

2 replies [Last post]
8086
Offline
Joined: 2011-03-25
Points: 0

I do a bit of logging in a ServletFilter to log which web services are being called, response times, etc, and I would ideallly like to log the domain name of the running Glassfish server. But so far I have not been able to come up with any way of programmatically access this info.
Do any of you know of a way to access this info from the currently running web application?
org.glassfish.admin.amx.base.DomainRoot seems to have some methods that might give some info, but I have no idea on what classes implement these interfaces. And I have no experience with AMX what so ever, so for all I know these methods might not even exist for end-user usage.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tmueller
Offline
Joined: 2005-10-31
Points: 0

What version of GlassFish are you using?

In version 3.1, servlets cannot access the internal GlassFish classes
unless there is a special configuration change made to the
default-web.xml file. An alternative to doing this is the following:

for each domain, run the following command:

asadmin create-system-properties --target domain domainName=domain1

where "domain1" is the name of the domain.

Then, from your code, do:

System.getProperty("domainName")

to get the name of the domain.

If you don't want to create your own property, there are several
GlassFish provided properties, such as "com.sun.aas.instanceRoot" that
contain the domain name, but it would have to be parsed out of the
value. For example:

new File(System.getProperty("com.sun.aas.instanceRoot")).getName()

Tom

On 3/25/2011 7:27 AM, forums@java.net wrote:
> I do a bit of logging in a ServletFilter to log which web services are
> being
> called, response times, etc, and I would ideallly like to log the
> domain name
> of the running Glassfish server. But so far I have not been able to
> come up
> with any way of programmatically access this info.
>
> Do any of you know of a way to access this info from the currently
> running
> web application?
>
> org.glassfish.admin.amx.base.DomainRoot [1] seems to have some methods
> that
> might give some info, but I have no idea on what classes implement these
> interfaces. And I have no experience with AMX what so ever, so for all I
> know these methods might not even exist for end-user usage.
>
>
> [1]
> http://javadoc.glassfish.org/v3/apidoc/org/glassfish/admin/amx/base/Doma...
>
> --
>
> [Message sent by forum member '8086']
>
> View Post: http://forums.java.net/node/785169
>
>

8086
Offline
Joined: 2011-03-25
Points: 0

I ended up doing the following:

String instanceName = System.getProperty("com.sun.aas.instanceName");
String[] tmp = instancename.split("/");
String domain = tmp[tmp.length-1]<br />