1 16 17 package org.springframework.jmx.support; 18 19 import java.lang.reflect.InvocationTargetException ; 20 21 import javax.management.MBeanServer ; 22 23 import org.springframework.beans.factory.FactoryBean; 24 import org.springframework.beans.factory.InitializingBean; 25 import org.springframework.jmx.MBeanServerNotFoundException; 26 27 58 public class WebLogicMBeanServerFactoryBean implements FactoryBean, InitializingBean { 59 60 private static final String WEBLOGIC_JMX_HELPER_CLASS = "weblogic.management.Helper"; 61 62 private static final String GET_MBEAN_HOME_METHOD = "getMBeanHome"; 63 64 private static final String GET_MBEAN_SERVER_METHOD = "getMBeanServer"; 65 66 67 private String username = "weblogic"; 68 69 private String password = "weblogic"; 70 71 private String serverUrl = "t3://localhost:7001"; 72 73 private String serverName = "server"; 74 75 private MBeanServer mbeanServer; 76 77 78 82 public void setUsername(String username) { 83 this.username = username; 84 } 85 86 90 public void setPassword(String password) { 91 this.password = password; 92 } 93 94 98 public void setServerUrl(String serverUrl) { 99 this.serverUrl = serverUrl; 100 } 101 102 106 public void setServerName(String serverName) { 107 this.serverName = serverName; 108 } 109 110 111 public void afterPropertiesSet() throws MBeanServerNotFoundException { 112 try { 113 116 Class helperClass = getClass().getClassLoader().loadClass(WEBLOGIC_JMX_HELPER_CLASS); 117 Class [] argTypes = new Class [] {String .class, String .class, String .class, String .class}; 118 Object [] args = new Object [] {this.username, this.password, this.serverUrl, this.serverName}; 119 Object mbeanHome = helperClass.getMethod(GET_MBEAN_HOME_METHOD, argTypes).invoke(null, args); 120 121 124 this.mbeanServer = (MBeanServer ) 125 mbeanHome.getClass().getMethod(GET_MBEAN_SERVER_METHOD, null).invoke(mbeanHome, null); 126 } 127 catch (ClassNotFoundException ex) { 128 throw new MBeanServerNotFoundException("Could not find WebLogic's JMX Helper class", ex); 129 } 130 catch (InvocationTargetException ex) { 131 throw new MBeanServerNotFoundException( 132 "WebLogic's JMX Helper.getMBeanHome/getMBeanServer method failed", ex.getTargetException()); 133 } 134 catch (Exception ex) { 135 throw new MBeanServerNotFoundException( 136 "Could not access WebLogic's JMX Helper.getMBeanHome/getMBeanServer method", ex); 137 } 138 } 139 140 141 public Object getObject() { 142 return this.mbeanServer; 143 } 144 145 public Class getObjectType() { 146 return (this.mbeanServer != null ? this.mbeanServer.getClass() : MBeanServer .class); 147 } 148 149 public boolean isSingleton() { 150 return true; 151 } 152 153 } 154 | Popular Tags |