Is there a simply way using the com.ibm.websphere API to get this path?
Thanks
In the console, look under Environment -> WebSphere Variables.
Brian
private static final int SCOPE_SERVER = 1;
private static final int SCOPE_NODE = 2;
private static final int SCOPE_CELL = 3;
public String getAppServerVariable(String variableName, int scope)
throws Exception
{
String value = null;
ConfigService cs = getConfigService();
Session session = new Session();
try
{
String containmentPath = getContainmentPathByScope(scope);
if(containmentPath==null)
throw new Exception("bad scope");
ObjectName[] onCell = cs.resolve(session, containmentPath);
ObjectName uron = new ObjectName("WebSphere:" +
SystemAttributes._WEBSPHERE_CONFIG_DATA_TYPE
+ "=VariableSubstitutionEntry");
for (int i = 0; i < onCell.length; i++)
{
ObjectName[] configObjects = cs.queryConfigObjects(session,
onCell[i], uron, null);
for (int j = 0; j < configObjects.length; j++)
{
AttributeList currentAttributes =
cs.getAttributes(session, configObjects[j], null, false);
String symbolicName = (String)
ConfigServiceHelper.getAttributeValue(
currentAttributes,
"symbolicName");
if(symbolicName.equals(variableName))
{
value = (String)
ConfigServiceHelper.getAttributeValue(currentAttributes, "value");
break;
}
}
if(value!=null) break;
}
if(value==null)
throw new Exception("value not found");
cs.discard(session);
}
catch (Exception e)
{
throw e;
}
return value;
}
private String getServerContainmentPath()
{
String cell = getServerMBeanProperty("cell");
String node = getServerMBeanProperty("node");
String process= getServerMBeanProperty("process");
StringBuffer containmentPath = new StringBuffer();
containmentPath.append("Cell=").append(cell);
containmentPath.append(":Node=").append(node);
containmentPath.append(":Server=").append(process);
return containmentPath.toString();
}
private String getNodeContainmentPath()
{
String cell = getServerMBeanProperty("cell");
String node = getServerMBeanProperty("node");
StringBuffer containmentPath = new StringBuffer();
containmentPath.append("Cell=").append(cell);
containmentPath.append(":Node=").append(node);
return containmentPath.toString();
}
private String getCellContainmentPath()
{
String cell = getServerMBeanProperty("cell");
StringBuffer containmentPath = new StringBuffer();
containmentPath.append("Cell=").append(cell);
return containmentPath.toString();
}
private String getContainmentPathByScope(int scope)
{
String cp = null;
if(scope==SCOPE_CELL)
cp = getCellContainmentPath();
if(scope==SCOPE_NODE)
cp = getNodeContainmentPath();
if(scope==SCOPE_SERVER)
cp = getServerContainmentPath();
return cp;
}
private String getServerMBeanProperty(String name)
{
String value = null;
try
{
// Here you need the WAS AdminClient or AdminService
ObjectName objectName = _adminClient.getServerMBean();
// ObjectName objectName = _adminService.getLocalServer();
value = objectName.getKeyProperty(name);
}
catch (Exception e)
{
System.err.println("error during getServerMBeanProperty");
}
return value;
}
<Sumit_...@bcbst.com> wrote in message
news:1298219762.118591510...@ltsgwas009.sby.ibm.com...
I have the same need as the submitter of the original message ? getting the location of the standard log directory for my profile/server within a Servlet/SOAP application. I prefer not to use WAS environment variables or configuration file fields because the application is hosted in the production environment by an external team ? this could add a new variable in production problem determination. I use a WebSphere Application Server V5.1.1 with Cumulative Fix 13, running under AIX operating system.
I tried to run your code but I always get null from the CONFIGSERVICEFACTORY.GETCONFIGSERVICE() call. I found out from the IBM Software Group pages that there is a bug in this API, described at APAR #PK31314 (http://www-1.ibm.com/support/docview.wss?uid=swg1PK31314). In the same page it is said that the fix is available within WAS V5.1.1 Cumulative Fix 13.
I took our development WAS server up to V5.1.1.13 in order to apply the fix. Then I ran the code again and got exactly the same null value.
Are you aware of any other dependency for solving this known bug in the WAS administrative classes ? When you run this code snippet successfully, which WAS version do you use (and also what SO you run WAS under) ?
Any help in this matter will be appreciated,
Marcelo Ito
mi...@br.ibm.com
For whom it may concern, Mark Lewis posted a reply to this post in the developerWorks WAS forum (http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?message=13985866&cat=9&thread=173652&treeDisplayType=threadmode1&forum=266#13985866) that worked just perfectly for me. I am not getting a null ConfigService object anymore.
"Hi Marcelo,
You may need to use the following to get hold of the config service if
not running on a standalone server:
ConfigService configService = ConfigServiceFactory.getConfigService();
if (configService == null)
{
Properties p = new Properties();
p.setProperty("location", "local");
configService = ConfigServiceFactory.createConfigService(true, p);
}
Hope that helps,
Mark."