Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gorovoy2011-03-24 23:13:35 +0000
committerMichael Gorovoy2011-03-24 23:13:35 +0000
commit86f9f44b6771723c664355ab88a17d81d2074b1f (patch)
treeb9705d89113212f58e9c1adc38e4dbc8af4e14af
parentbe843880b73354c34b9150f9465f29cb182ba680 (diff)
downloadorg.eclipse.jetty.project-86f9f44b6771723c664355ab88a17d81d2074b1f.tar.gz
org.eclipse.jetty.project-86f9f44b6771723c664355ab88a17d81d2074b1f.tar.xz
org.eclipse.jetty.project-86f9f44b6771723c664355ab88a17d81d2074b1f.zip
340920 Dynamically assign RMI registry port for integration testing
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2911 7e9141cc-0065-0410-87d8-b60c137991c4
-rw-r--r--VERSION.txt3
-rw-r--r--jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ConnectorServer.java94
-rw-r--r--jetty-jmx/src/test/java/org/eclipse/jetty/jmx/ConnectorServerTest.java37
3 files changed, 129 insertions, 5 deletions
diff --git a/VERSION.txt b/VERSION.txt
index 4179ce48da..40eff18e1d 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -7,10 +7,11 @@ jetty-7.3.2-SNAPSHOT
+ 339187 In the OSGi manifest of the jetty-all-server aggregate, mark javax.annotation as optional
+ 339543 Add configuration options for Certificate Revocation checking
+ 340265 Improve handling of io shutdown in SSL
+ + 340838 Update ConnectHandler to perform half closes properly
+ 340878 Integrations should be able to load their own keystores
+ + 340920 Dynamically assign RMI registry port for integration testing
+ Ensure generated fragment names are unique
+ JETTY-1245 Pooled Buffers implementation
- + 340838 Update ConnectHandler to perform half closes properly
jetty-7.3.1.v20110307 7 March 2011
+ 316382 Support a more strict SSL option with certificates
diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ConnectorServer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ConnectorServer.java
index db0f8d2feb..57106d63ec 100644
--- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ConnectorServer.java
+++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ConnectorServer.java
@@ -14,6 +14,11 @@
package org.eclipse.jetty.jmx;
import java.lang.management.ManagementFactory;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
import java.util.Map;
import javax.management.MBeanServer;
@@ -34,6 +39,7 @@ import org.eclipse.jetty.util.thread.ShutdownThread;
public class ConnectorServer extends AbstractLifeCycle
{
JMXConnectorServer _connectorServer;
+ Registry _registry;
/* ------------------------------------------------------------ */
/**
@@ -55,7 +61,7 @@ public class ConnectorServer extends AbstractLifeCycle
/**
* Constructs connector server
*
- * @param serviceURL the address of the new connector server.
+ * @param svcUrl the address of the new connector server.
* The actual address of the new connector server, as returned
* by its getAddress method, will not necessarily be exactly the same.
* @param environment a set of attributes to control the new connector
@@ -65,15 +71,26 @@ public class ConnectorServer extends AbstractLifeCycle
* @param name object name string to be assigned to connector server bean
* @throws Exception
*/
- public ConnectorServer(JMXServiceURL serviceURL, Map<String,?> environment, String name)
+ public ConnectorServer(JMXServiceURL svcUrl, Map<String,?> environment, String name)
throws Exception
{
+ String urlPath = svcUrl.getURLPath();
+ int idx = urlPath.indexOf("rmi://");
+ if (idx > 0)
+ {
+ String hostPort = urlPath.substring(idx+6, urlPath.indexOf('/', idx+6));
+ String regHostPort = startRegistry(hostPort);
+ if (regHostPort != null) {
+ urlPath = urlPath.replace(hostPort,regHostPort);
+ svcUrl = new JMXServiceURL(svcUrl.getProtocol(), svcUrl.getHost(), svcUrl.getPort(), urlPath);
+ }
+ }
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
- _connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, environment, mbeanServer);
+ _connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(svcUrl, environment, mbeanServer);
mbeanServer.registerMBean(_connectorServer,new ObjectName(name));
}
- /* ------------------------------------------------------------ */
+ /* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
*/
@@ -97,5 +114,74 @@ public class ConnectorServer extends AbstractLifeCycle
{
ShutdownThread.deregister(this);
_connectorServer.stop();
+ stopRegistry();
+ }
+
+ /**
+ * Check that local RMI registry is used, and ensure it is started. If local RMI registry is being used and not started, start it.
+ *
+ * @param hostPath
+ * hostname and port number of RMI registry
+ * @throws Exception
+ */
+ private String startRegistry(String hostPath) throws Exception
+ {
+ int rmiPort = 1099; // default RMI registry port
+ String rmiHost = hostPath;
+
+ int idx = hostPath.indexOf(':');
+ if (idx > 0)
+ {
+ rmiPort = Integer.parseInt(hostPath.substring(idx + 1));
+ rmiHost = hostPath.substring(0,idx);
+ }
+
+ // Verify that local registry is being used
+ InetAddress hostAddress = InetAddress.getByName(rmiHost);
+ if(hostAddress.isLoopbackAddress())
+ {
+ if (rmiPort == 0)
+ {
+ ServerSocket socket = new ServerSocket(0);
+ rmiPort = socket.getLocalPort();
+ socket.close();
+ }
+ else
+ {
+ try
+ {
+ // Check if a local registry is already running
+ LocateRegistry.getRegistry(rmiPort).list();
+ return null;
+ }
+ catch (Exception ex)
+ {
+ Log.ignore(ex);
+ }
+ }
+
+ _registry = LocateRegistry.createRegistry(rmiPort);
+ Thread.sleep(1000);
+
+ rmiHost = InetAddress.getLocalHost().getCanonicalHostName();
+ return rmiHost + ':' + Integer.toString(rmiPort);
+ }
+
+ return null;
+ }
+
+ private void stopRegistry()
+ {
+ if (_registry != null)
+ {
+ try
+ {
+ UnicastRemoteObject.unexportObject(_registry,true);
+ }
+ catch (Exception ex)
+ {
+ Log.ignore(ex);
+ }
+ }
}
}
diff --git a/jetty-jmx/src/test/java/org/eclipse/jetty/jmx/ConnectorServerTest.java b/jetty-jmx/src/test/java/org/eclipse/jetty/jmx/ConnectorServerTest.java
new file mode 100644
index 0000000000..10ed7d822a
--- /dev/null
+++ b/jetty-jmx/src/test/java/org/eclipse/jetty/jmx/ConnectorServerTest.java
@@ -0,0 +1,37 @@
+//========================================================================
+//Copyright (c) Webtide LLC
+//------------------------------------------------------------------------
+//All rights reserved. This program and the accompanying materials
+//are made available under the terms of the Eclipse Public License v1.0
+//and Apache License v2.0 which accompanies this distribution.
+//
+//The Eclipse Public License is available at
+//http://www.eclipse.org/legal/epl-v10.html
+//
+//The Apache License v2.0 is available at
+//http://www.apache.org/licenses/LICENSE-2.0.txt
+//
+//You may elect to redistribute this code under either of these licenses.
+//========================================================================
+
+package org.eclipse.jetty.jmx;
+
+import java.net.MalformedURLException;
+
+import javax.management.remote.JMXServiceURL;
+
+import org.junit.Test;
+
+public class ConnectorServerTest
+{
+ @Test
+ public void randomPortTest() throws Exception
+ {
+ ConnectorServer srv = new ConnectorServer(
+ new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:0/jettytest"),
+ "org.eclipse.jetty:name=rmiconnectorserver");
+ srv.start();
+ Thread.sleep(5000);
+ }
+
+}

Back to the top