Index Changes
ESB Console Home

Test Application Configuration In Java


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

import com.sun.esb.management.common.ManagementRemoteException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.openmbean.CompositeType;
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 TestApplicationConfiguration {

    /**
     * @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;
        String componentName = "sun-http-binding";
        String myConfigObjectKey = "myConfigObjectKey";
        Properties configValues = new Properties();

        configValues.put("configurationName", "myConfigObject");
        configValues.put("httpUrlLocation", "http://locahost:12345/foo");

        ExtendedManagementClient client = null;
        try {
            client = ExtendedManagementClientFactory.getInstance(hostName, portNumber, userName, password);
        } catch (ExtendedManagementRemoteException ex) {
            Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
        }
        ExtendedAdministrationService administrationService = client.getService(ExtendedAdministrationService.class);
        boolean isJBIRuntimeEnabled = false;
        try {
            isJBIRuntimeEnabled = administrationService.isJBIRuntimeEnabled();
        } catch (ManagementRemoteException ex) {
            Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (isJBIRuntimeEnabled) {
            System.out.println("The JBI Framework is Enabled");
            ExtendedConfigurationService configurationService = client.getService(ExtendedConfigurationService.class);
            if (configurationService != null) {
                boolean isAppConfigSupported = false;
                try {
                    System.out.println("Invoking isAppConfigSupported ...");
                    isAppConfigSupported = configurationService.isAppConfigSupported(componentName, targetName);
                    System.out.println("Application Configuration is" + (isAppConfigSupported ? "" : " NOT") + " supported");
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (isAppConfigSupported) {

                    try {
                        System.out.println("Invoking queryApplicationConfigurationType ...");
                        CompositeType aCompositeType = configurationService.queryApplicationConfigurationType(componentName, targetName);
                        System.out.println(aCompositeType);
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    try {
                        System.out.println("Invoking addApplicationConfiguration ...");
                        configurationService.addApplicationConfiguration(componentName, targetName, myConfigObjectKey, configValues);
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    try {
                        System.out.println("Invoking listApplicationConfigurationNames ...");
                        String[] configurationNames = configurationService.listApplicationConfigurationNames(componentName, targetName);
                        if (configurationNames != null) {
                            for (String aName : configurationNames) {
                                System.out.println(aName);
                            }
                        }
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    try {
                        System.out.println("Invoking getApplicationConfiguration ...");
                        Properties properties = configurationService.getApplicationConfiguration(componentName, targetName, myConfigObjectKey);
                        if (properties != null) {
                            Enumeration anEnumeration = properties.propertyNames();
                            while (anEnumeration.hasMoreElements()) {
                                String key = (String) anEnumeration.nextElement();
                                System.out.println(key + ": " + properties.getProperty(key));
                            }
                        }
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                    }


                    try {
                        System.out.println("Invoking getApplicationConfigurations ...");
                        Map<String, Properties> configNameToValues = configurationService.getApplicationConfigurations(componentName, targetName);
                        for (Properties properties : configNameToValues.values()) {
                            Enumeration anEnumeration = properties.propertyNames();
                            while (anEnumeration.hasMoreElements()) {
                                String key = (String) anEnumeration.nextElement();
                                System.out.println(key + ": " + properties.getProperty(key));
                            }
                        }
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    try {
                        System.out.println("Invoking deleteApplicationConfiguration ...");
                        configurationService.deleteApplicationConfiguration(componentName, targetName, myConfigObjectKey);
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    try {
                        System.out.println("Invoking getApplicationConfigurations ...");
                        Map<String, Properties> configNameToValues = configurationService.getApplicationConfigurations(componentName, targetName);
                        for (Properties properties : configNameToValues.values()) {
                            Enumeration anEnumeration = properties.propertyNames();
                            while (anEnumeration.hasMoreElements()) {
                                String key = (String) anEnumeration.nextElement();
                                System.out.println(key + ": " + properties.getProperty(key));
                            }
                        }
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestApplicationConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
        }
    }
}





Number of visits: 7

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-2) was last changed on 27-Jan-10 02:33 AM, -0800 by newacct