Test Extended Configuration Service In Java
package org.glassfish.extended.management.sample.impl.configuration;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import java.util.logging.Level;
import javax.management.ObjectName;
import org.glassfish.openesb.extended.management.api.administration.ExtendedAdministrationService;
import org.glassfish.openesb.extended.management.api.configuration.ExtendedConfigurationService;
import org.glassfish.openesb.extended.management.client.ExtendedManagementClient;
import org.glassfish.openesb.extended.management.client.ExtendedManagementClientFactory;
import org.glassfish.openesb.extended.management.common.jbi.ManagementRemoteExceptionProcessor;
import com.sun.esb.management.common.ManagementRemoteException;
import org.glassfish.openesb.management.ServerConnectionFactory;
/**
* @author graj
*
*/
public class TestExtendedConfigurationServiceImpl {
/**
*
*/
public TestExtendedConfigurationServiceImpl() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
String hostName = ServerConnectionFactory.LOCALHOST,
userName = ServerConnectionFactory.ADMIN_USERNAME,
password = ServerConnectionFactory.ADMINADMIN_PASSWORD;
int portNumber = ServerConnectionFactory.RMI_ADMIN_PORT;
String targetName = ServerConnectionFactory.SERVER_TARGET;
String engine = "sun-bpel-engine";
String binding = "sun-http-binding";
try {
ExtendedManagementClient client = null;
client = ExtendedManagementClientFactory.getInstance(hostName, portNumber, userName, password);
ExtendedAdministrationService administrationService = client.getService(ExtendedAdministrationService.class);
boolean isJBIRuntimeEnabled = administrationService.isJBIRuntimeEnabled();
if (isJBIRuntimeEnabled) {
System.out.println("The JBI Framework is Enabled");
ExtendedConfigurationService configurationService = client.getService(ExtendedConfigurationService.class);
Properties configurationProperties = null;
Enumeration<?> enumeration = null;
// Binding Component Configuration
configurationProperties = configurationService.getComponentConfiguration(binding, targetName);
System.out.println("Configuration for: " + binding);
enumeration = configurationProperties.propertyNames();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = configurationProperties.getProperty(key);
System.out.println(" " + key + "=" + value);
}
if(configurationProperties != null) {
String httpDefaultPortValue = configurationProperties.getProperty("HttpDefaultPort");
Properties newProperties = new Properties();
if(httpDefaultPortValue != null) {
int httpDefaultPort = Integer.parseInt(httpDefaultPortValue);
if(httpDefaultPort == -1) {
httpDefaultPort = 9080;
}
System.out.println("HttpDefaultPort is: "+httpDefaultPort);
httpDefaultPort++;
newProperties.setProperty("HttpDefaultPort", ""+httpDefaultPort);
}
configurationService.setComponentConfiguration(binding, newProperties, targetName);
System.out.println("New configuration for: " + binding);
configurationProperties = configurationService.getComponentConfiguration(binding, targetName);
enumeration = configurationProperties.propertyNames();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = configurationProperties.getProperty(key);
System.out.println(" " + key + "=" + value);
}
}
// Service Engine Configuration
configurationProperties = configurationService.getComponentConfiguration(engine, targetName);
System.out.println("Configuration for: " + engine);
enumeration = null;
enumeration = configurationProperties.propertyNames();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = configurationProperties.getProperty(key);
System.out.println(" " + key + "=" + value);
}
if(configurationProperties != null) {
String kpiValue = configurationProperties.getProperty("KPIEnabled");
Properties newProperties = new Properties();
if(kpiValue != null) {
boolean isKPIEnabled = Boolean.parseBoolean(kpiValue);
if(!isKPIEnabled) {
newProperties.setProperty("KPIEnabled", "true");
} else {
newProperties.setProperty("KPIEnabled", "false");
}
}
String result = configurationService.setComponentConfiguration(engine, newProperties, targetName);
System.out.println("setComponentConfiguration :"+result);
}
Map<String /* targetInstanceName */, ObjectName[]> extensionMBeanMap = null;
extensionMBeanMap = configurationService.getComponentExtensionMBeanObjectNames(binding,"Configuration", targetName);
System.out.println("Configuration Extension ObjectNames for: "+ binding);
ObjectName[] objectNames = extensionMBeanMap.get(targetName);
for (ObjectName objectName : objectNames) {
System.out.println(" " + objectName);
}
Map<String /* loggerCustomName */, Level /* logLevel */> loggerMap = null;
loggerMap = configurationService.getComponentLoggerLevels(binding, targetName, null);
System.out.println("Custom Logger Levels for: " + binding);
for (Entry<String /* loggerCustomName */, Level /* logLevel */> entry : loggerMap.entrySet()) {
String loggerCustomName = entry.getKey();
Level logLevel = entry.getValue();
System.out.println(" " + loggerCustomName + "="+ logLevel);
}
Properties runtimeConfigProperties = configurationService.getDefaultRuntimeConfiguration();
System.out.println("Default Runtime Configuration:");
enumeration = runtimeConfigProperties.propertyNames();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = runtimeConfigProperties.getProperty(key);
System.out.println(" " + key + "=" + value);
}
runtimeConfigProperties = configurationService.getRuntimeConfiguration(targetName);
System.out.println("Runtime Configuration:");
enumeration = runtimeConfigProperties.propertyNames();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = runtimeConfigProperties.getProperty(key);
System.out.println(" " + key + "=" + value);
}
Properties metadataProperties = configurationService.getRuntimeConfigurationMetaData("autoInstallDir");
System.out.println("Metadata Properties for autoInstallDir:");
enumeration = metadataProperties.propertyNames();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = metadataProperties.getProperty(key);
System.out.println(" " + key + "=" + value);
}
boolean isServerRestartRequired = configurationService.isServerRestartRequired();
System.out.println("Server Restart is "+ (isServerRestartRequired ? "Required.": "NOT required."));
} else {
System.out.println("The JBI Framework is NOT Enabled");
}
} catch (ManagementRemoteException e) {
String result = ManagementRemoteExceptionProcessor.processTaskException(e);
System.out.println(result);
}
}
}
Quick Navigation Links
Number of visits: 4
This page (revision-2) was last changed on
04-Feb-10 19:37 PM, -0800
by newacct.
This page was created on
21-Sep-09 10:01 AM, -0700 by Gopalan Suresh Raj.
More info...
| Version |
Date |
Author |
Size |
Changes ... |
|
2
|
04-Feb-10 19:37 PM, -0800
|
newacct |
10318 |
to previous
|
|
1
|
21-Sep-09 10:01 AM, -0700
|
Gopalan Suresh Raj |
10382 |
to last
|