users@glassfish.java.net

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

From: Tom Mueller <tom.mueller_at_oracle.com>
Date: Fri, 25 Mar 2011 09:10:55 -0500

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_at_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/DomainRoot.html
>
> --
>
> [Message sent by forum member '8086']
>
> View Post: http://forums.java.net/node/785169
>
>