Index Changes
ESB Console Home

Test Logger Configuration - for Runtime and Components In Java


package org.glassfish.extended.management.sample.impl.configuration;

import com.sun.esb.management.common.ManagementRemoteException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
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.ExtendedManagementRemoteException;
import org.glassfish.openesb.management.ServerConnectionFactory;

/**
 *
 * @author gopalan
 */
public class TestLoggerConfiguration {

    /**
     * @param args
     */
    public static void main(String[] args) {
        String hostName = ServerConnectionFactory.LOCALHOST;
        String userName = ServerConnectionFactory.ADMIN_USERNAME;
        String password = ServerConnectionFactory.ADMINADMIN_PASSWORD;
        int portNumber = ServerConnectionFactory.RMI_ADMIN_PORT;
        String targetName = ServerConnectionFactory.SERVER_TARGET;
        ExtendedManagementClient client = null;
        ExtendedConfigurationService configurationService = null;
        ExtendedAdministrationService administrationService = null;
        boolean isJBIRuntimeEnabled = false;
        String serviceEngineName = "sun-bpel-engine";
        //String bindingComponentName = "gestalt-rss-binding";
        String bindingComponentName = "sun-http-binding";
        
        Properties properties = null;
        Properties keyValuePairs = new Properties();

        String componentName = bindingComponentName, targetInstanceName = targetName;
        String runtimeLoggerName = "com.sun.jbi.messaging"; // "runtime-logger"
        String loggerCustomName = "com.sun.jbi.sun-http-binding.com.sun.jbi.httpsoapbc.proxy.HttpProxy";
        String displayName = "";
        Level loggerLevel = Level.INFO;
        Map<String, String> displayNameMap = null;
        Map<String, Level> displayNameStringToLevelMap = null;
        try {
            client = ExtendedManagementClientFactory.getInstance(hostName, portNumber, userName, password);
        } catch (ExtendedManagementRemoteException ex) {
            Logger.getLogger(TestApplicationVariables.class.getName()).log(Level.SEVERE, null, ex);
        }
        administrationService = client.getService(ExtendedAdministrationService.class);
        try {
            isJBIRuntimeEnabled = administrationService.isJBIRuntimeEnabled();
        } catch (ManagementRemoteException ex) {
            Logger.getLogger(TestApplicationVariables.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (true == isJBIRuntimeEnabled) {
            System.out.println("The JBI Framework is Enabled");
            configurationService = client.getService(ExtendedConfigurationService.class);
            if (configurationService != null) {
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getComponentLoggerDisplayNames(componentName, targetName, targetInstanceName)");
                    displayNameMap = configurationService.getComponentLoggerDisplayNames(componentName, targetName, targetInstanceName);
                    Set<Entry<String, String>> entries = displayNameMap.entrySet();
                    for (Map.Entry<String, String> entry : entries) {
                        String key = entry.getKey();
                        String value = entry.getValue();
                        System.out.println(key + " = " + value);
                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getComponentLoggerLevels(componentName, targetName, targetInstanceName)");
                    displayNameStringToLevelMap = configurationService.getComponentLoggerLevels(componentName, targetName, targetInstanceName);
                    Set<Entry<String, Level>> entries = displayNameStringToLevelMap.entrySet();
                    for (Map.Entry<String, Level> entry : entries) {
                        String key = entry.getKey();
                        Level value = entry.getValue();
                        System.out.println(key + " = " + value);
                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerDisplayName(runtimeLoggerName, targetName)");
                    displayName = configurationService.getRuntimeLoggerDisplayName(runtimeLoggerName, targetName);
                    System.out.println(displayName);
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerDisplayName(runtimeLoggerName, targetName, targetInstanceName)");
                    displayName = configurationService.getRuntimeLoggerDisplayName(runtimeLoggerName, targetName, targetInstanceName);
                    System.out.println(displayName);
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerLevel(runtimeLoggerName, targetName)");
                    loggerLevel = configurationService.getRuntimeLoggerLevel(runtimeLoggerName, targetName);
                    System.out.println(loggerLevel);
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerLevel(runtimeLoggerName, targetName, targetInstanceName)");
                    loggerLevel = configurationService.getRuntimeLoggerLevel(runtimeLoggerName, targetName, targetInstanceName);
                    System.out.println(loggerLevel);
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerLevels(targetName)");
                    displayNameStringToLevelMap = configurationService.getRuntimeLoggerLevels(targetName);
                    Set<Entry<String, Level>> entries = displayNameStringToLevelMap.entrySet();
                    for (Map.Entry<String, Level> entry : entries) {
                        String key = entry.getKey();
                        Level value = entry.getValue();
                        System.out.println(key + " = " + value);
                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    displayNameStringToLevelMap = configurationService.getRuntimeLoggerLevels(targetName, targetInstanceName);
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerLevels(targetName, targetInstanceName)");
                    Set<Entry<String, Level>> entries = displayNameStringToLevelMap.entrySet();
                    for (Map.Entry<String, Level> entry : entries) {
                        String key = entry.getKey();
                        Level value = entry.getValue();
                        System.out.println(key + " = " + value);
                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerNames(targetName)");
                    displayNameMap = configurationService.getRuntimeLoggerNames(targetName);
                    Set<Entry<String, String>> entries = displayNameMap.entrySet();
                    for (Map.Entry<String, String> entry : entries) {
                        String key = entry.getKey();
                        String value = entry.getValue();
                        System.out.println(key + " = " + value);
                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerNames(targetName, targetInstanceName)");
                    displayNameMap = configurationService.getRuntimeLoggerNames(targetName, targetInstanceName);
                    Set<Entry<String, String>> entries = displayNameMap.entrySet();
                    for (Map.Entry<String, String> entry : entries) {
                        String key = entry.getKey();
                        String value = entry.getValue();
                        System.out.println(key + " = " + value);
                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking setComponentLoggerLevel(componentName, loggerCustomName, Level.WARNING, targetName, targetInstanceName)");
                    configurationService.setComponentLoggerLevel(componentName, loggerCustomName, (loggerLevel.equals(Level.INFO)?Level.WARNING:Level.INFO), targetName, targetInstanceName);
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking setRuntimeLoggerLevel(runtimeLoggerName, Level.WARNING, targetName)");
                    configurationService.setRuntimeLoggerLevel(runtimeLoggerName, (loggerLevel.equals(Level.INFO)?Level.WARNING:Level.INFO), targetName);
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking setRuntimeLoggerLevel(runtimeLoggerName, Level.WARNING, targetName, targetInstanceName)");
                    configurationService.setRuntimeLoggerLevel(runtimeLoggerName, (loggerLevel.equals(Level.INFO)?Level.WARNING:Level.INFO), targetName, targetInstanceName);
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getRuntimeLoggerLevel(runtimeLoggerName, targetName)");
                    loggerLevel = configurationService.getRuntimeLoggerLevel(runtimeLoggerName, targetName);
                    System.out.println(loggerLevel);
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("////////////////////////////////////");
                    System.out.println("Invoking getComponentLoggerLevels(componentName, targetName, targetInstanceName)");
                    displayNameStringToLevelMap = configurationService.getComponentLoggerLevels(componentName, targetName, targetInstanceName);
                    Set<Entry<String, Level>> entries = displayNameStringToLevelMap.entrySet();
                    for (Map.Entry<String, Level> entry : entries) {
                        String key = entry.getKey();
                        Level value = entry.getValue();
                        System.out.println(key + " = " + value);
                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestLoggerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}






Number of visits: 3

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-1) was last changed on 09-Nov-09 08:53 AM, -0800 by Gopalan Suresh Raj