You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2008/08/12 23:53:54 UTC
svn commit: r685333 - in /geronimo/server/branches/2.1/framework/modules:
geronimo-commands/src/main/groovy/org/apache/geronimo/commands/
geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/
Author: gawor
Date: Tue Aug 12 14:53:53 2008
New Revision: 685333
URL: http://svn.apache.org/viewvc?rev=685333&view=rev
Log:
added support for --secure option for the shutdown cli tool and gshell start-server command (for cases where the secure JMX server is the only one running) (GERONIMO-4238)
Modified:
geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java
Modified: geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java?rev=685333&r1=685332&r2=685333&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java Tue Aug 12 14:53:53 2008
@@ -28,8 +28,10 @@
import javax.management.remote.JMXServiceURL;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.rmi.RMIConnectorServer;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
+import javax.rmi.ssl.SslRMIClientSocketFactory;
//
// FIXME: It should be possible to query state with-out any Geronimo classes,
@@ -73,18 +75,30 @@
log.debug("Initialized with URL: " + url + ", environment: " + environment);
}
- public ServerProxy(final String hostname, final int port, final String username, final String password) throws Exception {
- this("service:jmx:rmi://" + hostname + "/jndi/rmi://" + hostname + ":" + port + "/JMXConnector", username, password);
+ public ServerProxy(String hostname, int port, String username, String password) throws Exception {
+ this(hostname, port, username, password, false);
+ }
+
+ public ServerProxy(String hostname, int port, String username, String password, boolean secure) throws Exception {
+ this(createJMXServiceURL(hostname, port, secure), username, password, secure);
+ }
+
+ public ServerProxy(String url, String username, String password) throws Exception {
+ this(url, username, password, false);
}
- public ServerProxy(final String url, final String username, final String password) throws Exception {
+ public ServerProxy(String url, String username, String password, boolean secure) throws Exception {
assert url != null;
assert username != null;
assert password != null;
this.url = new JMXServiceURL(url);
this.environment = new HashMap();
- this.environment.put("jmx.remote.credentials", new String[] {username, password});
+ this.environment.put(JMXConnector.CREDENTIALS, new String[] {username, password});
+ if (secure) {
+ SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
+ this.environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
+ }
log.debug("Initialized with URL: " + url + ", environment: " + environment);
}
@@ -93,6 +107,11 @@
this.mbeanConnection = connector.getMBeanServerConnection();
}
+ private static String createJMXServiceURL(String hostname, int port, boolean secure) {
+ String connectorName = (secure) ? "/JMXSecureConnector" : "/JMXConnector";
+ return "service:jmx:rmi://" + hostname + "/jndi/rmi://" + hostname + ":" + port + connectorName;
+ }
+
private MBeanServerConnection getConnection() throws IOException {
if (this.mbeanConnection == null) {
log.debug("Connecting to: " + url);
Modified: geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy?rev=685333&r1=685332&r2=685333&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy Tue Aug 12 14:53:53 2008
@@ -72,6 +72,9 @@
@Option(name='-w', aliases=['--password'], description='Password (used to check server startup status)')
String password = 'manager'
+
+ @Option(name='--secure', description='Use secure channel')
+ boolean secure = false
protected Object doExecute() throws Exception {
ant = new AntBuilder(log, io)
@@ -180,7 +183,7 @@
}
}
- def server = new ServerProxy(hostname, port, username, password)
+ def server = new ServerProxy(hostname, port, username, password, secure)
launcher.verifier = {
if(server.fullyStarted) {
Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java?rev=685333&r1=685332&r2=685333&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java Tue Aug 12 14:53:53 2008
@@ -26,6 +26,8 @@
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
+import javax.management.remote.rmi.RMIConnectorServer;
+import javax.rmi.ssl.SslRMIClientSocketFactory;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
@@ -42,11 +44,15 @@
public static final String DEFAULT_PORT = "1099"; // 1099 is used by java.rmi.registry.Registry
+ String host = "localhost";
+
String port;
String user;
String password;
+
+ boolean secure = false;
private String[] args;
@@ -104,7 +110,8 @@
try {
kernel = getRunningKernel();
} catch (IOException e) {
- System.out.println("\nCould not communicate with the server. The server may not be running or the port number may be incorrect.");
+ System.out.println();
+ System.out.println("Could not communicate with the server. The server may not be running or the port number may be incorrect (" + e.getMessage() + ")");
}
if (kernel != null) {
System.out.println("Server found.");
@@ -131,10 +138,14 @@
password = args[++i];
} else if (args[i].equals("--port")) {
port = args[++i];
+ } else if (args[i].equals("--host")) {
+ host = args[++i];
} else {
printUsage();
}
return true;
+ } else if (args[i].equals("--secure")) {
+ secure = true;
} else {
printUsage();
}
@@ -143,11 +154,17 @@
public Kernel getRunningKernel() throws IOException {
Map map = new HashMap();
- map.put("jmx.remote.credentials", new String[] { user, password });
+ map.put(JMXConnector.CREDENTIALS, new String[] { user, password });
+ String connectorName = "/JMXConnector";
+ if (secure) {
+ connectorName = "/JMXSecureConnector";
+ SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
+ map.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
+ }
Kernel kernel = null;
try {
JMXServiceURL address = new JMXServiceURL(
- "service:jmx:rmi:///jndi/rmi://localhost" + ":" + port + "/JMXConnector");
+ "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + connectorName);
JMXConnector jmxConnector = JMXConnectorFactory.connect(address, map);
MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
kernel = new KernelDelegate(mbServerConnection);
@@ -163,9 +180,11 @@
System.out.println(" shutdown [options]");
System.out.println();
System.out.println("The available options are:");
- System.out.println(" --user");
- System.out.println(" --password");
- System.out.println(" --port");
+ System.out.println(" --user <username>");
+ System.out.println(" --password <password>");
+ System.out.println(" --host <hostname>");
+ System.out.println(" --port <port>");
+ System.out.println(" --secure");
System.exit(1);
}