![]() |
package org.glassfish.extended.management.sample.impl.administration.osgi;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import org.glassfish.openesb.extended.management.api.administration.osgi.OSGiAdministrationService;
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.extended.management.common.model.osgi.data.FujiInterceptorInfo;
import org.glassfish.openesb.extended.management.common.model.osgi.data.OSGiBundleInfo;
import org.glassfish.openesb.extended.management.common.model.osgi.data.OSGiConfigInfo;
import org.glassfish.openesb.extended.management.common.model.osgi.data.OSGiServiceInfo;
import org.glassfish.openesb.extended.management.common.model.osgi.data.helper.FujiInterceptorInfoReader;
import org.glassfish.openesb.extended.management.common.model.osgi.data.helper.OSGiBundleInfoReader;
import org.glassfish.openesb.extended.management.common.model.osgi.data.helper.OSGiConfigInfoReader;
import org.glassfish.openesb.extended.management.common.model.osgi.data.helper.OSGiServiceInfoReader;
import org.glassfish.openesb.management.ServerConnectionFactory;
import org.xml.sax.SAXException;
/**
*
* @author gopalan
*/
public class TestExtendedOSGiAdministrationServiceImpl {
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;
ExtendedManagementClient client = null;
try {
client = ExtendedManagementClientFactory.getInstance(hostName, portNumber, userName, password);
OSGiAdministrationService osgiAdministrationService = client.getService(OSGiAdministrationService.class);
String[] bundles = osgiAdministrationService.listAllBundles();
if(bundles != null) {
for(String bundleInfoString : bundles) {
try {
OSGiBundleInfo bundleInfo = OSGiBundleInfoReader.parseFromXMLData(bundleInfoString);
System.out.println(bundleInfo.getDisplayString());
System.out.println("======================");
} catch (SAXException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
String[] configurations = osgiAdministrationService.listConfigurations();
if(configurations != null) {
for(String configurationInfoString : configurations) {
try {
OSGiConfigInfo configInfo = OSGiConfigInfoReader.parseFromXMLData(configurationInfoString);
System.out.println(configInfo.getDisplayString());
System.out.println("======================");
} catch (SAXException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
String[] fujiInterceptorInfos = osgiAdministrationService.listInterceptors();
if(fujiInterceptorInfos != null) {
for(String fujiInterceptorInfoString : fujiInterceptorInfos) {
try {
FujiInterceptorInfo fujiInterceptorInfo = FujiInterceptorInfoReader.parseFromXMLData(fujiInterceptorInfoString);
System.out.println(fujiInterceptorInfo.getDisplayString());
System.out.println("======================");
} catch (SAXException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
bundles = osgiAdministrationService.listOtherBundles();
if(bundles != null) {
for(String bundleInfoString : bundles) {
try {
OSGiBundleInfo bundleInfo = OSGiBundleInfoReader.parseFromXMLData(bundleInfoString);
System.out.println(bundleInfo.getDisplayString());
System.out.println("======================");
} catch (SAXException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
String[] serviceInfos = osgiAdministrationService.listServiceRefs();
if(serviceInfos != null) {
for(String serviceInfoString : configurations) {
try {
OSGiServiceInfo serviceInfo = OSGiServiceInfoReader.parseFromXMLData(serviceInfoString);
System.out.println(serviceInfo.getDisplayString());
System.out.println("======================");
} catch (SAXException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
String bundleId = osgiAdministrationService.stopBundle("20");
System.out.println(bundleId+" Stopped");
System.out.println("Starting "+bundleId);
bundleId = osgiAdministrationService.startBundle("20");
} catch (ExtendedManagementRemoteException ex) {
Logger.getLogger(TestExtendedOSGiAdministrationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
This page (revision-1) was last changed on
21-Sep-09 10:49 AM, -0700
by Gopalan Suresh Raj.
Back to ESB Console Test Extended Osgi Administration Service In Java
