Access WebSphere Variables in J2EE Applications
Accessing WebSphere Variables from inside your J2EE application isn't as easy as it looks. They're not environment variables or system properties, but a portion of the WebSphere configuration that is used by the WebSphere Application Server Runtime.
You can access these variables by invoking an operation on "AdminOperations" MBean as follows:
try
{
AdminService adminService = AdminServiceFactory.getAdminService();
ObjectName queryName = new ObjectName( "WebSphere:*,type=AdminOperations" );
Set objs = adminService.queryNames( queryName, null );
if ( !objs.isEmpty() )
{
ObjectName thisObj = (ObjectName)objs.iterator().next();
String opName = "expandVariable";
String signature[] = { "java.lang.String" };
String params[] = { "${VARIABLE_NAME}" } ;
Object retVal = adminService.invoke( thisObj, opName, params, signature );
System.out.println( retVal );
}
} catch (MalformedObjectNameException e) {
e.printStackTrace();
} catch (InstanceNotFoundException e) {
e.printStackTrace();
} catch (MBeanException e) {
e.printStackTrace();
} catch (ReflectionException e) {
e.printStackTrace();
}
This code will only work from an application running inside the server.
blog comments powered by Disqus