Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting the Application Name

93 views
Skip to first unread message

shelle...@cerner.com

unread,
Jan 6, 2009, 6:13:43 PM1/6/09
to
Is there any way to retrieve an application's name at runtime within the application (EAR)? For example, via JNDI context or some other means?

Ken Hygh

unread,
Jan 7, 2009, 7:32:44 AM1/7/09
to
shelle...@cerner.com wrote:
> Is there any way to retrieve an application's name at runtime within the application (EAR)? For example, via JNDI context or some other means?
>
ServletContext appears to have attributes
com.ibm.websphere.servlet.enterprise.application.name
and
com.ibm.websphere.servlet.application.name

Ken

bob.c...@fil.com

unread,
Jan 7, 2009, 7:37:39 AM1/7/09
to
Hi,
not sure if this is the answer you're looking for but you can get a list of installed applications from a WAS instance using wsadmin as follows

$WAS_INSTALL_ROOT/bin/wsadmin.sh -user -password -c '$AdminApp list'

Hope this helps

Bob

shelle...@cerner.com

unread,
Jan 7, 2009, 11:59:37 AM1/7/09
to
Thank you for the response, but I am actually looking for the name of the current running application from within the application itself.

anthon...@bnpparibas.com

unread,
Mar 4, 2009, 6:27:18 AM3/4/09
to
Hi!

I'm also interested in getting the application name: Shelley, did you find how to sort this out? FYI, my target is to check, from my application itself, if WebSphere configuration is okay (in my very particular case, if session management setup has been rightly configured and otherwise, to raise a warning during application startup).

I think this could be feasible, thanks to the com.ibm.websphere.management.configservice.ConfigService, but I need to know the deployed application name before calling ConfigService.resolve() method.

shelle...@cerner.com

unread,
Mar 4, 2009, 10:54:58 AM3/4/09
to
As of 6.1.0.21, there is not a standard means for obtaining the application name, and I don't think there is currently a way to do this in WAS 7.0 yet either.

To work around this, I have been inspecting the path returned by a known resource's URL. Something similar to the following:

{code}
final URL url = getClass().getResource(getClass().getSimpleName() + ".class");
{code}

Assuming this class is being loaded from the application or module class loader (as opposed to the extensions class loader, for instance) [1], and that WebSphere's ClassLoader implementations consistently load resources from the application installation directory [2], you can generally determine the name of the application.

It's not ideal and makes some assumptions about WAS's internal ClassLoader implementations (ie: how getResource() is implemented), but +so far+ seems to do the trick. I've started discussing this a bit with IBM, and hope that they might introduce such a feature since this request doesn't seem that uncommon (nor, I would think, difficult to implement).

[1] http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.nd.doc/info/ae/ae/crun_classload.html
[2] http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/urun_rapp_installoptions.html

anthon...@bnpparibas.com

unread,
Mar 4, 2009, 11:37:48 AM3/4/09
to
Thanks a lot for your answer. I've dug a little bit and I've found something interesting: if you use JSP, instantiated ServletConfig "config" object may help:

You can use the debugger to get a list of valid attributes. But one more time, it makes an assumption on internal WebSphere mechanism.

shelle...@cerner.com

unread,
Mar 4, 2009, 2:32:56 PM3/4/09
to
Thanks for sharing your finding. Unfortunately, my code may not be executed within a servlet container, so I can't rely on any ServletContext attributes.

mihail.f...@sap.com

unread,
Mar 4, 2009, 3:57:23 PM3/4/09
to
You may try to use WebSphere Management APIs
IBM WebSphere Developer Technical Journal has a caple of "System management for WebSphere Application Server" articles demonstrating how to use the com.ibm.websphere.management classes.

For example:
IBM WebSphere Developer Technical Journal: System Administration for WebSphere Application Server V5
Part 2 -- Writing Your Own Administration Programs
http://www.ibm.com/developerworks/websphere/techjournal/0302_cundiff/cundiff.html

The code below lists all applications deployed on the WAS

//obtain config service
ConfigService configService = ...

ObjectName objName = ConfigServiceHelper.createObjectName(null, "Deployment",null);
ObjectName[] objNames = configService.queryConfigObjects(session,null,objName ,null);

for (int i=0; iobjNames.length;i++){
String appName = objNames.getKeyProperty(SystemAttributes._WEBSPHERE_CONFIG_DATA_DISPLAY_NAME);
System.out.println("Application: "+appName);
}

Ken Hygh

unread,
Mar 4, 2009, 4:30:31 PM3/4/09
to
shelle...@cerner.com wrote:
> Thanks for sharing your finding. Unfortunately, my code may not be executed within a servlet container, so I can't rely on any ServletContext attributes.

Could you write one auto-start servlet that doesn't have any doXXX()
methods, just an init() that grabs something from the context and shoves
it into the System properties?

If not, where will your code be executing?

Ken

shelle...@cerner.com

unread,
Mar 4, 2009, 5:48:45 PM3/4/09
to
Thanks for the idea, but that does not get the name of the current application from within which my code is running. There are several ways to obtain the list of installed applications (the easiest way I've found is to use AppManagement.listApplications() [1]), but I am interested in obtaining the name of the +current+ application from within the application itself.

[1] http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/management/application/AppManagement.html

0 new messages