1 19 package org.netbeans.modules.j2ee.sun.util; 20 21 import java.io.IOException ; 22 import javax.management.Attribute ; 23 import com.sun.appserv.management.client.AppserverConnectionSource; 24 import com.sun.appserv.management.client.TLSParams; 25 import com.sun.appserv.management.client.TrustAnyTrustManager; 26 import com.sun.appserv.management.config.ConfigDottedNames; 27 28 29 33 public class AppserverConnectionFactory { 34 35 36 private static final String JMX_CONNECTOR_PORT_DOTTED_NAME = 37 "server.admin-service.jmx-connector.system.port"; 38 39 40 private static final String SECURITY_ENABLED_DOTTED_NAME = 41 "server.admin-service.jmx-connector.system.security-enabled"; 42 43 48 private AppserverConnectionFactory() { 49 } 50 51 52 63 public static AppserverConnectionSource getAppserverConnection( 64 final String host, final int port, final String username, 65 final String password, final boolean isSecure) throws IOException { 66 return getAppserverConnection(host, port, username, password, 67 getDefaultTLSParams(isSecure), false); 68 } 69 70 71 84 public static AppserverConnectionSource getAppserverConnection( 85 final String host, final int port, final String username, 86 final String password, final boolean isSecure, boolean forceNew) 87 throws IOException { 88 return getAppserverConnection(host, port, username, password, 89 getDefaultTLSParams(isSecure), forceNew); 90 } 91 92 93 107 public static AppserverConnectionSource getAppserverConnection( 108 final String host, final int port, final String username, 109 final String password, final TLSParams tlsParams, boolean forceNew) 110 throws IOException { 111 return getRMIAppserverConnectionSource(host, port, username, password, 112 tlsParams); 113 } 114 115 116 127 public static AppserverConnectionSource getHTTPAppserverConnection( 128 final String host, final int port, final String username, 129 final String password, final boolean isSecure) throws IOException { 130 return getHTTPAppserverConnectionSource(host, port, username, password, 131 getDefaultTLSParams(isSecure)); 132 } 133 134 135 150 static AppserverConnectionSource getRMIAppserverConnectionSource( 151 final String host, final int port, final String username, 152 final String password, final TLSParams tlsParams) 153 throws IOException { 154 AppserverConnectionSource httpConn = 155 getHTTPAppserverConnectionSource(host, port, username, password, 156 tlsParams); 157 return new AppserverConnectionSource( 158 AppserverConnectionSource.PROTOCOL_RMI, host, 159 getJMXConnectorPort(httpConn), username, password, tlsParams, null); 160 } 161 162 177 static AppserverConnectionSource getHTTPAppserverConnectionSource( 178 final String host, final int port, final String username, 179 final String password, final TLSParams tlsParams) { 180 return new AppserverConnectionSource( 181 AppserverConnectionSource.PROTOCOL_HTTP, host, port, username, 182 password, tlsParams, null); 183 } 184 185 192 static ConfigDottedNames getConfigDottedNames( 193 final AppserverConnectionSource conn) throws IOException { 194 ConfigDottedNames names = null; 195 names = conn.getDomainRoot().getConfigDottedNames(); 196 return names; 197 } 198 199 209 static int getJMXConnectorPort( 210 final AppserverConnectionSource conn) throws IOException { 211 Attribute attr = 212 (Attribute )getAttributeFromConfigDottedNames(conn, 213 JMX_CONNECTOR_PORT_DOTTED_NAME); 214 return Integer.parseInt((String )attr.getValue()); 215 } 216 217 225 static boolean isAppserverConnectionSecurityEnabled( 226 final AppserverConnectionSource conn) throws IOException { 227 Attribute attr = 228 (Attribute )getAttributeFromConfigDottedNames(conn, 229 SECURITY_ENABLED_DOTTED_NAME); 230 return Boolean.getBoolean((String )attr.getValue()); 231 } 232 233 241 static Object getAttributeFromConfigDottedNames( 242 final AppserverConnectionSource conn, final String dottedName) 243 throws IOException { 244 return getConfigDottedNames(conn).dottedNameGet(dottedName); 245 } 246 247 248 256 private static TLSParams getDefaultTLSParams(final boolean isSecure) { 257 return (isSecure) 258 ? new TLSParams(TrustAnyTrustManager.getInstanceArray(), null) 259 : null; 260 } 261 262 263 } 264 265 266 267 268 269 270 | Popular Tags |