1 23 24 29 30 package com.sun.cli.jmx.spi; 31 32 import java.util.Map ; 33 import java.util.Iterator ; 34 import java.io.IOException ; 35 import javax.management.remote.JMXConnector ; 36 import javax.management.remote.JMXServiceURL ; 37 import com.sun.enterprise.admin.jmx.remote.DefaultConfiguration; 38 import com.sun.enterprise.admin.jmx.remote.SunOneHttpJmxConnectorFactory; 39 import com.sun.cli.jmx.spi.JMXConnectorProvider; 40 41 47 48 public class SunOneHttpProvider implements JMXConnectorProvider { 49 50 public SunOneHttpProvider() { 51 } 52 53 static class Info implements JMXConnectorProviderInfo 54 { 55 private static final String DESCRIPTION = 56 "Implements the SunOne Appserver 8.0 PE connector."; 57 private static final String USAGE = 58 "connect --host <host> --port port --protocol s1ashttp " + 59 "--user <user> --password <pass> [connection-name]"; 60 61 public String 62 getDescription() { 63 return( DESCRIPTION ); 64 } 65 public String 66 getUsage() { 67 return( USAGE ); 68 } 69 } 70 71 public static JMXConnectorProviderInfo 72 getInfo() { 73 return( new Info() ); 74 } 75 76 77 public JMXConnector connect(Map m) throws IOException { 78 final String user = (String ) m.get(DefaultConfiguration.ADMIN_USER_ENV_PROPERTY_NAME); 79 final String password = (String ) m.get(DefaultConfiguration.ADMIN_PASSWORD_ENV_PROPERTY_NAME); 80 final JMXServiceURL url = env2JmxServiceUrl(m); 81 System.out.println("User = " + user); 82 System.out.println("Password = " + password); 83 return ( SunOneHttpJmxConnectorFactory.connect(url, user, password) ); 84 } 85 86 public final static String MY_PROTOCOL = "s1ashttp"; 87 88 public boolean isSupported(Map m) { 89 final boolean hostPresent = m.get(JMXConnectorProvider.HOST) != null; 90 final boolean portPresent = m.get(JMXConnectorProvider.PORT) != null; 91 92 final String protocol = (String )m.get(JMXConnectorProvider.PROTOCOL); 93 final boolean protocolPresent = protocol != null; 94 final boolean userPresent = m.get(DefaultConfiguration.ADMIN_USER_ENV_PROPERTY_NAME) != null; 95 final boolean passwordPresent = m.get(DefaultConfiguration.ADMIN_PASSWORD_ENV_PROPERTY_NAME) != null; 96 return ( hostPresent && portPresent && protocolPresent && protocol.equals( MY_PROTOCOL ) && 97 userPresent && passwordPresent ); 98 } 99 100 private JMXServiceURL env2JmxServiceUrl(Map m) throws java.net.MalformedURLException { 101 final String protocol = (String ) m.get(JMXConnectorProvider.PROTOCOL); 102 final String host = (String ) m.get(JMXConnectorProvider.HOST); 103 final int port = Integer.parseInt((String )m.get(JMXConnectorProvider.PORT)); 104 return ( new JMXServiceURL (protocol, host, port) ); 105 } 106 } 107 | Popular Tags |