1 16 package org.jmanage.core.modules.weblogic; 17 18 import org.jmanage.core.management.ServerConnection; 19 import org.jmanage.core.management.ConnectionFailedException; 20 import org.jmanage.core.management.ServerConnectionFactory; 21 import org.jmanage.core.config.ApplicationConfig; 22 import weblogic.management.MBeanHome; 23 24 import javax.naming.NamingException ; 25 import javax.naming.Context ; 26 import javax.naming.InitialContext ; 27 import java.util.Hashtable ; 28 29 34 public class WLServerConnectionFactory implements ServerConnectionFactory{ 35 36 40 public ServerConnection getServerConnection(ApplicationConfig config) 41 throws ConnectionFailedException { 42 43 try { 44 MBeanHome home = findExternal(config.getURL(), config.getUsername(), 45 config.getPassword()); 46 return new WLServerConnection(home.getMBeanServer()); 47 } catch (Throwable e) { 48 throw new ConnectionFailedException(e); 49 } 50 } 51 52 private static MBeanHome findExternal(String url, 53 String username, 54 String password) 55 throws NamingException { 56 57 Hashtable props = new Hashtable (); 58 props.put(Context.INITIAL_CONTEXT_FACTORY, 59 "weblogic.jndi.WLInitialContextFactory"); 60 props.put(Context.PROVIDER_URL, url); 61 props.put(Context.SECURITY_PRINCIPAL, username); 62 props.put(Context.SECURITY_CREDENTIALS, password); 63 Context ctx = new InitialContext (props); 64 MBeanHome home = (MBeanHome) ctx.lookup(MBeanHome.JNDI_NAME + "." + 65 "localhome"); 66 ctx.close(); 67 return home; 68 } 69 70 } 71 | Popular Tags |