package fr.ippon.groovy.util; import java.io.IOException; import java.net.MalformedURLException; import java.util.Hashtable; import javax.management.JMException; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.naming.Context; /** * Classe utilitaire permettant de récupérer simplement une référence à un des MBeans racines de WebLogic * sous forme de {@link GroovierMBean} * * @author Fabien Arrault */ public class WebLoMBean { /** * * @param urlBase * url du serveur (ex : t3://localhost:7001 ) * @param user * @param password * @return * @throws JMException * @throws IOException */ public static GroovierMBean getRuntimeServiceMBean(String urlBase, String user, String password) throws JMException, IOException { MBeanServerConnection server = getRuntimeMBeanServer(urlBase, user, password); ObjectName domainName = new ObjectName( "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean"); return new GroovierMBean(server, domainName); } public static GroovierMBean getRuntimeServiceMBean(MBeanServerConnection server) throws JMException, IOException { ObjectName domainName = new ObjectName( "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean"); return new GroovierMBean(server, domainName); } public static MBeanServerConnection getRuntimeMBeanServer(String urlBase, String user, String password) throws MalformedURLException, IOException { String urlRuntime = "/jndi/weblogic.management.mbeanservers.runtime"; return getMBeanServer("service:jmx:" + urlBase + urlRuntime, user, password); } // Domain : public static GroovierMBean getDomainMBean(String urlBase, String user, String password) throws IOException, JMException { MBeanServerConnection server = getDomainMBeanServer(urlBase, user, password); ObjectName domainName = new ObjectName( "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean"); return new GroovierMBean(server, domainName); } public static MBeanServerConnection getDomainMBeanServer(String urlBase, String user, String password) throws MalformedURLException, IOException { String urlRuntime = "/jndi/weblogic.management.mbeanservers.domainruntime"; return getMBeanServer("service:jmx:" + urlBase + urlRuntime, user, password); } // -- public static MBeanServerConnection getMBeanServer(String url, String user, String password) throws MalformedURLException, IOException { JMXServiceURL serviceURL = new JMXServiceURL(url); Hashtable h = new Hashtable(); h.put(Context.SECURITY_PRINCIPAL, user); h.put(Context.SECURITY_CREDENTIALS, password); h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h); MBeanServerConnection server = connector.getMBeanServerConnection(); return server; } }