From 2a67ebca955a380e6ad1a25795e9ccfbfd811688 Mon Sep 17 00:00:00 2001
From: Jesse McConnell
Date: Tue, 20 Mar 2012 11:25:11 -0500
Subject: [PATCH 01/10] noop change to test commit and push speed
---
pom.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/pom.xml b/pom.xml
index 8edf9e2e289..ef80c180e0d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,6 +10,7 @@
Jetty :: Project${jetty.url}pom
+
UTF-8http://www.eclipse.org/jetty
From c81dbb86940bab2ce36a4538e9dda17efea49990 Mon Sep 17 00:00:00 2001
From: pgdad
Date: Wed, 21 Mar 2012 08:44:02 -0400
Subject: [PATCH 02/10] 374891 - enhancement to how ProxyServlet determines the
proxy target
---
.../main/java/org/eclipse/jetty/servlets/ProxyServlet.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java
index 445a1bf9150..afae2ab946e 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java
@@ -414,7 +414,7 @@ public class ProxyServlet implements Servlet
if (request.getQueryString() != null)
uri += "?" + request.getQueryString();
- HttpURI url = proxyHttpURI(request.getScheme(),request.getServerName(),request.getServerPort(),uri);
+ HttpURI url = proxyHttpURI(request,uri);
if (debug != 0)
_log.debug(debug + " proxy " + uri + "-->" + url);
@@ -677,6 +677,11 @@ public class ProxyServlet implements Servlet
}
/* ------------------------------------------------------------ */
+ protected HttpURI proxyHttpURI(HttpServletRequest request, String uri) throws MalformedURLException
+ {
+ return proxyHttpURI(request.getScheme(), request.getServerName(), request.getServerPort(), uri);
+ }
+
protected HttpURI proxyHttpURI(String scheme, String serverName, int serverPort, String uri) throws MalformedURLException
{
if (!validateDestination(serverName,uri))
From 6a2c5fc9fde44ba966da3dd494ecfdba6954f3e6 Mon Sep 17 00:00:00 2001
From: Jan Bartel
Date: Thu, 22 Mar 2012 13:50:36 +1100
Subject: [PATCH 03/10] 375009 Filter initialization error will throw
MultiException
---
jetty-server/src/main/java/org/eclipse/jetty/server/Server.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
index 8f154b693dc..9a01f509562 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
@@ -265,7 +265,7 @@ public class Server extends HandlerWrapper implements Attributes
mex.add(e);
}
- if (_connectors!=null)
+ if (_connectors!=null && mex.size()==0)
{
for (int i=0;i<_connectors.length;i++)
{
From 875bcb5bb838ae843266894dc46f5598558d0612 Mon Sep 17 00:00:00 2001
From: Thomas Becker
Date: Thu, 22 Mar 2012 12:40:16 +0100
Subject: [PATCH 04/10] 374995: configure jmx rmi port via SystemProperty
Change-Id: I35f336d4754c79717b741aea0896bd71b46ed28d
374995: configure jmx rmi host via SystemProperty,change objectname and jmxpath from jettyjmx to jmxrmi
Change-Id: Ib469d631682c9fb31aea584c38906aae0958198f
374995: configure jmx rmi host via SystemProperty,change objectname and jmxpath from jettyjmx to jmxrmi
Change-Id: I02c88c518810e03c7ae59453fa6752d80108960e
---
jetty-jmx/src/main/config/etc/jetty-jmx.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/jetty-jmx/src/main/config/etc/jetty-jmx.xml b/jetty-jmx/src/main/config/etc/jetty-jmx.xml
index a685eded058..4db0dbb473a 100644
--- a/jetty-jmx/src/main/config/etc/jetty-jmx.xml
+++ b/jetty-jmx/src/main/config/etc/jetty-jmx.xml
@@ -69,7 +69,7 @@
-->
From bb66cfc8774800b41d0d0616a1e33ca159116191 Mon Sep 17 00:00:00 2001
From: Simone Bordet
Date: Thu, 22 Mar 2012 17:08:11 +0100
Subject: [PATCH 05/10] 375083 - Flow control should take in account window
size changes from concurrent SETTINGS
---
.../java/org/eclipse/jetty/spdy/ISession.java | 2 -
.../eclipse/jetty/spdy/StandardSession.java | 16 ++---
.../org/eclipse/jetty/spdy/api/Session.java | 4 +-
.../eclipse/jetty/spdy/FlowControlTest.java | 65 +++++++++++++++++++
4 files changed, 74 insertions(+), 13 deletions(-)
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/ISession.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/ISession.java
index 10e64130726..c69af218385 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/ISession.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/ISession.java
@@ -35,6 +35,4 @@ public interface ISession extends Session
public void control(IStream stream, ControlFrame frame, long timeout, TimeUnit unit, Handler handler, C context);
public void data(IStream stream, DataInfo dataInfo, long timeout, TimeUnit unit, Handler handler, C context);
-
- public int getWindowSize();
}
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java
index 314695336ac..f8fc892b1cb 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java
@@ -18,10 +18,11 @@ package org.eclipse.jetty.spdy;
import java.nio.ByteBuffer;
import java.nio.channels.InterruptedByTimeoutException;
-import java.util.ArrayList;
import java.util.Deque;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -253,9 +254,9 @@ public class StandardSession implements ISession, Parser.Listener, Handler getStreams()
+ public Set getStreams()
{
- List result = new ArrayList<>();
+ Set result = new HashSet<>();
result.addAll(streams.values());
return result;
}
@@ -540,7 +541,10 @@ public class StandardSession implements ISession, Parser.Listener, Handler getStreams();
+ public Set getStreams();
/**
*
Super interface for listeners with callbacks that are invoked on specific session events.
diff --git a/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/FlowControlTest.java b/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/FlowControlTest.java
index 1ee5f8a96c0..526c9a8d81b 100644
--- a/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/FlowControlTest.java
+++ b/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/FlowControlTest.java
@@ -23,6 +23,7 @@ import java.util.concurrent.Exchanger;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.spdy.api.BytesDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo;
@@ -41,6 +42,70 @@ import org.junit.Test;
public class FlowControlTest extends AbstractTest
{
+ @Test
+ public void testFlowControlWithConcurrentSettings() throws Exception
+ {
+ // Initial window is 64 KiB. We allow the client to send 1024 B
+ // then we change the window to 512 B. At this point, the client
+ // must stop sending data (although the initial window allows it)
+
+ final int size = 512;
+ final AtomicReference dataInfoRef = new AtomicReference<>();
+ final CountDownLatch dataLatch = new CountDownLatch(2);
+ final CountDownLatch settingsLatch = new CountDownLatch(1);
+ Session session = startClient(startServer(new ServerSessionFrameListener.Adapter()
+ {
+ @Override
+ public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
+ {
+ stream.reply(new ReplyInfo(true));
+ return new StreamFrameListener.Adapter()
+ {
+ private final AtomicInteger dataFrames = new AtomicInteger();
+
+ @Override
+ public void onData(Stream stream, DataInfo dataInfo)
+ {
+ int dataFrameCount = dataFrames.incrementAndGet();
+ if (dataFrameCount == 1)
+ {
+ dataInfoRef.set(dataInfo);
+ Settings settings = new Settings();
+ settings.put(new Settings.Setting(Settings.ID.INITIAL_WINDOW_SIZE, size));
+ stream.getSession().settings(new SettingsInfo(settings));
+ }
+ else if (dataFrameCount > 1)
+ {
+ dataInfo.consume(dataInfo.length());
+ dataLatch.countDown();
+ }
+ }
+ };
+ }
+ }), new SessionFrameListener.Adapter()
+ {
+ @Override
+ public void onSettings(Session session, SettingsInfo settingsInfo)
+ {
+ settingsLatch.countDown();
+ }
+ });
+
+ Stream stream = session.syn(new SynInfo(false), null).get(5, TimeUnit.SECONDS);
+ stream.data(new BytesDataInfo(new byte[size * 2], false));
+ settingsLatch.await(5, TimeUnit.SECONDS);
+
+ // Send the second chunk of data, must not arrive since we're flow control stalled now
+ stream.data(new BytesDataInfo(new byte[size * 2], true));
+ Assert.assertFalse(dataLatch.await(1, TimeUnit.SECONDS));
+
+ // Consume the data arrived to server, this will resume flow control
+ DataInfo dataInfo = dataInfoRef.get();
+ dataInfo.consume(dataInfo.length());
+
+ Assert.assertTrue(dataLatch.await(5, TimeUnit.SECONDS));
+ }
+
@Test
public void testServerFlowControlOneBigWrite() throws Exception
{
From 65725b00257a0724a06c6d0534c422bb4f9adf5c Mon Sep 17 00:00:00 2001
From: Greg Wilkins
Date: Fri, 23 Mar 2012 09:21:00 +1100
Subject: [PATCH 06/10] 357318: make the cancel key work around conditional on
running on windows
---
.../jetty/io/nio/SelectChannelEndPoint.java | 25 +++++++++++++------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java
index 8db704b15d5..ca182eadde6 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java
@@ -37,6 +37,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
{
public static final Logger LOG=Log.getLogger("org.eclipse.jetty.io.nio");
+ private final boolean WORK_AROUND_JVM_BUG_6346658 = System.getProperty("os.name").toLowerCase().contains("win");
private final SelectorManager.SelectSet _selectSet;
private final SelectorManager _manager;
private SelectionKey _key;
@@ -681,15 +682,23 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
@Override
public void close() throws IOException
{
- try
+ // On unix systems there is a JVM issue that if you cancel before closing, it can
+ // cause the selector to block waiting for a channel to close and that channel can
+ // block waiting for the remote end. But on windows, if you don't cancel before a
+ // close, then the selector can block anyway!
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=357318
+ if (WORK_AROUND_JVM_BUG_6346658)
{
- SelectionKey key = _key;
- if (key!=null)
- key.cancel();
- }
- catch (Throwable e)
- {
- LOG.ignore(e);
+ try
+ {
+ SelectionKey key = _key;
+ if (key!=null)
+ key.cancel();
+ }
+ catch (Throwable e)
+ {
+ LOG.ignore(e);
+ }
}
try
From 72951403d35ee2ce5207ba7f657bf3daae2f05fe Mon Sep 17 00:00:00 2001
From: Jan Bartel
Date: Mon, 26 Mar 2012 22:48:50 +1100
Subject: [PATCH 07/10] 375096 If starting a server instance fails in osgi it
is cleaned up.
---
.../DefaultJettyAtJettyHomeHelper.java | 345 +++++++++---------
.../JettyServerServiceTracker.java | 100 ++---
.../JettyServersManagedFactory.java | 13 +-
.../serverfactory/ServerInstanceWrapper.java | 218 ++++++-----
4 files changed, 336 insertions(+), 340 deletions(-)
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java
index c07ab027131..d8491eeacbe 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java
@@ -39,7 +39,7 @@ import org.osgi.framework.BundleContext;
public class DefaultJettyAtJettyHomeHelper {
private static final Logger LOG = Log.getLogger(DefaultJettyAtJettyHomeHelper.class);
-
+
/**
* contains a comma separated list of pathes to the etc/jetty-*.xml files
* used to configure jetty. By default the value is 'etc/jetty.xml' when the
@@ -69,7 +69,7 @@ public class DefaultJettyAtJettyHomeHelper {
* Usual system property used as the port for https for a typical jetty configuration.
*/
public static final String SYS_PROP_JETTY_PORT_SSL = "jetty.port.ssl";
-
+
/**
* Called by the JettyBootStrapActivator.
* If the system property jetty.home is defined and points to a folder,
@@ -88,81 +88,76 @@ public class DefaultJettyAtJettyHomeHelper {
* that might use them as part of their properties.
*
*/
- public static void startJettyAtJettyHome(BundleContext bundleContext)
+ public static void startJettyAtJettyHome(BundleContext bundleContext) throws Exception
{
- String jettyHomeSysProp = System.getProperty(SYS_PROP_JETTY_HOME);
- String jettyHomeBundleSysProp = System.getProperty(SYS_PROP_JETTY_HOME_BUNDLE);
- File jettyHome = null;
- Bundle jettyHomeBundle = null;
- if (jettyHomeSysProp != null)
- {
- jettyHomeSysProp = resolvePropertyValue(jettyHomeSysProp);
- //bug 329621
- if (jettyHomeSysProp.startsWith("\"") && jettyHomeSysProp.endsWith("\"")
- || (jettyHomeSysProp.startsWith("'") && jettyHomeSysProp.endsWith("'"))) {
- jettyHomeSysProp = jettyHomeSysProp.substring(1, jettyHomeSysProp.length() - 1);
- }
- if (jettyHomeBundleSysProp != null)
- {
- LOG.warn("Both the jetty.home property and the jetty.home.bundle property are defined."
- + " jetty.home.bundle is not taken into account.");
- }
- jettyHome = new File(jettyHomeSysProp);
- if (!jettyHome.exists() || !jettyHome.isDirectory())
- {
- LOG.warn("Unable to locate the jetty.home folder " + jettyHomeSysProp);
- return;
- }
- }
- else if (jettyHomeBundleSysProp != null)
- {
- jettyHomeBundleSysProp = resolvePropertyValue(jettyHomeBundleSysProp);
- for (Bundle b : bundleContext.getBundles())
- {
- if (b.getSymbolicName().equals(jettyHomeBundleSysProp))
- {
- jettyHomeBundle = b;
- break;
- }
- }
- if (jettyHomeBundle == null)
- {
- LOG.warn("Unable to find the jetty.home.bundle named " + jettyHomeSysProp);
- return;
- }
-
- }
- if (jettyHome == null && jettyHomeBundle == null)
- {
- LOG.warn("No default jetty started.");
- return;
- }
- try
- {
- Server server = new Server();
- Dictionary properties = new Hashtable();
- properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, OSGiServerConstants.MANAGED_JETTY_SERVER_DEFAULT_NAME);
-
- String configURLs = jettyHome != null ? getJettyConfigurationURLs(jettyHome) : getJettyConfigurationURLs(jettyHomeBundle);
- properties.put(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS, configURLs);
+ String jettyHomeSysProp = System.getProperty(SYS_PROP_JETTY_HOME);
+ String jettyHomeBundleSysProp = System.getProperty(SYS_PROP_JETTY_HOME_BUNDLE);
+ File jettyHome = null;
+ Bundle jettyHomeBundle = null;
+ if (jettyHomeSysProp != null)
+ {
+ jettyHomeSysProp = resolvePropertyValue(jettyHomeSysProp);
+ //bug 329621
+ if (jettyHomeSysProp.startsWith("\"") && jettyHomeSysProp.endsWith("\"")
+ || (jettyHomeSysProp.startsWith("'") && jettyHomeSysProp.endsWith("'"))) {
+ jettyHomeSysProp = jettyHomeSysProp.substring(1, jettyHomeSysProp.length() - 1);
+ }
+ if (jettyHomeBundleSysProp != null)
+ {
+ LOG.warn("Both the jetty.home property and the jetty.home.bundle property are defined."
+ + " jetty.home.bundle is not taken into account.");
+ }
+ jettyHome = new File(jettyHomeSysProp);
+ if (!jettyHome.exists() || !jettyHome.isDirectory())
+ {
+ LOG.warn("Unable to locate the jetty.home folder " + jettyHomeSysProp);
+ return;
+ }
+ }
+ else if (jettyHomeBundleSysProp != null)
+ {
+ jettyHomeBundleSysProp = resolvePropertyValue(jettyHomeBundleSysProp);
+ for (Bundle b : bundleContext.getBundles())
+ {
+ if (b.getSymbolicName().equals(jettyHomeBundleSysProp))
+ {
+ jettyHomeBundle = b;
+ break;
+ }
+ }
+ if (jettyHomeBundle == null)
+ {
+ LOG.warn("Unable to find the jetty.home.bundle named " + jettyHomeSysProp);
+ return;
+ }
- LOG.info("Configuring the default jetty server with " + configURLs);
-
- //these properties usually are the ones passed to this type of configuration.
- setProperty(properties,SYS_PROP_JETTY_HOME,System.getProperty(SYS_PROP_JETTY_HOME));
- setProperty(properties,SYS_PROP_JETTY_HOST,System.getProperty(SYS_PROP_JETTY_HOST));
- setProperty(properties,SYS_PROP_JETTY_PORT,System.getProperty(SYS_PROP_JETTY_PORT));
- setProperty(properties,SYS_PROP_JETTY_PORT_SSL,System.getProperty(SYS_PROP_JETTY_PORT_SSL));
+ }
+ if (jettyHome == null && jettyHomeBundle == null)
+ {
+ LOG.warn("No default jetty started.");
+ return;
+ }
+
+ Server server = new Server();
+ Dictionary properties = new Hashtable();
+ properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, OSGiServerConstants.MANAGED_JETTY_SERVER_DEFAULT_NAME);
+
+ String configURLs = jettyHome != null ? getJettyConfigurationURLs(jettyHome) : getJettyConfigurationURLs(jettyHomeBundle);
+ properties.put(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS, configURLs);
+
+ LOG.info("Configuring the default jetty server with " + configURLs);
+
+ //these properties usually are the ones passed to this type of configuration.
+ setProperty(properties,SYS_PROP_JETTY_HOME,System.getProperty(SYS_PROP_JETTY_HOME));
+ setProperty(properties,SYS_PROP_JETTY_HOST,System.getProperty(SYS_PROP_JETTY_HOST));
+ setProperty(properties,SYS_PROP_JETTY_PORT,System.getProperty(SYS_PROP_JETTY_PORT));
+ setProperty(properties,SYS_PROP_JETTY_PORT_SSL,System.getProperty(SYS_PROP_JETTY_PORT_SSL));
+
+ bundleContext.registerService(Server.class.getName(), server, properties);
+ // hookNestedConnectorToBridgeServlet(server);
- bundleContext.registerService(Server.class.getName(), server, properties);
-// hookNestedConnectorToBridgeServlet(server);
- }
- catch (Throwable t)
- {
- t.printStackTrace();
- }
}
-
+
/**
* Minimum setup for the location of the configuration files given a jettyhome folder.
* Reads the system property jetty.etc.config.urls and look for the corresponding jetty
@@ -172,22 +167,22 @@ public class DefaultJettyAtJettyHomeHelper {
*/
private static String getJettyConfigurationURLs(File jettyhome)
{
- String jettyetc = System.getProperty(SYS_PROP_JETTY_ETC_FILES,"etc/jetty.xml");
+ String jettyetc = System.getProperty(SYS_PROP_JETTY_ETC_FILES,"etc/jetty.xml");
StringTokenizer tokenizer = new StringTokenizer(jettyetc,";,", false);
StringBuilder res = new StringBuilder();
while (tokenizer.hasMoreTokens())
{
- String next = tokenizer.nextToken().trim();
- if (!next.startsWith("/") && next.indexOf(':') == -1)
- {
- try {
- next = new File(jettyhome, next).toURI().toURL().toString();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- continue;
- }
- }
- appendToCommaSeparatedList(res, next);
+ String next = tokenizer.nextToken().trim();
+ if (!next.startsWith("/") && next.indexOf(':') == -1)
+ {
+ try {
+ next = new File(jettyhome, next).toURI().toURL().toString();
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ continue;
+ }
+ }
+ appendToCommaSeparatedList(res, next);
}
return res.toString();
}
@@ -202,108 +197,108 @@ public class DefaultJettyAtJettyHomeHelper {
*/
private static String getJettyConfigurationURLs(Bundle configurationBundle)
{
- String jettyetc = System.getProperty(SYS_PROP_JETTY_ETC_FILES,"etc/jetty.xml");
+ String jettyetc = System.getProperty(SYS_PROP_JETTY_ETC_FILES,"etc/jetty.xml");
StringTokenizer tokenizer = new StringTokenizer(jettyetc,";,", false);
StringBuilder res = new StringBuilder();
-
+
while (tokenizer.hasMoreTokens())
{
String etcFile = tokenizer.nextToken().trim();
if (etcFile.startsWith("/") || etcFile.indexOf(":") != -1)
{
- appendToCommaSeparatedList(res, etcFile);
+ appendToCommaSeparatedList(res, etcFile);
}
else
{
- Enumeration enUrls = BundleFileLocatorHelper.DEFAULT
- .findEntries(configurationBundle, etcFile);
-
- //default for org.eclipse.osgi.boot where we look inside jettyhome for the default embedded configuration.
- //default inside jettyhome. this way fragments to the bundle can define their own configuration.
- if ((enUrls == null || !enUrls.hasMoreElements()) && etcFile.endsWith("etc/jetty.xml"))
- {
- enUrls = BundleFileLocatorHelper.DEFAULT
- .findEntries(configurationBundle, "/jettyhome/etc/jetty-osgi-default.xml");
- System.err.println("Configuring jetty with the default embedded configuration:" +
- "bundle: " + configurationBundle.getSymbolicName() +
- " config: /jettyhome/etc/jetty-osgi-default.xml");
- }
- if (enUrls == null || !enUrls.hasMoreElements())
- {
- System.err.println("Unable to locate a jetty configuration file for " + etcFile);
- }
- if (enUrls != null)
- {
- while (enUrls.hasMoreElements())
- {
- appendToCommaSeparatedList(res, enUrls.nextElement().toString());
- }
- }
+ Enumeration enUrls = BundleFileLocatorHelper.DEFAULT
+ .findEntries(configurationBundle, etcFile);
+
+ //default for org.eclipse.osgi.boot where we look inside jettyhome for the default embedded configuration.
+ //default inside jettyhome. this way fragments to the bundle can define their own configuration.
+ if ((enUrls == null || !enUrls.hasMoreElements()) && etcFile.endsWith("etc/jetty.xml"))
+ {
+ enUrls = BundleFileLocatorHelper.DEFAULT
+ .findEntries(configurationBundle, "/jettyhome/etc/jetty-osgi-default.xml");
+ System.err.println("Configuring jetty with the default embedded configuration:" +
+ "bundle: " + configurationBundle.getSymbolicName() +
+ " config: /jettyhome/etc/jetty-osgi-default.xml");
+ }
+ if (enUrls == null || !enUrls.hasMoreElements())
+ {
+ System.err.println("Unable to locate a jetty configuration file for " + etcFile);
+ }
+ if (enUrls != null)
+ {
+ while (enUrls.hasMoreElements())
+ {
+ appendToCommaSeparatedList(res, enUrls.nextElement().toString());
+ }
+ }
}
}
return res.toString();
}
-
- private static void appendToCommaSeparatedList(StringBuilder buffer, String value)
- {
- if (buffer.length() != 0)
- {
- buffer.append(",");
- }
- buffer.append(value);
- }
-
- private static void setProperty(Dictionary properties, String key, String value)
- {
- if (value != null)
- {
- properties.put(key, value);
- }
- }
-
- /**
- * recursively substitute the ${sysprop} by their actual system property.
- * ${sysprop,defaultvalue} will use 'defaultvalue' as the value if no sysprop is defined.
- * Not the most efficient code but we are shooting for simplicity and speed of development here.
- *
- * @param value
- * @return
- */
- public static String resolvePropertyValue(String value)
- {
- int ind = value.indexOf("${");
- if (ind == -1) {
- return value;
- }
- int ind2 = value.indexOf('}', ind);
- if (ind2 == -1) {
- return value;
- }
- String sysprop = value.substring(ind+2, ind2);
- String defaultValue = null;
- int comma = sysprop.indexOf(',');
- if (comma != -1 && comma+1 != sysprop.length())
- {
- defaultValue = sysprop.substring(comma+1);
- defaultValue = resolvePropertyValue(defaultValue);
- sysprop = sysprop.substring(0,comma);
- }
- else
- {
- defaultValue = "${" + sysprop + "}";
- }
-
- String v = System.getProperty(sysprop);
-
- String reminder = value.length() > ind2 + 1 ? value.substring(ind2+1) : "";
- reminder = resolvePropertyValue(reminder);
- if (v != null)
- {
- return value.substring(0, ind) + v + reminder;
- }
- else
- {
- return value.substring(0, ind) + defaultValue + reminder;
- }
- }
+
+ private static void appendToCommaSeparatedList(StringBuilder buffer, String value)
+ {
+ if (buffer.length() != 0)
+ {
+ buffer.append(",");
+ }
+ buffer.append(value);
+ }
+
+ private static void setProperty(Dictionary properties, String key, String value)
+ {
+ if (value != null)
+ {
+ properties.put(key, value);
+ }
+ }
+
+ /**
+ * recursively substitute the ${sysprop} by their actual system property.
+ * ${sysprop,defaultvalue} will use 'defaultvalue' as the value if no sysprop is defined.
+ * Not the most efficient code but we are shooting for simplicity and speed of development here.
+ *
+ * @param value
+ * @return
+ */
+ public static String resolvePropertyValue(String value)
+ {
+ int ind = value.indexOf("${");
+ if (ind == -1) {
+ return value;
+ }
+ int ind2 = value.indexOf('}', ind);
+ if (ind2 == -1) {
+ return value;
+ }
+ String sysprop = value.substring(ind+2, ind2);
+ String defaultValue = null;
+ int comma = sysprop.indexOf(',');
+ if (comma != -1 && comma+1 != sysprop.length())
+ {
+ defaultValue = sysprop.substring(comma+1);
+ defaultValue = resolvePropertyValue(defaultValue);
+ sysprop = sysprop.substring(0,comma);
+ }
+ else
+ {
+ defaultValue = "${" + sysprop + "}";
+ }
+
+ String v = System.getProperty(sysprop);
+
+ String reminder = value.length() > ind2 + 1 ? value.substring(ind2+1) : "";
+ reminder = resolvePropertyValue(reminder);
+ if (v != null)
+ {
+ return value.substring(0, ind) + v + reminder;
+ }
+ else
+ {
+ return value.substring(0, ind) + defaultValue + reminder;
+ }
+ }
}
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServerServiceTracker.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServerServiceTracker.java
index 200647cecc9..88f1d7f4f5c 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServerServiceTracker.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServerServiceTracker.java
@@ -18,50 +18,53 @@ import java.util.Properties;
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
/**
- * Deploy the jetty server instances when they are registered as an OSGi service.
+ * Deploy the jetty server instances when they are registered as an OSGi
+ * service.
*/
public class JettyServerServiceTracker implements ServiceListener, IManagedJettyServerRegistry
{
-
+ private static Logger LOG = Log.getLogger(JettyServerServiceTracker.class.getName());
+
/**
- * Servers indexed by PIDs. PIDs are generated by the ConfigurationAdmin service.
+ * Servers indexed by PIDs. PIDs are generated by the ConfigurationAdmin
+ * service.
*/
private Map _serversIndexedByName = new HashMap();
+
/** The context-handler to deactivate indexed by ServerInstanceWrapper */
private Map _indexByServiceReference = new HashMap();
-
/**
* Stops each one of the registered servers.
*/
public void stop()
{
- //not sure that this is really useful but here we go.
- for (ServerInstanceWrapper wrapper : _serversIndexedByName.values())
- {
- try
- {
- wrapper.stop();
- }
- catch (Throwable t)
- {
-
- }
- }
+ // not sure that this is really useful but here we go.
+ for (ServerInstanceWrapper wrapper : _serversIndexedByName.values())
+ {
+ try
+ {
+ wrapper.stop();
+ }
+ catch (Throwable t)
+ {
+ LOG.warn(t);
+ }
+ }
}
-
/**
* Receives notification that a service has had a lifecycle change.
*
- * @param ev
- * The ServiceEvent object.
+ * @param ev The ServiceEvent object.
*/
public void serviceChanged(ServiceEvent ev)
{
@@ -71,17 +74,16 @@ public class JettyServerServiceTracker implements ServiceListener, IManagedJetty
case ServiceEvent.MODIFIED:
case ServiceEvent.UNREGISTERING:
{
- ServerInstanceWrapper instance = unregisterInIndex(ev.getServiceReference());
+ ServerInstanceWrapper instance = unregisterInIndex(ev.getServiceReference());
if (instance != null)
{
try
{
- instance.stop();
+ instance.stop();
}
catch (Exception e)
{
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.warn(e);
}
}
}
@@ -96,32 +98,35 @@ public class JettyServerServiceTracker implements ServiceListener, IManagedJetty
}
case ServiceEvent.REGISTERED:
{
- Bundle contributor = sr.getBundle();
- Server server = (Server)contributor.getBundleContext().getService(sr);
- ServerInstanceWrapper wrapper = registerInIndex(server, sr);
- Properties props = new Properties();
- for (String key : sr.getPropertyKeys())
- {
- Object value = sr.getProperty(key);
- props.put(key, value);
- }
- wrapper.start(server, props);
- break;
+ try
+ {
+ Bundle contributor = sr.getBundle();
+ Server server = (Server) contributor.getBundleContext().getService(sr);
+ ServerInstanceWrapper wrapper = registerInIndex(server, sr);
+ Properties props = new Properties();
+ for (String key : sr.getPropertyKeys())
+ {
+ Object value = sr.getProperty(key);
+ props.put(key, value);
+ }
+ wrapper.start(server, props);
+ }
+ catch (Exception e)
+ {
+ LOG.warn(e);
+ }
+ break;
}
}
}
private ServerInstanceWrapper registerInIndex(Server server, ServiceReference sr)
{
- String name = (String)sr.getProperty(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME);
- if (name == null)
- {
- throw new IllegalArgumentException("The property " +
- OSGiServerConstants.MANAGED_JETTY_SERVER_NAME + " is mandatory");
- }
+ String name = (String) sr.getProperty(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME);
+ if (name == null) { throw new IllegalArgumentException("The property " + OSGiServerConstants.MANAGED_JETTY_SERVER_NAME + " is mandatory"); }
ServerInstanceWrapper wrapper = new ServerInstanceWrapper(name);
- _indexByServiceReference.put(sr,wrapper);
- _serversIndexedByName.put(name,wrapper);
+ _indexByServiceReference.put(sr, wrapper);
+ _serversIndexedByName.put(name, wrapper);
return wrapper;
}
@@ -133,7 +138,7 @@ public class JettyServerServiceTracker implements ServiceListener, IManagedJetty
*/
private ServerInstanceWrapper unregisterInIndex(ServiceReference sr)
{
- ServerInstanceWrapper handler = _indexByServiceReference.remove(sr);
+ ServerInstanceWrapper handler = _indexByServiceReference.remove(sr);
if (handler == null)
{
// a warning?
@@ -149,13 +154,12 @@ public class JettyServerServiceTracker implements ServiceListener, IManagedJetty
/**
* @param managedServerName The server name
- * @return the corresponding jetty server wrapped with its deployment properties.
+ * @return the corresponding jetty server wrapped with its deployment
+ * properties.
*/
public ServerInstanceWrapper getServerInstanceWrapper(String managedServerName)
{
- return _serversIndexedByName.get(managedServerName == null
- ? OSGiServerConstants.MANAGED_JETTY_SERVER_DEFAULT_NAME : managedServerName);
+ return _serversIndexedByName.get(managedServerName == null ? OSGiServerConstants.MANAGED_JETTY_SERVER_DEFAULT_NAME : managedServerName);
}
-
-
+
}
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServersManagedFactory.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServersManagedFactory.java
index 31ad22534b2..3872fad70ff 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServersManagedFactory.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/JettyServersManagedFactory.java
@@ -99,14 +99,21 @@ public class JettyServersManagedFactory implements ManagedServiceFactory, IManag
String name = (String)properties.get(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME);
if (name == null)
{
- throw new ConfigurationException(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME,
- "The name of the server is mandatory");
+ throw new ConfigurationException(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME,
+ "The name of the server is mandatory");
}
serverInstanceWrapper = new ServerInstanceWrapper(name);
_serversIndexedByPID.put(pid, serverInstanceWrapper);
_serversNameIndexedByPID.put(pid, name);
_serversPIDIndexedByName.put(name, pid);
- serverInstanceWrapper.start(new Server(), properties);
+ try
+ {
+ serverInstanceWrapper.start(new Server(), properties);
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException(null, "Error starting jetty server instance", e);
+ }
}
public synchronized void deleted(String pid)
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java
index 21d0d6adb7d..bb274fe313e 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java
@@ -44,28 +44,29 @@ import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.xml.sax.SAXParseException;
-
/**
* Exposes a Jetty Server to be managed by an OSGi ManagedServiceFactory
- * Configure and start it.
- * Can also be used from the ManagedServiceFactory
+ * Configure and start it. Can also be used from the ManagedServiceFactory
*/
-public class ServerInstanceWrapper {
+public class ServerInstanceWrapper
+{
- /** The value of this property points to the parent director of
- * the jetty.xml configuration file currently executed.
- * Everything is passed as a URL to support the
- * case where the bundle is zipped. */
+ /**
+ * The value of this property points to the parent director of the jetty.xml
+ * configuration file currently executed. Everything is passed as a URL to
+ * support the case where the bundle is zipped.
+ */
public static final String PROPERTY_THIS_JETTY_XML_FOLDER_URL = "this.jetty.xml.parent.folder.url";
- private static Logger __logger = Log.getLogger(ServerInstanceWrapper.class.getName());
-
+ private static Logger LOG = Log.getLogger(ServerInstanceWrapper.class.getName());
+
private final String _managedServerName;
-
+
/**
* The managed jetty server
*/
private Server _server;
+
private ContextHandlerCollection _ctxtHandler;
/**
@@ -74,32 +75,34 @@ public class ServerInstanceWrapper {
* let the TldScanner find the jars where the tld files are.
*/
private ClassLoader _commonParentClassLoaderForWebapps;
+
private DeploymentManager _deploymentManager;
+
private OSGiAppProvider _provider;
-
+
private WebBundleDeployerHelper _webBundleDeployerHelper;
-
-
+
public ServerInstanceWrapper(String managedServerName)
{
_managedServerName = managedServerName;
}
-
+
public String getManagedServerName()
{
return _managedServerName;
}
-
+
/**
- * The classloader that should be the parent classloader for
- * each webapp deployed on this server.
+ * The classloader that should be the parent classloader for each webapp
+ * deployed on this server.
+ *
* @return
*/
public ClassLoader getParentClassLoaderForWebapps()
{
return _commonParentClassLoaderForWebapps;
}
-
+
/**
* @return The deployment manager registered on this server.
*/
@@ -107,7 +110,7 @@ public class ServerInstanceWrapper {
{
return _deploymentManager;
}
-
+
/**
* @return The app provider registered on this server.
*/
@@ -115,19 +118,17 @@ public class ServerInstanceWrapper {
{
return _provider;
}
-
-
+
public Server getServer()
{
return _server;
}
-
-
+
public WebBundleDeployerHelper getWebBundleDeployerHelp()
{
return _webBundleDeployerHelper;
}
-
+
/**
* @return The collection of context handlers
*/
@@ -136,8 +137,7 @@ public class ServerInstanceWrapper {
return _ctxtHandler;
}
-
- public void start(Server server, Dictionary props)
+ public void start(Server server, Dictionary props) throws Exception
{
_server = server;
ClassLoader contextCl = Thread.currentThread().getContextClassLoader();
@@ -146,62 +146,61 @@ public class ServerInstanceWrapper {
// passing this bundle's classloader as the context classlaoder
// makes sure there is access to all the jetty's bundles
ClassLoader libExtClassLoader = null;
- String sharedURLs = (String)props.get(OSGiServerConstants.MANAGED_JETTY_SHARED_LIB_FOLDER_URLS);
- try
- {
- List shared = sharedURLs != null ? extractFiles(sharedURLs) : null;
- libExtClassLoader = LibExtClassLoaderHelper.createLibExtClassLoader(
- shared, null, server, JettyBootstrapActivator.class.getClassLoader());
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- }
+ String sharedURLs = (String) props.get(OSGiServerConstants.MANAGED_JETTY_SHARED_LIB_FOLDER_URLS);
+
+ List shared = sharedURLs != null ? extractFiles(sharedURLs) : null;
+ libExtClassLoader = LibExtClassLoaderHelper.createLibExtClassLoader(shared, null, server, JettyBootstrapActivator.class.getClassLoader());
Thread.currentThread().setContextClassLoader(libExtClassLoader);
-
+
configure(server, props);
init();
- //now that we have an app provider we can call the registration customizer.
- try
- {
- URL[] jarsWithTlds = getJarsWithTlds();
- _commonParentClassLoaderForWebapps = jarsWithTlds == null
- ? libExtClassLoader
- :new TldLocatableURLClassloader(libExtClassLoader,jarsWithTlds);
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- }
+ // now that we have an app provider we can call the registration
+ // customizer.
+
+ URL[] jarsWithTlds = getJarsWithTlds();
+ _commonParentClassLoaderForWebapps = jarsWithTlds == null ? libExtClassLoader : new TldLocatableURLClassloader(libExtClassLoader, jarsWithTlds);
-
server.start();
+ _webBundleDeployerHelper = new WebBundleDeployerHelper(this);
}
- catch (Throwable t)
+ catch (Exception e)
{
- t.printStackTrace();
+ if (server != null)
+ {
+ try
+ {
+ server.stop();
+ }
+ catch (Exception x)
+ {
+ LOG.ignore(x);
+ }
+ }
+ throw e;
}
finally
{
Thread.currentThread().setContextClassLoader(contextCl);
}
- _webBundleDeployerHelper = new WebBundleDeployerHelper(this);
+
+
}
-
-
+
public void stop()
{
- try {
+ try
+ {
if (_server.isRunning())
{
_server.stop();
}
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ LOG.warn(e);
}
}
@@ -229,14 +228,13 @@ public class ServerInstanceWrapper {
private URL[] getJarsWithTlds() throws Exception
{
ArrayList res = new ArrayList();
- WebBundleDeployerHelper.staticInit();//that is not looking great.
+ WebBundleDeployerHelper.staticInit();// that is not looking great.
for (WebappRegistrationCustomizer regCustomizer : WebBundleDeployerHelper.JSP_REGISTRATION_HELPERS)
{
URL[] urls = regCustomizer.getJarsWithTlds(_provider, WebBundleDeployerHelper.BUNDLE_FILE_LOCATOR_HELPER);
for (URL url : urls)
{
- if (!res.contains(url))
- res.add(url);
+ if (!res.contains(url)) res.add(url);
}
}
if (!res.isEmpty())
@@ -244,19 +242,15 @@ public class ServerInstanceWrapper {
else
return null;
}
-
+
private void configure(Server server, Dictionary props) throws Exception
{
String jettyConfigurationUrls = (String) props.get(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS);
- List jettyConfigurations = jettyConfigurationUrls != null
- ? extractResources(jettyConfigurationUrls) : null;
- if (jettyConfigurations == null || jettyConfigurations.isEmpty())
- {
- return;
- }
- Map id_map = new HashMap();
- id_map.put("Server",server);
- Map properties = new HashMap();
+ List jettyConfigurations = jettyConfigurationUrls != null ? extractResources(jettyConfigurationUrls) : null;
+ if (jettyConfigurations == null || jettyConfigurations.isEmpty()) { return; }
+ Map id_map = new HashMap();
+ id_map.put("Server", server);
+ Map properties = new HashMap();
Enumeration