diff --git a/.gitignore b/.gitignore
index 12ab1b6945c..815d2963057 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,3 +38,4 @@ target/
#maven
*.versionsBackup
+*.releaseBackup
diff --git a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
index 86453ae9e4f..9ebba4e49fd 100644
--- a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
+++ b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
@@ -29,7 +29,11 @@ public class OneWebApp
server.setConnectors(new Connector[]
{ connector });
- String war = args.length > 0?args[0]: "../test-jetty-webapp/target/test-jetty-webapp-" + Server.getVersion();
+
+ //If you're running this from inside Eclipse, then Server.getVersion will not provide
+ //the correct number as there is no manifest. Use the command line instead to provide the path to the
+ //test webapp
+ String war = args.length > 0?args[0]: "../test-jetty-webapp/target/test-jetty-webapp-"+Server.getVersion();
String path = args.length > 1?args[1]:"/";
System.err.println(war + " " + path);
@@ -37,6 +41,15 @@ public class OneWebApp
WebAppContext webapp = new WebAppContext();
webapp.setContextPath(path);
webapp.setWar(war);
+
+ //If the webapp contains security constraints, you will need to configure a LoginService
+ if (war.contains("test-jetty-webapp"))
+ {
+ org.eclipse.jetty.security.HashLoginService loginService = new org.eclipse.jetty.security.HashLoginService();
+ loginService.setName("Test Realm");
+ loginService.setConfig("src/test/resources/realm.properties");
+ webapp.getSecurityHandler().setLoginService(loginService);
+ }
server.setHandler(webapp);
diff --git a/jetty-aggregate/jetty-all-server/pom.xml b/jetty-aggregate/jetty-all-server/pom.xml
index cee39b8ffcf..7dfeca062dc 100644
--- a/jetty-aggregate/jetty-all-server/pom.xml
+++ b/jetty-aggregate/jetty-all-server/pom.xml
@@ -5,7 +5,6 @@
8.1.3-SNAPSHOT4.0.0
- org.eclipse.jetty.aggregatejetty-all-serverJetty :: Aggregate :: All Server
@@ -80,6 +79,8 @@
!org.eclipse.jetty*,
javax.annotation;version="1.0.0";resolution:=optional,
javax.servlet;version="2.6.0",
+ javax.servlet.annotation;version="2.6.0",
+ javax.servlet.descriptor;version="2.6.0",
javax.servlet.http;version="2.6.0",
javax.mail;version="1.4.0";resolution:=optional,
javax.mail.event;version="1.4.0";resolution:=optional,
diff --git a/jetty-aggregate/jetty-client/pom.xml b/jetty-aggregate/jetty-client/pom.xml
index 26b5d746011..d06130ff5c5 100644
--- a/jetty-aggregate/jetty-client/pom.xml
+++ b/jetty-aggregate/jetty-client/pom.xml
@@ -5,7 +5,6 @@
8.1.3-SNAPSHOT4.0.0
- org.eclipse.jetty.aggregatejetty-clientJetty :: Aggregate :: HTTP Client
diff --git a/jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13SocketConnector.java b/jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13SocketConnector.java
index 3632b291844..37ff45fac6c 100644
--- a/jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13SocketConnector.java
+++ b/jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13SocketConnector.java
@@ -36,10 +36,10 @@ public class Ajp13SocketConnector extends SocketConnector
static boolean __allowShutdown = false;
public Ajp13SocketConnector()
{
- super.setRequestHeaderSize(Ajp13Packet.MAX_DATA_SIZE);
- super.setResponseHeaderSize(Ajp13Packet.MAX_DATA_SIZE);
- super.setRequestBufferSize(Ajp13Packet.MAX_DATA_SIZE);
- super.setResponseBufferSize(Ajp13Packet.MAX_DATA_SIZE);
+ super.setRequestHeaderSize(Ajp13Packet.MAX_PACKET_SIZE);
+ super.setResponseHeaderSize(Ajp13Packet.MAX_PACKET_SIZE);
+ super.setRequestBufferSize(Ajp13Packet.MAX_PACKET_SIZE);
+ super.setResponseBufferSize(Ajp13Packet.MAX_PACKET_SIZE);
// IN AJP protocol the socket stay open, so
// by default the time out is set to 0 seconds
super.setMaxIdleTime(0);
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java
index 0b5581ed984..4de850fa627 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java
@@ -171,7 +171,7 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
/* ------------------------------------------------------------ */
/** Set the ThreadPool.
- * The threadpool passed is added via {@link #addBean(Object)} so that
+ * The threadpool passed is added via {@link #addBean(Object)} so that
* it's lifecycle may be managed as a {@link AggregateLifeCycle}.
* @param threadPool the threadPool to set
*/
@@ -878,7 +878,7 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
@Deprecated
public void setProvider(String provider)
{
- setProvider(provider);
+ _sslContextFactory.setProvider(provider);
}
/* ------------------------------------------------------------ */
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java
index 18a197ced6a..5ea60430766 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java
@@ -475,10 +475,12 @@ public class HttpDestination implements Dumpable
HttpEventListener elistener = (HttpEventListener)constructor.newInstance(this, ex);
ex.setEventListener(elistener);
}
- catch (Exception e)
+ catch (final Exception e)
{
- e.printStackTrace();
- throw new IOException("Unable to instantiate registered listener for destination: " + listenerClass);
+ throw new IOException("Unable to instantiate registered listener for destination: " + listenerClass)
+ {
+ {initCause(e);}
+ };
}
}
}
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector.java b/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector.java
index e1c282e74db..baf31b1f902 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector.java
@@ -276,6 +276,11 @@ class SelectConnector extends AggregateLifeCycle implements HttpClient.Connector
_endp.shutdownOutput();
}
+ public void dispatch()
+ {
+ _endp.asyncDispatch();
+ }
+
public void asyncDispatch()
{
_endp.asyncDispatch();
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/security/DigestAuthentication.java b/jetty-client/src/main/java/org/eclipse/jetty/client/security/DigestAuthentication.java
index 032a2aafab2..a5ba37ee740 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/security/DigestAuthentication.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/security/DigestAuthentication.java
@@ -104,8 +104,7 @@ public class DigestAuthentication implements Authentication
}
catch(Exception e)
{
- e.printStackTrace();
- return null;
+ throw new RuntimeException(e);
}
}
@@ -119,8 +118,7 @@ public class DigestAuthentication implements Authentication
}
catch(Exception e)
{
- e.printStackTrace();
- return null;
+ throw new RuntimeException(e);
}
}
diff --git a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationSupport.java b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationSupport.java
index 6a90a5ad3c9..4dd86193df9 100644
--- a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationSupport.java
+++ b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationSupport.java
@@ -14,7 +14,6 @@
package org.eclipse.jetty.continuation;
import java.lang.reflect.Constructor;
-
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestWrapper;
import javax.servlet.ServletResponse;
@@ -36,7 +35,7 @@ public class ContinuationSupport
static
{
boolean servlet3Support=false;
- Constructor>s3cc=null;
+ Constructor extends Continuation>s3cc=null;
try
{
boolean servlet3=ServletRequest.class.getMethod("startAsync")!=null;
@@ -52,11 +51,11 @@ public class ContinuationSupport
finally
{
__servlet3=servlet3Support;
- __newServlet3Continuation=(Constructor extends Continuation>)s3cc;
+ __newServlet3Continuation=s3cc;
}
-
+
boolean jetty6Support=false;
- Constructor>j6cc=null;
+ Constructor extends Continuation>j6cc=null;
try
{
Class> jetty6ContinuationClass = ContinuationSupport.class.getClassLoader().loadClass("org.mortbay.util.ajax.Continuation");
@@ -73,9 +72,9 @@ public class ContinuationSupport
finally
{
__jetty6=jetty6Support;
- __newJetty6Continuation=(Constructor extends Continuation>)j6cc;
+ __newJetty6Continuation=j6cc;
}
-
+
Class> waiting=null;
try
{
@@ -93,12 +92,12 @@ public class ContinuationSupport
/* ------------------------------------------------------------ */
/**
* Get a Continuation. The type of the Continuation returned may
- * vary depending on the container in which the application is
+ * vary depending on the container in which the application is
* deployed. It may be an implementation native to the container (eg
* org.eclipse.jetty.server.AsyncContinuation) or one of the utility
* implementations provided such as an internal FauxContinuation
* or a real implementation like {@link org.eclipse.jetty.continuation.Servlet3Continuation}.
- * @param request The request
+ * @param request The request
* @return a Continuation instance
*/
public static Continuation getContinuation(ServletRequest request)
@@ -106,10 +105,10 @@ public class ContinuationSupport
Continuation continuation = (Continuation) request.getAttribute(Continuation.ATTRIBUTE);
if (continuation!=null)
return continuation;
-
+
while (request instanceof ServletRequestWrapper)
request=((ServletRequestWrapper)request).getRequest();
-
+
if (__servlet3 )
{
try
diff --git a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/Servlet3Continuation.java b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/Servlet3Continuation.java
index 9486b725ad8..26323372c49 100644
--- a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/Servlet3Continuation.java
+++ b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/Servlet3Continuation.java
@@ -3,7 +3,6 @@ package org.eclipse.jetty.continuation;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-
import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
@@ -16,7 +15,7 @@ import javax.servlet.ServletResponseWrapper;
/* ------------------------------------------------------------ */
/**
* This implementation of Continuation is used by {@link ContinuationSupport}
- * when it detects that the application has been deployed in a non-jetty Servlet 3
+ * when it detects that the application has been deployed in a non-jetty Servlet 3
* server.
*/
public class Servlet3Continuation implements Continuation
@@ -24,11 +23,11 @@ public class Servlet3Continuation implements Continuation
// Exception reused for all continuations
// Turn on debug in ContinuationFilter to see real stack trace.
private final static ContinuationThrowable __exception = new ContinuationThrowable();
-
+
private final ServletRequest _request;
private ServletResponse _response;
private AsyncContext _context;
- private List _listeners=new ArrayList();
+ private List _listeners=new ArrayList();
private volatile boolean _initial=true;
private volatile boolean _resumed=false;
private volatile boolean _expired=false;
@@ -59,7 +58,6 @@ public class Servlet3Continuation implements Continuation
public void onTimeout(AsyncEvent event) throws IOException
{
_initial=false;
- System.err.println("Doing dispatch on timed out continuation for "+_request.getAttribute("FOO"));
event.getAsyncContext().dispatch();
}
});
@@ -91,7 +89,7 @@ public class Servlet3Continuation implements Continuation
listener.onTimeout(Servlet3Continuation.this);
}
};
-
+
if (_context!=null)
_context.addListener(wrapped);
else
@@ -171,7 +169,7 @@ public class Servlet3Continuation implements Continuation
_expired=false;
_context=_request.startAsync();
_context.setTimeout(_timeoutMs);
-
+
for (AsyncListener listener:_listeners)
_context.addListener(listener);
_listeners.clear();
@@ -184,7 +182,7 @@ public class Servlet3Continuation implements Continuation
_expired=false;
_context=_request.startAsync();
_context.setTimeout(_timeoutMs);
-
+
for (AsyncListener listener:_listeners)
_context.addListener(listener);
_listeners.clear();
diff --git a/jetty-distribution/pom.xml b/jetty-distribution/pom.xml
index e93d75c3656..fb442e3963d 100644
--- a/jetty-distribution/pom.xml
+++ b/jetty-distribution/pom.xml
@@ -103,6 +103,16 @@
${assembly-directory}/webappstest.war
+
+ org.eclipse.jetty.spdy
+ spdy-jetty-http-webapp
+ ${project.version}
+ war
+ true
+ **
+ ${assembly-directory}/webapps
+ spdy.war
+ org.eclipse.jettyjetty-start
@@ -124,12 +134,24 @@
org.eclipse.jetty
- org.eclipse.jetty.orbit
+ org.eclipse.jetty.orbit,org.eclipse.jetty.spdyjetty-all,jetty-start,jetty-monitor,jetty-jspjar${assembly-directory}/lib
+
+ copy-lib-spdy-deps
+ generate-resources
+
+ copy-dependencies
+
+
+ org.eclipse.jetty.spdy
+ jar
+ ${assembly-directory}/lib/spdy
+
+ copy-orbit-servlet-api-depsgenerate-resources
@@ -222,7 +244,7 @@
unpack-dependencies
- org.eclipse.jetty
+ org.eclipse.jetty,org.eclipse.jetty.spdyconfigfalseMETA-INF/**
@@ -398,6 +420,27 @@
jetty-overlay-deployer${project.version}
+
+ org.eclipse.jetty.spdy
+ spdy-core
+ ${project.version}
+
+
+ org.eclipse.jetty.spdy
+ spdy-jetty
+ ${project.version}
+
+
+ org.eclipse.jetty.spdy
+ spdy-jetty-http
+ ${project.version}
+
+
+ org.eclipse.jetty.spdy
+ spdy-jetty-http-webapp
+ ${project.version}
+ war
+ org.eclipse.jetty.aggregatejetty-all
diff --git a/jetty-http/pom.xml b/jetty-http/pom.xml
index 5f232e3100e..51d9367641e 100644
--- a/jetty-http/pom.xml
+++ b/jetty-http/pom.xml
@@ -1,4 +1,5 @@
-
+
+jetty-projectorg.eclipse.jetty
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
index 36d38a7dea9..427ea48398b 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
@@ -295,7 +295,6 @@ public class HttpFields
/* -------------------------------------------------------------- */
private final ArrayList _fields = new ArrayList(20);
private final HashMap _names = new HashMap(32);
- private final int _maxCookieVersion;
/* ------------------------------------------------------------ */
/**
@@ -303,19 +302,8 @@ public class HttpFields
*/
public HttpFields()
{
- _maxCookieVersion=1;
}
- /* ------------------------------------------------------------ */
- /**
- * Constructor.
- */
- public HttpFields(int maxCookieVersion)
- {
- _maxCookieVersion=maxCookieVersion;
- }
-
-
// TODO externalize this cache so it can be configurable
private static ConcurrentMap __cache = new ConcurrentHashMap();
private static int __cacheSize = Integer.getInteger("org.eclipse.jetty.http.HttpFields.CACHE",2000);
@@ -971,7 +959,7 @@ public class HttpFields
final boolean isHttpOnly,
int version)
{
- String delim=_maxCookieVersion==0?"":__COOKIE_DELIM;
+ String delim=__COOKIE_DELIM;
// Check arguments
if (name == null || name.length() == 0)
@@ -980,29 +968,18 @@ public class HttpFields
// Format value and params
StringBuilder buf = new StringBuilder(128);
String name_value_params;
- boolean quoted = QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
+ QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
buf.append('=');
String start=buf.toString();
if (value != null && value.length() > 0)
- quoted|=QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
-
- // upgrade to version 1 cookies if quoted.
- if (quoted&&version==0 && _maxCookieVersion>=1)
- version=1;
+ QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
- if (version>_maxCookieVersion)
- version=_maxCookieVersion;
-
- if (version > 0)
+ if (comment != null && comment.length() > 0)
{
- buf.append(";Version=");
- buf.append(version);
- if (comment != null && comment.length() > 0)
- {
- buf.append(";Comment=");
- QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
- }
+ buf.append(";Comment=");
+ QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
}
+
if (path != null && path.length() > 0)
{
buf.append(";Path=");
@@ -1019,23 +996,19 @@ public class HttpFields
if (maxAge >= 0)
{
- // Always add the expires param as some browsers still don't handle max-age
- buf.append(";Expires=");
- if (maxAge == 0)
- buf.append(__01Jan1970_COOKIE);
- else
- formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
-
+ // Always add the expires param as some browsers still don't handle max-age
+ buf.append(";Expires=");
+ if (maxAge == 0)
+ buf.append(__01Jan1970_COOKIE);
+ else
+ formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
+
if (version >0)
{
buf.append(";Max-Age=");
buf.append(maxAge);
}
}
- else if (version > 0)
- {
- buf.append(";Discard");
- }
if (isSecure)
buf.append(";Secure");
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
index c7d7d39f88a..0b4053c15e3 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
@@ -260,7 +260,6 @@ public class HttpParser implements Parser
{
_state=STATE_END;
_handler.messageComplete(_contentPosition);
- returnBuffers();
return 1;
}
@@ -326,7 +325,6 @@ public class HttpParser implements Parser
if (!isComplete() && !isIdle())
throw new EofException();
- returnBuffers();
return -1;
}
length=_buffer.length();
@@ -440,7 +438,6 @@ public class HttpParser implements Parser
_state=STATE_SEEKING_EOF;
_handler.headerComplete();
_handler.messageComplete(_contentPosition);
- returnBuffers();
return 1;
}
break;
@@ -470,7 +467,6 @@ public class HttpParser implements Parser
_state=STATE_SEEKING_EOF;
_handler.headerComplete();
_handler.messageComplete(_contentPosition);
- returnBuffers();
return 1;
}
}
@@ -634,7 +630,6 @@ public class HttpParser implements Parser
_handler.headerComplete();
_state=_persistent||(_responseStatus>=100&&_responseStatus<200)?STATE_END:STATE_SEEKING_EOF;
_handler.messageComplete(_contentPosition);
- returnBuffers();
return 1;
default:
@@ -840,7 +835,6 @@ public class HttpParser implements Parser
{
_state=_persistent?STATE_END:STATE_SEEKING_EOF;
_handler.messageComplete(_contentPosition);
- returnBuffers();
return 1;
}
@@ -860,7 +854,6 @@ public class HttpParser implements Parser
{
_state=_persistent?STATE_END:STATE_SEEKING_EOF;
_handler.messageComplete(_contentPosition);
- returnBuffers();
}
// TODO adjust the _buffer to keep unconsumed content
return 1;
@@ -895,7 +888,6 @@ public class HttpParser implements Parser
_eol=_buffer.get();
_state=_persistent?STATE_END:STATE_SEEKING_EOF;
_handler.messageComplete(_contentPosition);
- returnBuffers();
return 1;
}
else
@@ -926,7 +918,6 @@ public class HttpParser implements Parser
_eol=_buffer.get();
_state=_persistent?STATE_END:STATE_SEEKING_EOF;
_handler.messageComplete(_contentPosition);
- returnBuffers();
return 1;
}
else
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/AbstractCompressedStream.java b/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/AbstractCompressedStream.java
new file mode 100644
index 00000000000..77ac1fe41d0
--- /dev/null
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/AbstractCompressedStream.java
@@ -0,0 +1,345 @@
+// ========================================================================
+// Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// 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.opensource.org/licenses/apache2.0.php
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+
+package org.eclipse.jetty.http.gzip;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.zip.DeflaterOutputStream;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.util.ByteArrayOutputStream2;
+
+/* ------------------------------------------------------------ */
+/**
+ * Skeletal implementation of a CompressedStream. This class adds compression features to a ServletOutputStream and takes care of setting response headers, etc.
+ * Major work and configuration is done here. Subclasses using different kinds of compression only have to implement the abstract methods doCompress() and
+ * setContentEncoding() using the desired compression and setting the appropriate Content-Encoding header string.
+ */
+public abstract class AbstractCompressedStream extends ServletOutputStream
+{
+ private final String _encoding;
+ protected HttpServletRequest _request;
+ protected HttpServletResponse _response;
+ protected OutputStream _out;
+ protected ByteArrayOutputStream2 _bOut;
+ protected DeflaterOutputStream _compressedOutputStream;
+ protected boolean _closed;
+ protected int _bufferSize;
+ protected int _minCompressSize;
+ protected long _contentLength;
+ protected boolean _doNotCompress;
+
+ /**
+ * Instantiates a new compressed stream.
+ *
+ * @param request
+ * the request
+ * @param response
+ * the response
+ * @param contentLength
+ * the content length
+ * @param bufferSize
+ * the buffer size
+ * @param minCompressSize
+ * the min compress size
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public AbstractCompressedStream(String encoding,HttpServletRequest request, HttpServletResponse response, long contentLength, int bufferSize, int minCompressSize)
+ throws IOException
+ {
+ _encoding=encoding;
+ _request = request;
+ _response = response;
+ _contentLength = contentLength;
+ _bufferSize = bufferSize;
+ _minCompressSize = minCompressSize;
+ if (minCompressSize == 0)
+ doCompress();
+ }
+
+ /**
+ * Reset buffer.
+ */
+ public void resetBuffer()
+ {
+ if (_response.isCommitted())
+ throw new IllegalStateException("Committed");
+ _closed = false;
+ _out = null;
+ _bOut = null;
+ if (_compressedOutputStream != null)
+ _response.setHeader("Content-Encoding",null);
+ _compressedOutputStream = null;
+ _doNotCompress = false;
+ }
+
+ /**
+ * Sets the content length.
+ *
+ * @param length
+ * the new content length
+ */
+ public void setContentLength(long length)
+ {
+ _contentLength = length;
+ if (_doNotCompress && length >= 0)
+ {
+ if (_contentLength < Integer.MAX_VALUE)
+ _response.setContentLength((int)_contentLength);
+ else
+ _response.setHeader("Content-Length",Long.toString(_contentLength));
+ }
+ }
+
+ /* ------------------------------------------------------------ */
+ /**
+ * @see java.io.OutputStream#flush()
+ */
+ @Override
+ public void flush() throws IOException
+ {
+ if (_out == null || _bOut != null)
+ {
+ if (_contentLength > 0 && _contentLength < _minCompressSize)
+ doNotCompress();
+ else
+ doCompress();
+ }
+
+ _out.flush();
+ }
+
+ /* ------------------------------------------------------------ */
+ /**
+ * @see java.io.OutputStream#close()
+ */
+ @Override
+ public void close() throws IOException
+ {
+ if (_closed)
+ return;
+
+ if (_request.getAttribute("javax.servlet.include.request_uri") != null)
+ flush();
+ else
+ {
+ if (_bOut != null)
+ {
+ if (_contentLength < 0)
+ _contentLength = _bOut.getCount();
+ if (_contentLength < _minCompressSize)
+ doNotCompress();
+ else
+ doCompress();
+ }
+ else if (_out == null)
+ {
+ doNotCompress();
+ }
+
+ if (_compressedOutputStream != null)
+ _compressedOutputStream.close();
+ else
+ _out.close();
+ _closed = true;
+ }
+ }
+
+ /**
+ * Finish.
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public void finish() throws IOException
+ {
+ if (!_closed)
+ {
+ if (_out == null || _bOut != null)
+ {
+ if (_contentLength > 0 && _contentLength < _minCompressSize)
+ doNotCompress();
+ else
+ doCompress();
+ }
+
+ if (_compressedOutputStream != null && !_closed)
+ {
+ _closed = true;
+ _compressedOutputStream.close();
+ }
+ }
+ }
+
+ /* ------------------------------------------------------------ */
+ /**
+ * @see java.io.OutputStream#write(int)
+ */
+ @Override
+ public void write(int b) throws IOException
+ {
+ checkOut(1);
+ _out.write(b);
+ }
+
+ /* ------------------------------------------------------------ */
+ /**
+ * @see java.io.OutputStream#write(byte[])
+ */
+ @Override
+ public void write(byte b[]) throws IOException
+ {
+ checkOut(b.length);
+ _out.write(b);
+ }
+
+ /* ------------------------------------------------------------ */
+ /**
+ * @see java.io.OutputStream#write(byte[], int, int)
+ */
+ @Override
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ checkOut(len);
+ _out.write(b,off,len);
+ }
+
+ /**
+ * Do compress.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ public void doCompress() throws IOException
+ {
+ if (_compressedOutputStream==null)
+ {
+ if (_response.isCommitted())
+ throw new IllegalStateException();
+
+ setHeader("Content-Encoding", _encoding);
+
+ if (_response.containsHeader("Content-Encoding"))
+ {
+ _out=_compressedOutputStream=createStream();
+
+ if (_bOut!=null)
+ {
+ _out.write(_bOut.getBuf(),0,_bOut.getCount());
+ _bOut=null;
+ }
+ }
+ else
+ doNotCompress();
+ }
+ }
+
+ /**
+ * Do not compress.
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public void doNotCompress() throws IOException
+ {
+ if (_compressedOutputStream != null)
+ throw new IllegalStateException();
+ if (_out == null || _bOut != null)
+ {
+ _doNotCompress = true;
+
+ _out = _response.getOutputStream();
+ setContentLength(_contentLength);
+
+ if (_bOut != null)
+ _out.write(_bOut.getBuf(),0,_bOut.getCount());
+ _bOut = null;
+ }
+ }
+
+ /**
+ * Check out.
+ *
+ * @param length
+ * the length
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ private void checkOut(int length) throws IOException
+ {
+ if (_closed)
+ throw new IOException("CLOSED");
+
+ if (_out == null)
+ {
+ if (_response.isCommitted() || (_contentLength >= 0 && _contentLength < _minCompressSize))
+ doNotCompress();
+ else if (length > _minCompressSize)
+ doCompress();
+ else
+ _out = _bOut = new ByteArrayOutputStream2(_bufferSize);
+ }
+ else if (_bOut != null)
+ {
+ if (_response.isCommitted() || (_contentLength >= 0 && _contentLength < _minCompressSize))
+ doNotCompress();
+ else if (length >= (_bOut.getBuf().length - _bOut.getCount()))
+ doCompress();
+ }
+ }
+
+ /**
+ * @see org.eclipse.jetty.http.gzip.CompressedStream#getOutputStream()
+ */
+ public OutputStream getOutputStream()
+ {
+ return _out;
+ }
+
+ /**
+ * @see org.eclipse.jetty.http.gzip.CompressedStream#isClosed()
+ */
+ public boolean isClosed()
+ {
+ return _closed;
+ }
+
+ /**
+ * Allows derived implementations to replace PrintWriter implementation.
+ */
+ protected PrintWriter newWriter(OutputStream out, String encoding) throws UnsupportedEncodingException
+ {
+ return encoding == null?new PrintWriter(out):new PrintWriter(new OutputStreamWriter(out,encoding));
+ }
+
+ protected void setHeader(String name,String value)
+ {
+ _response.setHeader(name, value);
+ }
+
+ /**
+ * Create the stream fitting to the underlying compression type.
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ protected abstract DeflaterOutputStream createStream() throws IOException;
+
+}
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/GzipResponseWrapper.java b/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/CompressedResponseWrapper.java
similarity index 63%
rename from jetty-http/src/main/java/org/eclipse/jetty/http/gzip/GzipResponseWrapper.java
rename to jetty-http/src/main/java/org/eclipse/jetty/http/gzip/CompressedResponseWrapper.java
index 093e127d902..1431f3868e2 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/GzipResponseWrapper.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/CompressedResponseWrapper.java
@@ -1,5 +1,5 @@
// ========================================================================
-// Copyright (c) Webtide LLC
+// Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
@@ -11,7 +11,6 @@
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
-
package org.eclipse.jetty.http.gzip;
import java.io.IOException;
@@ -28,42 +27,34 @@ import javax.servlet.http.HttpServletResponseWrapper;
import org.eclipse.jetty.util.StringUtil;
-
-/* ------------------------------------------------------------ */
+/*------------------------------------------------------------ */
/**
*/
-public class GzipResponseWrapper extends HttpServletResponseWrapper
+public abstract class CompressedResponseWrapper extends HttpServletResponseWrapper
{
- public static final int DEFAULT_BUFFER_SIZE = 8192;
- public static final int DEFAULT_MIN_GZIP_SIZE = 256;
- private HttpServletRequest _request;
+ public static final int DEFAULT_BUFFER_SIZE = 8192;
+ public static final int DEFAULT_MIN_COMPRESS_SIZE = 256;
+
private Set _mimeTypes;
private int _bufferSize=DEFAULT_BUFFER_SIZE;
- private int _minGzipSize=DEFAULT_MIN_GZIP_SIZE;
+ private int _minCompressSize=DEFAULT_MIN_COMPRESS_SIZE;
+ protected HttpServletRequest _request;
private PrintWriter _writer;
- private GzipStream _gzStream;
+ private AbstractCompressedStream _compressedStream;
private long _contentLength=-1;
- private boolean _noGzip;
+ private boolean _noCompression;
- /**
- * Instantiates a new gzip response wrapper.
- *
- * @param request the request
- * @param response the response
- */
- public GzipResponseWrapper(HttpServletRequest request, HttpServletResponse response)
+ public CompressedResponseWrapper(HttpServletRequest request, HttpServletResponse response)
{
super(response);
- _request=request;
+ _request = request;
}
/* ------------------------------------------------------------ */
/**
- * Sets the mime types.
- *
- * @param mimeTypes the new mime types
+ * @see org.eclipse.jetty.http.gzip.CompressedResponseWrapper#setMimeTypes(java.util.Set)
*/
public void setMimeTypes(Set mimeTypes)
{
@@ -72,8 +63,9 @@ public class GzipResponseWrapper extends HttpServletResponseWrapper
/* ------------------------------------------------------------ */
/**
- * @see javax.servlet.ServletResponseWrapper#setBufferSize(int)
+ * @see org.eclipse.jetty.http.gzip.CompressedResponseWrapper#setBufferSize(int)
*/
+ @Override
public void setBufferSize(int bufferSize)
{
_bufferSize = bufferSize;
@@ -81,64 +73,66 @@ public class GzipResponseWrapper extends HttpServletResponseWrapper
/* ------------------------------------------------------------ */
/**
- * Sets the min gzip size.
- *
- * @param minGzipSize the new min gzip size
+ * @see org.eclipse.jetty.http.gzip.CompressedResponseWrapper#setMinCompressSize(int)
*/
- public void setMinGzipSize(int minGzipSize)
+ public void setMinCompressSize(int minCompressSize)
{
- _minGzipSize = minGzipSize;
+ _minCompressSize = minCompressSize;
}
/* ------------------------------------------------------------ */
/**
- * @see javax.servlet.ServletResponseWrapper#setContentType(java.lang.String)
+ * @see org.eclipse.jetty.http.gzip.CompressedResponseWrapper#setContentType(java.lang.String)
*/
+ @Override
public void setContentType(String ct)
{
super.setContentType(ct);
-
+
if (ct!=null)
{
int colon=ct.indexOf(";");
if (colon>0)
ct=ct.substring(0,colon);
}
-
- if ((_gzStream==null || _gzStream._out==null) &&
+
+ if ((_compressedStream==null || _compressedStream.getOutputStream()==null) &&
(_mimeTypes==null && ct!=null && ct.contains("gzip") ||
_mimeTypes!=null && (ct==null||!_mimeTypes.contains(StringUtil.asciiToLowerCase(ct)))))
{
- noGzip();
+ noCompression();
}
}
/* ------------------------------------------------------------ */
/**
- * @see javax.servlet.http.HttpServletResponseWrapper#setStatus(int, java.lang.String)
+ * @see org.eclipse.jetty.http.gzip.CompressedResponseWrapper#setStatus(int, java.lang.String)
*/
+ @Override
public void setStatus(int sc, String sm)
{
super.setStatus(sc,sm);
if (sc<200 || sc==204 || sc==205 || sc>=300)
- noGzip();
+ noCompression();
}
/* ------------------------------------------------------------ */
/**
- * @see javax.servlet.http.HttpServletResponseWrapper#setStatus(int)
+ * @see org.eclipse.jetty.http.gzip.CompressedResponseWrapper#setStatus(int)
*/
+ @Override
public void setStatus(int sc)
{
super.setStatus(sc);
if (sc<200 || sc==204 || sc==205 ||sc>=300)
- noGzip();
+ noCompression();
}
/* ------------------------------------------------------------ */
/**
- * @see javax.servlet.ServletResponseWrapper#setContentLength(int)
+ * @see org.eclipse.jetty.http.gzip.CompressedResponseWrapper#setContentLength(int)
*/
+ @Override
public void setContentLength(int length)
{
setContentLength((long)length);
@@ -148,9 +142,9 @@ public class GzipResponseWrapper extends HttpServletResponseWrapper
protected void setContentLength(long length)
{
_contentLength=length;
- if (_gzStream!=null)
- _gzStream.setContentLength(length);
- else if (_noGzip && _contentLength>=0)
+ if (_compressedStream!=null)
+ _compressedStream.setContentLength(length);
+ else if (_noCompression && _contentLength>=0)
{
HttpServletResponse response = (HttpServletResponse)getResponse();
if(_contentLength=0)
- {
- if(_contentLength0 && _contentLength<_minGzipSize)
- doNotGzip();
- else
- doGzip();
- }
-
- _out.flush();
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#close()
- */
- public void close() throws IOException
- {
- if (_closed)
- return;
-
- if (_request.getAttribute("javax.servlet.include.request_uri")!=null)
- flush();
- else
- {
- if (_bOut!=null)
- {
- if (_contentLength<0)
- _contentLength=_bOut.getCount();
- if (_contentLength<_minGzipSize)
- doNotGzip();
- else
- doGzip();
- }
- else if (_out==null)
- {
- doNotGzip();
- }
-
- if (_gzOut!=null)
- _gzOut.close();
- else
- _out.close();
- _closed=true;
- }
- }
-
- /**
- * Finish.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- */
- public void finish() throws IOException
- {
- if (!_closed)
- {
- if (_out==null || _bOut!=null)
- {
- if (_contentLength>0 && _contentLength<_minGzipSize)
- doNotGzip();
- else
- doGzip();
- }
-
- if (_gzOut!=null && !_closed)
- {
- _closed=true;
- _gzOut.close();
- }
- }
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#write(int)
- */
- public void write(int b) throws IOException
- {
- checkOut(1);
- _out.write(b);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#write(byte[])
- */
- public void write(byte b[]) throws IOException
- {
- checkOut(b.length);
- _out.write(b);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#write(byte[], int, int)
- */
- public void write(byte b[], int off, int len) throws IOException
- {
- checkOut(len);
- _out.write(b,off,len);
- }
-
- /**
- * Sets the content encoding gzip.
- *
- * @return true, if successful
- */
- protected boolean setContentEncodingGzip()
- {
- _response.setHeader("Content-Encoding", "gzip");
- return _response.containsHeader("Content-Encoding");
- }
-
- /**
- * Do gzip.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- */
- public void doGzip() throws IOException
- {
- if (_gzOut==null)
- {
- if (_response.isCommitted())
- throw new IllegalStateException();
-
- if (setContentEncodingGzip())
- {
- _out=_gzOut=new GZIPOutputStream(_response.getOutputStream(),_bufferSize);
-
- if (_bOut!=null)
- {
- _out.write(_bOut.getBuf(),0,_bOut.getCount());
- _bOut=null;
- }
- }
- else
- doNotGzip();
- }
- }
-
- /**
- * Do not gzip.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- */
- public void doNotGzip() throws IOException
- {
- if (_gzOut!=null)
- throw new IllegalStateException();
- if (_out==null || _bOut!=null )
- {
- _doNotGzip = true;
-
- _out=_response.getOutputStream();
- setContentLength(_contentLength);
-
- if (_bOut!=null)
- _out.write(_bOut.getBuf(),0,_bOut.getCount());
- _bOut=null;
- }
- }
-
- /**
- * Check out.
- *
- * @param length the length
- * @throws IOException Signals that an I/O exception has occurred.
- */
- private void checkOut(int length) throws IOException
- {
- if (_closed)
- throw new IOException("CLOSED");
-
- if (_out==null)
- {
- if (_response.isCommitted() || (_contentLength>=0 && _contentLength<_minGzipSize))
- doNotGzip();
- else if (length>_minGzipSize)
- doGzip();
- else
- _out=_bOut=new ByteArrayOutputStream2(_bufferSize);
- }
- else if (_bOut!=null)
- {
- if (_response.isCommitted() || (_contentLength>=0 && _contentLength<_minGzipSize))
- doNotGzip();
- else if (length>=(_bOut.getBuf().length -_bOut.getCount()))
- doGzip();
- }
- }
-
- /**
- * Allows derived implementations to replace PrintWriter implementation.
- */
- protected PrintWriter newWriter(OutputStream out,String encoding) throws UnsupportedEncodingException
- {
- return encoding==null?new PrintWriter(out):new PrintWriter(new OutputStreamWriter(out,encoding));
- }
-}
-
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
index 3ae9a409fd0..4d36e9aa3b7 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
@@ -361,28 +361,18 @@ public class HttpFieldsTest
fields.clear();
fields.addSetCookie("everything","wrong","wrong","wrong",0,"to be replaced",true,true,0);
fields.addSetCookie("everything","value","domain","path",0,"comment",true,true,0);
- assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",fields.getStringField("Set-Cookie"));
+ assertEquals("everything=value;Comment=comment;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",fields.getStringField("Set-Cookie"));
Enumeration e =fields.getValues("Set-Cookie");
assertTrue(e.hasMoreElements());
- assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",e.nextElement());
+ assertEquals("everything=value;Comment=comment;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",e.nextElement());
assertFalse(e.hasMoreElements());
- assertEquals("Thu, 01 Jan 1970 00:00:00 GMT",fields.getStringField("Expires"));
-
+ assertEquals("Thu, 01 Jan 1970 00:00:00 GMT",fields.getStringField("Expires"));
fields.clear();
fields.addSetCookie("ev erything","va lue","do main","pa th",1,"co mment",true,true,2);
String setCookie=fields.getStringField("Set-Cookie");
- assertTrue(setCookie.startsWith("\"ev erything\"=\"va lue\";Version=1;Comment=\"co mment\";Path=\"pa th\";Domain=\"do main\";Expires="));
+ assertTrue(setCookie.startsWith("\"ev erything\"=\"va lue\";Comment=\"co mment\";Path=\"pa th\";Domain=\"do main\";Expires="));
assertTrue(setCookie.endsWith("GMT;Max-Age=1;Secure;HttpOnly"));
-
- fields.clear();
- fields.addSetCookie("name","value",null,null,-1,null,false,false,0);
- setCookie=fields.getStringField("Set-Cookie");
- assertEquals(-1,setCookie.indexOf("Version="));
- fields.clear();
- fields.addSetCookie("name","v a l u e",null,null,-1,null,false,false,0);
- setCookie=fields.getStringField("Set-Cookie");
- assertEquals(17,setCookie.indexOf("Version=1"));
fields.clear();
fields.addSetCookie("json","{\"services\":[\"cwa\", \"aa\"]}",null,null,-1,null,false,false,-1);
@@ -401,12 +391,6 @@ public class HttpFieldsTest
e=fields.getValues("Set-Cookie");
assertEquals("name=more;Domain=domain",e.nextElement());
assertEquals("foo=bob;Domain=domain",e.nextElement());
-
- fields=new HttpFields(0);
- fields.addSetCookie("name","value==",null,null,-1,null,false,false,0);
- setCookie=fields.getStringField("Set-Cookie");
- assertEquals("name=value==",setCookie);
-
}
private Set enum2set(Enumeration e)
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorClientTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorClientTest.java
index 46cfd4e2953..15c53bc9c08 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorClientTest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorClientTest.java
@@ -13,9 +13,6 @@
package org.eclipse.jetty.http;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
@@ -28,6 +25,9 @@ import org.eclipse.jetty.io.SimpleBuffers;
import org.eclipse.jetty.io.View;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class HttpGeneratorClientTest
{
public final static String CONTENT="The quick brown fox jumped over the lazy dog.\nNow is the time for all good men to come to the aid of the party\nThe moon is blue to a fish in love.\n";
@@ -52,7 +52,7 @@ public class HttpGeneratorClientTest
generator.completeHeader(fields,false);
- generator.addContent(new ByteArrayBuffer(content),true);
+ generator.addContent(new ByteArrayBuffer(content).asMutableBuffer(),true);
generator.flushBuffer();
generator.complete();
generator.flushBuffer();
@@ -77,7 +77,7 @@ public class HttpGeneratorClientTest
String content = "The quick brown fox jumped over the lazy dog";
- generator.addContent(new ByteArrayBuffer(content),true);
+ generator.addContent(new ByteArrayBuffer(content).asMutableBuffer(),true);
generator.completeHeader(fields,true);
generator.flushBuffer();
@@ -106,7 +106,7 @@ public class HttpGeneratorClientTest
generator.completeHeader(fields,false);
- generator.addContent(new ByteArrayBuffer(content),false);
+ generator.addContent(new ByteArrayBuffer(content).asMutableBuffer(),false);
generator.flushBuffer();
generator.complete();
generator.flushBuffer();
@@ -120,7 +120,7 @@ public class HttpGeneratorClientTest
* screw up the chunking by leaving out the second chunk header.
*/
@Test
- public void testChunkedWithBackPressure() throws Exception
+ public void testChunkedWithBackPressure() throws Exception
{
final AtomicInteger availableChannelBytes = new AtomicInteger(500);
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096)
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/AsyncEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/AsyncEndPoint.java
index 992ad7a195a..5a58160ec35 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/AsyncEndPoint.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/AsyncEndPoint.java
@@ -19,7 +19,14 @@ public interface AsyncEndPoint extends ConnectedEndPoint
{
/* ------------------------------------------------------------ */
/**
- * Dispatch the endpoint to a thread to attend to it.
+ * Dispatch the endpoint if it is not already dispatched
+ *
+ */
+ public void dispatch();
+
+ /* ------------------------------------------------------------ */
+ /**
+ * Dispatch the endpoint. If it is already dispatched, schedule a redispatch
*
*/
public void asyncDispatch();
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayBuffer.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayBuffer.java
index f66a52c0018..933dbf98b28 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayBuffer.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayBuffer.java
@@ -352,7 +352,8 @@ public class ByteArrayBuffer extends AbstractBuffer
throws IOException
{
out.write(_bytes,getIndex(),length());
- clear();
+ if (!isImmutable())
+ clear();
}
/* ------------------------------------------------------------ */
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java
index 029ed2f84ee..a0e4f8e96df 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java
@@ -246,7 +246,8 @@ public class ByteArrayEndPoint implements ConnectedEndPoint
}
}
int len = _out.put(buffer);
- buffer.skip(len);
+ if (!buffer.isImmutable())
+ buffer.skip(len);
return len;
}
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/bio/StreamEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/bio/StreamEndPoint.java
index a92e2e83700..0ebab0058d3 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/bio/StreamEndPoint.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/bio/StreamEndPoint.java
@@ -157,7 +157,8 @@ public class StreamEndPoint implements EndPoint
int length=buffer.length();
if (length>0)
buffer.writeTo(_out);
- buffer.clear();
+ if (!buffer.isImmutable())
+ buffer.clear();
return length;
}
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/bio/StringEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/bio/StringEndPoint.java
index 1698249d438..e55d4aeb6b6 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/bio/StringEndPoint.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/bio/StringEndPoint.java
@@ -70,10 +70,12 @@ public class StringEndPoint extends StreamEndPoint
_bout.reset();
return s;
}
- catch(Exception e)
+ catch(final Exception e)
{
- e.printStackTrace();
- throw new IllegalStateException(_encoding+": "+e.toString());
+ throw new IllegalStateException(_encoding)
+ {
+ {initCause(e);}
+ };
}
}
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java
index fa8a02d505a..828e38e3fcb 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java
@@ -280,24 +280,17 @@ public class ChannelEndPoint implements EndPoint
if (buf instanceof NIOBuffer)
{
final NIOBuffer nbuf = (NIOBuffer)buf;
- final ByteBuffer bbuf=nbuf.getByteBuffer();
-
- //noinspection SynchronizationOnLocalVariableOrMethodParameter
- synchronized(bbuf)
+ final ByteBuffer bbuf=nbuf.getByteBuffer().asReadOnlyBuffer();
+ try
{
- try
- {
- bbuf.position(buffer.getIndex());
- bbuf.limit(buffer.putIndex());
- len=_channel.write(bbuf);
- }
- finally
- {
- if (len>0)
- buffer.skip(len);
- bbuf.position(0);
- bbuf.limit(bbuf.capacity());
- }
+ bbuf.position(buffer.getIndex());
+ bbuf.limit(buffer.putIndex());
+ len=_channel.write(bbuf);
+ }
+ finally
+ {
+ if (len>0)
+ buffer.skip(len);
}
}
else if (buf instanceof RandomAccessFileBuffer)
@@ -363,52 +356,29 @@ public class ChannelEndPoint implements EndPoint
synchronized(this)
{
- // We must sync because buffers may be shared (eg nbuf1 is likely to be cached content).
- //noinspection SynchronizationOnLocalVariableOrMethodParameter
- synchronized(bbuf0)
+ // Adjust position indexs of buf0 and buf1
+ bbuf0=bbuf0.asReadOnlyBuffer();
+ bbuf0.position(header.getIndex());
+ bbuf0.limit(header.putIndex());
+ bbuf1=bbuf1.asReadOnlyBuffer();
+ bbuf1.position(buffer.getIndex());
+ bbuf1.limit(buffer.putIndex());
+
+ _gather2[0]=bbuf0;
+ _gather2[1]=bbuf1;
+
+ // do the gathering write.
+ length=(int)((GatheringByteChannel)_channel).write(_gather2);
+
+ int hl=header.length();
+ if (length>hl)
{
- //noinspection SynchronizationOnLocalVariableOrMethodParameter
- synchronized(bbuf1)
- {
- try
- {
- // Adjust position indexs of buf0 and buf1
- bbuf0.position(header.getIndex());
- bbuf0.limit(header.putIndex());
- bbuf1.position(buffer.getIndex());
- bbuf1.limit(buffer.putIndex());
-
- _gather2[0]=bbuf0;
- _gather2[1]=bbuf1;
-
- // do the gathering write.
- length=(int)((GatheringByteChannel)_channel).write(_gather2);
-
- int hl=header.length();
- if (length>hl)
- {
- header.clear();
- buffer.skip(length-hl);
- }
- else if (length>0)
- {
- header.skip(length);
- }
- }
- finally
- {
- // adjust buffer 0 and 1
- if (!header.isImmutable())
- header.setGetIndex(bbuf0.position());
- if (!buffer.isImmutable())
- buffer.setGetIndex(bbuf1.position());
-
- bbuf0.position(0);
- bbuf1.position(0);
- bbuf0.limit(bbuf0.capacity());
- bbuf1.limit(bbuf1.capacity());
- }
- }
+ header.clear();
+ buffer.skip(length-hl);
+ }
+ else if (length>0)
+ {
+ header.skip(length);
}
}
return length;
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 b24ebd8d0d9..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;
@@ -208,11 +209,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
{
synchronized(this)
{
- if (_dispatched)
- {
- throw new IllegalStateException("dispatched");
- }
- else
+ if (!_dispatched)
{
_dispatched = true;
boolean dispatched = _manager.dispatch(_handler);
@@ -685,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
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java
index 4b8e0a55d1d..b4e9791b165 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java
@@ -237,6 +237,9 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
/* ------------------------------------------------------------ */
public void onClose()
{
+ Connection connection = _sslEndPoint.getConnection();
+ if (connection != null && connection != this)
+ connection.onClose();
}
/* ------------------------------------------------------------ */
@@ -408,8 +411,8 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
}
// If we are reading into the temp buffer and it has some content, then we should be dispatched.
- if (toFill==_unwrapBuf && _unwrapBuf.hasContent())
- _aEndp.asyncDispatch();
+ if (toFill==_unwrapBuf && _unwrapBuf.hasContent() && !_connection.isSuspended())
+ _aEndp.dispatch();
}
finally
{
@@ -550,7 +553,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
break;
case BUFFER_OVERFLOW:
- _logger.debug("{} unwrap {} {}->{}",_session,result.getStatus(),_inbound.toDetailString(),buffer.toDetailString());
+ if (_logger.isDebugEnabled()) _logger.debug("{} unwrap {} {}->{}",_session,result.getStatus(),_inbound.toDetailString(),buffer.toDetailString());
break;
case OK:
@@ -718,6 +721,11 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
process(null, null);
}
+ public void dispatch()
+ {
+ _aEndp.dispatch();
+ }
+
public void asyncDispatch()
{
_aEndp.asyncDispatch();
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 @@
-->
diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionManager.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionManager.java
index e4eab9e057f..085522f270a 100644
--- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionManager.java
+++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionManager.java
@@ -245,21 +245,37 @@ public class MongoSessionManager extends NoSqlSessionManager
{
for (String name : attrs.keySet())
{
- if ( __METADATA.equals(name) )
+ if (__METADATA.equals(name))
{
continue;
}
-
+
String attr = decodeName(name);
Object value = decodeValue(attrs.get(name));
- session.doPutOrRemove(attr,value);
- session.bindValue(attr,value);
+
+ if (attrs.keySet().contains(name))
+ {
+ session.doPutOrRemove(attr,value);
+ session.bindValue(attr,value);
+ }
+ else
+ {
+ session.doPutOrRemove(attr,value);
+ }
+ }
+ // cleanup, remove values from session, that don't exist in data anymore:
+ for (String name : session.getNames())
+ {
+ if (!attrs.keySet().contains(name))
+ {
+ session.doPutOrRemove(name,null);
+ session.unbindValue(name,session.getAttribute(name));
+ }
}
}
session.didActivate();
-
-
+
return version;
}
catch (Exception e)
@@ -348,7 +364,7 @@ public class MongoSessionManager extends NoSqlSessionManager
BasicDBObject remove = new BasicDBObject();
BasicDBObject unsets = new BasicDBObject();
unsets.put(getContextKey(),1);
- remove.put("$unsets",unsets);
+ remove.put("$unset",unsets);
_sessions.update(key,remove);
return true;
diff --git a/jetty-npn/pom.xml b/jetty-npn/pom.xml
index 243f4cdfa84..063dffda7a0 100644
--- a/jetty-npn/pom.xml
+++ b/jetty-npn/pom.xml
@@ -2,13 +2,35 @@
org.eclipse.jetty
- jetty-project
- 8.1.3-SNAPSHOT
+ jetty-parent
+ 194.0.0org.eclipse.jetty.npnnpn-api
+ 1.0.1-SNAPSHOTJetty :: Next Protocol Negotiation :: API
+
+ scm:git:http://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project.git
+ scm:git:ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project.git
+ http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-npn
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-release-plugin
+ 2.2.1
+
+ false
+ deploy
+ -Peclipse-release
+ clean install
+
+
+
+
diff --git a/jetty-osgi/jetty-osgi-boot-jsp/META-INF/MANIFEST.MF b/jetty-osgi/jetty-osgi-boot-jsp/META-INF/MANIFEST.MF
index 08335e141cb..3388173dcd0 100644
--- a/jetty-osgi/jetty-osgi-boot-jsp/META-INF/MANIFEST.MF
+++ b/jetty-osgi/jetty-osgi-boot-jsp/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Jetty-OSGi-Jasper integration
Fragment-Host: org.eclipse.jetty.osgi.boot
Bundle-SymbolicName: org.eclipse.jetty.osgi.boot.jsp
-Bundle-Version: 8.1.2.qualifier
+Bundle-Version: 8.1.3.qualifier
Bundle-Vendor: Mort Bay Consulting
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: com.sun.el;version="2.2.0";resolution:=optional,
@@ -16,7 +16,7 @@ Import-Package: com.sun.el;version="2.2.0";resolution:=optional,
javax.servlet.jsp.jstl.tlv;version="1.2.0";resolution:=optional,
javax.servlet.jsp.resources;version="2.1.0",
javax.servlet.jsp.tagext;version="2.1.0",
- javax.servlet.resources;version="2.5.0",
+ javax.servlet.resources;version="2.6.0",
org.apache.jasper;version="2.2.2";resolution:=optional,
org.apache.jasper.compiler;version="2.2.2";resolution:=optional,
org.apache.jasper.compiler.tagplugin;version="2.2.2";resolution:=optional,
diff --git a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/PluggableWebAppRegistrationCustomizerImpl.java b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/PluggableWebAppRegistrationCustomizerImpl.java
index 3dc2f896c45..79854f2c99f 100644
--- a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/PluggableWebAppRegistrationCustomizerImpl.java
+++ b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/PluggableWebAppRegistrationCustomizerImpl.java
@@ -28,98 +28,106 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
/**
- * Plug bundles that contains tld files so that jasper will discover them
- * and set them up in jetty.
+ * Plug bundles that contains tld files so that jasper will discover them and
+ * set them up in jetty.
*
- * For example: -Dorg.eclipse.jetty.osgi.tldbundles=org.springframework.web.servlet,com.opensymphony.module.sitemesh
- * Otherwise use an attribute to the WebAppDeployer
- * <New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
- * ....
- * <Set name="tldBundles"><Property name="org.eclipse.jetty.osgi.tldsbundles" default="" /></Set>
- * <New>
+ * For example:
+ * -Dorg.eclipse.jetty.osgi.tldbundles=org.springframework.web.servlet
+ * ,com.opensymphony.module.sitemesh Otherwise use an attribute to the
+ * WebAppDeployer <New
+ * class="org.eclipse.jetty.deploy.providers.WebAppProvider"> .... <Set
+ * name="tldBundles"><Property name="org.eclipse.jetty.osgi.tldsbundles"
+ * default="" /></Set> <New>
*/
public class PluggableWebAppRegistrationCustomizerImpl implements WebappRegistrationCustomizer
{
- /**
- * To plug into jasper bundles that contain tld files
- * please use a list of bundle's symbolic names:
- * -Djetty.osgi.tldbundles=org.springframework.web.servlet,com.opensymphony.module.sitemesh
- */
- public static final String SYS_PROP_TLD_BUNDLES = "org.eclipse.jetty.osgi.tldbundles";
-
- /**
- * Union of the tld bundles defined system wide and the one defines as an attribute of the AppProvider.
- * @param provider
- * @return
- */
- private static Collection getTldBundles(OSGiAppProvider provider)
- {
- String sysprop = System.getProperty(SYS_PROP_TLD_BUNDLES);
- String att = (String)provider.getTldBundles();
- if (sysprop == null && att == null)
- {
- return Collections.emptySet();
- }
- if (att == null)
- {
- att = sysprop;
- }
- else if (sysprop != null)
- {
- att = att + "," + sysprop;
- }
-
- Collection tldbundles = new HashSet();
- StringTokenizer tokenizer = new StringTokenizer(att, ", \n\r\t", false);
- while (tokenizer.hasMoreTokens())
- {
- tldbundles.add(tokenizer.nextToken());
- }
- return tldbundles;
- }
-
- /**
- * @return The location of the jars that contain tld files.
- * Jasper will discover them.
- */
+ /**
+ * To plug into jasper bundles that contain tld files please use a list of
+ * bundle's symbolic names:
+ * -Djetty.osgi.tldbundles=org.springframework.web.servlet
+ * ,com.opensymphony.module.sitemesh
+ */
+ public static final String SYS_PROP_TLD_BUNDLES = "org.eclipse.jetty.osgi.tldbundles";
+
+ /**
+ * Union of the tld bundles defined system wide and the one defines as an
+ * attribute of the AppProvider.
+ *
+ * @param provider
+ * @return
+ */
+ private static Collection getTldBundles(OSGiAppProvider provider)
+ {
+ String sysprop = System.getProperty(SYS_PROP_TLD_BUNDLES);
+ String att = (String) provider.getTldBundles();
+ if (sysprop == null && att == null) { return Collections.emptySet(); }
+ if (att == null)
+ {
+ att = sysprop;
+ }
+ else if (sysprop != null)
+ {
+ att = att + "," + sysprop;
+ }
+
+ Collection tldbundles = new HashSet();
+ StringTokenizer tokenizer = new StringTokenizer(att, ", \n\r\t", false);
+ while (tokenizer.hasMoreTokens())
+ {
+ tldbundles.add(tokenizer.nextToken());
+ }
+ return tldbundles;
+ }
+
+ /**
+ * @return The location of the jars that contain tld files. Jasper will
+ * discover them.
+ */
public URL[] getJarsWithTlds(OSGiAppProvider provider, BundleFileLocatorHelper locatorHelper) throws Exception
{
- List urls = new ArrayList();
- //naive way of finding those bundles.
- //lots of assumptions: for example we assume a single version of each bundle that would contain tld files.
- //this is probably good enough as those tlds are loaded system-wide on jetty.
- //to do better than this we need to do it on a per webapp basis.
- //probably using custom properties in the ContextHandler service
- //and mirroring those in the MANIFEST.MF
-
- Bundle[] bundles = FrameworkUtil.getBundle(PluggableWebAppRegistrationCustomizerImpl.class).getBundleContext().getBundles();
- Collection tldbundles = getTldBundles(provider);
- for (Bundle bundle : bundles)
- {
- if (tldbundles.contains(bundle.getSymbolicName()))
- {
- registerTldBundle(locatorHelper, bundle, urls);
- }
- }
-
- return urls.toArray(new URL[urls.size()]);
+ List urls = new ArrayList();
+ // naive way of finding those bundles.
+ // lots of assumptions: for example we assume a single version of each
+ // bundle that would contain tld files.
+ // this is probably good enough as those tlds are loaded system-wide on
+ // jetty.
+ // to do better than this we need to do it on a per webapp basis.
+ // probably using custom properties in the ContextHandler service
+ // and mirroring those in the MANIFEST.MF
+
+ Bundle[] bundles = FrameworkUtil.getBundle(PluggableWebAppRegistrationCustomizerImpl.class).getBundleContext().getBundles();
+ Collection tldbundles = getTldBundles(provider);
+ for (Bundle bundle : bundles)
+ {
+ if (tldbundles.contains(bundle.getSymbolicName()))
+ {
+ registerTldBundle(locatorHelper, bundle, urls);
+ }
+ }
+
+ return urls.toArray(new URL[urls.size()]);
}
-
+
/**
* Resolves the bundle that contains tld files as a set of URLs that will be
- * passed to jasper as a URLClassLoader later on.
- * Usually that would be a single URL per bundle.
- * But we do some more work if there are jars embedded in the bundle.
+ * passed to jasper as a URLClassLoader later on. Usually that would be a
+ * single URL per bundle. But we do some more work if there are jars
+ * embedded in the bundle.
*
- * The jasper TldScanner expects a URLClassloader to parse a jar for the /META-INF/*.tld it may contain. We place the bundles that we know contain such
- * tag-libraries. Please note that it will work if and only if the bundle is a jar (!) Currently we just hardcode the bundle that contains the jstl
- * implemenation.
+ * The jasper TldScanner expects a URLClassloader to parse a jar for the
+ * /META-INF/*.tld it may contain. We place the bundles that we know contain
+ * such tag-libraries. Please note that it will work if and only if the
+ * bundle is a jar (!) Currently we just hardcode the bundle that contains
+ * the jstl implemenation.
*
- * A workaround when the tld cannot be parsed with this method is to copy and paste it inside the WEB-INF of the webapplication where it is used.
+ * A workaround when the tld cannot be parsed with this method is to copy
+ * and paste it inside the WEB-INF of the webapplication where it is used.
*
- * Support only 2 types of packaging for the bundle: - the bundle is a jar (recommended for runtime.) - the bundle is a folder and contain jars in the root
- * and/or in the lib folder (nice for PDE developement situations) Unsupported: the bundle is a jar that embeds more jars.
+ * Support only 2 types of packaging for the bundle: - the bundle is a jar
+ * (recommended for runtime.) - the bundle is a folder and contain jars in
+ * the root and/or in the lib folder (nice for PDE developement situations)
+ * Unsupported: the bundle is a jar that embeds more jars.
*
* @param locatorHelper
* @param bundle
@@ -152,9 +160,9 @@ public class PluggableWebAppRegistrationCustomizerImpl implements WebappRegistra
}
else
{
- urls.add(jasperLocation.toURI().toURL());
+ urls.add(jasperLocation.toURI().toURL());
}
}
-
+
}
\ No newline at end of file
diff --git a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java
index 197c7497476..8e1a9b988db 100644
--- a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java
+++ b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java
@@ -36,48 +36,52 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
- * Fix various shortcomings with the way jasper parses the tld files.
- * Plugs the JSTL tlds assuming that they are packaged with the bundle that contains the JSTL classes.
+ * Fix various shortcomings with the way jasper parses the tld files. Plugs the
+ * JSTL tlds assuming that they are packaged with the bundle that contains the
+ * JSTL classes.
*
- * Pluggable tlds at the server level are handled by {@link PluggableWebAppRegistrationCustomizerImpl}.
+ * Pluggable tlds at the server level are handled by
+ * {@link PluggableWebAppRegistrationCustomizerImpl}.
*
*/
public class WebappRegistrationCustomizerImpl implements WebappRegistrationCustomizer
{
-
- /**
- * Default name of a class that belongs to the jstl bundle.
- * From that class we locate the corresponding bundle and register it
- * as a bundle that contains tld files.
- */
- private static String DEFAULT_JSTL_BUNDLE_CLASS = "org.apache.taglibs.standard.tag.el.core.WhenTag";
- //used to be "org.apache.jasper.runtime.JspFactoryImpl" but now
- //the standard tag library implementation are stored in a separate bundle.
-
- //DISABLED please use the tld bundle argument for the OSGiAppProvider
-// /**
-// * Default name of a class that belongs to the bundle where the Java server Faces tld files are defined.
-// * This is the sun's reference implementation.
-// */
-// private static String DEFAUT_JSF_IMPL_CLASS = "com.sun.faces.config.ConfigureListener";
- /**
- * Default jsp factory implementation.
- * Idally jasper is osgified and we can use services.
- * In the mean time we statically set the jsp factory implementation.
- * bug #299733
- */
- private static String DEFAULT_JSP_FACTORY_IMPL_CLASS = "org.apache.jasper.runtime.JspFactoryImpl";
-
+ /**
+ * Default name of a class that belongs to the jstl bundle. From that class
+ * we locate the corresponding bundle and register it as a bundle that
+ * contains tld files.
+ */
+ private static String DEFAULT_JSTL_BUNDLE_CLASS = "org.apache.taglibs.standard.tag.el.core.WhenTag";
+
+ // used to be "org.apache.jasper.runtime.JspFactoryImpl" but now
+ // the standard tag library implementation are stored in a separate bundle.
+
+ // DISABLED please use the tld bundle argument for the OSGiAppProvider
+ // /**
+ // * Default name of a class that belongs to the bundle where the Java
+ // server Faces tld files are defined.
+ // * This is the sun's reference implementation.
+ // */
+ // private static String DEFAUT_JSF_IMPL_CLASS =
+ // "com.sun.faces.config.ConfigureListener";
+
+ /**
+ * Default jsp factory implementation. Idally jasper is osgified and we can
+ * use services. In the mean time we statically set the jsp factory
+ * implementation. bug #299733
+ */
+ private static String DEFAULT_JSP_FACTORY_IMPL_CLASS = "org.apache.jasper.runtime.JspFactoryImpl";
+
public WebappRegistrationCustomizerImpl()
{
fixupDtdResolution();
-
+
try
{
- //sanity check:
+ // sanity check:
Class cl = getClass().getClassLoader().loadClass("org.apache.jasper.servlet.JspServlet");
- //System.err.println("found the jsp servlet: " + cl.getName());
+ // System.err.println("found the jsp servlet: " + cl.getName());
}
catch (Exception e)
{
@@ -87,18 +91,18 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
}
try
{
- //bug #299733
+ // bug #299733
JspFactory fact = JspFactory.getDefaultFactory();
if (fact == null)
- { //bug #299733
- //JspFactory does a simple Class.getForName("org.apache.jasper.runtime.JspFactoryImpl")
- //however its bundles does not import the jasper package
- //so it fails. let's help things out:
- fact = (JspFactory)JettyBootstrapActivator.class.getClassLoader()
- .loadClass(DEFAULT_JSP_FACTORY_IMPL_CLASS).newInstance();
+ { // bug #299733
+ // JspFactory does a simple
+ // Class.getForName("org.apache.jasper.runtime.JspFactoryImpl")
+ // however its bundles does not import the jasper package
+ // so it fails. let's help things out:
+ fact = (JspFactory) JettyBootstrapActivator.class.getClassLoader().loadClass(DEFAULT_JSP_FACTORY_IMPL_CLASS).newInstance();
JspFactory.setDefaultFactory(fact);
}
-
+
}
catch (Exception e)
{
@@ -106,84 +110,90 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
e.printStackTrace();
}
}
-
+
/**
- * The jasper TldScanner expects a URLClassloader to parse a jar for the /META-INF/*.tld it may contain. We place the bundles that we know contain such
- * tag-libraries. Please note that it will work if and only if the bundle is a jar (!) Currently we just hardcode the bundle that contains the jstl
- * implemenation.
+ * The jasper TldScanner expects a URLClassloader to parse a jar for the
+ * /META-INF/*.tld it may contain. We place the bundles that we know contain
+ * such tag-libraries. Please note that it will work if and only if the
+ * bundle is a jar (!) Currently we just hardcode the bundle that contains
+ * the jstl implemenation.
*
- * A workaround when the tld cannot be parsed with this method is to copy and paste it inside the WEB-INF of the webapplication where it is used.
+ * A workaround when the tld cannot be parsed with this method is to copy
+ * and paste it inside the WEB-INF of the webapplication where it is used.
*
- * Support only 2 types of packaging for the bundle: - the bundle is a jar (recommended for runtime.) - the bundle is a folder and contain jars in the root
- * and/or in the lib folder (nice for PDE developement situations) Unsupported: the bundle is a jar that embeds more jars.
+ * Support only 2 types of packaging for the bundle: - the bundle is a jar
+ * (recommended for runtime.) - the bundle is a folder and contain jars in
+ * the root and/or in the lib folder (nice for PDE developement situations)
+ * Unsupported: the bundle is a jar that embeds more jars.
*
* @return array of URLs
* @throws Exception
*/
public URL[] getJarsWithTlds(OSGiAppProvider provider, BundleFileLocatorHelper locatorHelper) throws Exception
{
+
HashSet> classesToAddToTheTldBundles = new HashSet>();
- //Look for the jstl bundle
- //We assume the jstl's tlds are defined there.
- //We assume that the jstl bundle is imported by this bundle
- //So we can look for this class using this bundle's classloader:
- Class> jstlClass = WebappRegistrationCustomizerImpl.class.getClassLoader().loadClass(DEFAULT_JSTL_BUNDLE_CLASS);
-
- classesToAddToTheTldBundles.add(jstlClass);
-
+ // Look for the jstl bundle
+ // We assume the jstl's tlds are defined there.
+ // We assume that the jstl bundle is imported by this bundle
+ // So we can look for this class using this bundle's classloader:
+ Class> jstlClass = WebappRegistrationCustomizerImpl.class.getClassLoader().loadClass(DEFAULT_JSTL_BUNDLE_CLASS);
+
+ classesToAddToTheTldBundles.add(jstlClass);
+
ArrayList urls = new ArrayList();
- for (Class> cl : classesToAddToTheTldBundles)
- {
- Bundle tldBundle = FrameworkUtil.getBundle(cl);
- File tldBundleLocation = locatorHelper.getBundleInstallLocation(tldBundle);
- if (tldBundleLocation != null && tldBundleLocation.isDirectory())
- {
- // try to find the jar files inside this folder
- for (File f : tldBundleLocation.listFiles())
- {
- if (f.getName().endsWith(".jar") && f.isFile())
- {
- urls.add(f.toURI().toURL());
- }
- else if (f.isDirectory() && f.getName().equals("lib"))
- {
- for (File f2 : tldBundleLocation.listFiles())
- {
- if (f2.getName().endsWith(".jar") && f2.isFile())
- {
- urls.add(f2.toURI().toURL());
- }
- }
- }
- }
-
- }
- else if (tldBundleLocation != null)
- {
- urls.add(tldBundleLocation.toURI().toURL());
- }
- }
- return urls.toArray(new URL[urls.size()]);
+ for (Class> cl : classesToAddToTheTldBundles)
+ {
+ Bundle tldBundle = FrameworkUtil.getBundle(cl);
+ File tldBundleLocation = locatorHelper.getBundleInstallLocation(tldBundle);
+ if (tldBundleLocation != null && tldBundleLocation.isDirectory())
+ {
+ // try to find the jar files inside this folder
+ for (File f : tldBundleLocation.listFiles())
+ {
+ if (f.getName().endsWith(".jar") && f.isFile())
+ {
+ urls.add(f.toURI().toURL());
+ }
+ else if (f.isDirectory() && f.getName().equals("lib"))
+ {
+ for (File f2 : tldBundleLocation.listFiles())
+ {
+ if (f2.getName().endsWith(".jar") && f2.isFile())
+ {
+ urls.add(f2.toURI().toURL());
+ }
+ }
+ }
+ }
+
+ }
+ else if (tldBundleLocation != null)
+ {
+ urls.add(tldBundleLocation.toURI().toURL());
+ }
+ }
+ return urls.toArray(new URL[urls.size()]);
}
-
-
-
+
/**
- * Jasper resolves the dtd when it parses a taglib descriptor.
- * It uses this code to do that: ParserUtils.getClass().getResourceAsStream(resourcePath); where
- * resourcePath is for example: /javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd Unfortunately,
- * the dtd file is not in the exact same classloader as
- * ParserUtils class and the dtds are packaged in 2 separate bundles.
- * OSGi does not look in the dependencies' classloader when a resource is searched.
+ * Jasper resolves the dtd when it parses a taglib descriptor. It uses this
+ * code to do that:
+ * ParserUtils.getClass().getResourceAsStream(resourcePath); where
+ * resourcePath is for example:
+ * /javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd Unfortunately, the
+ * dtd file is not in the exact same classloader as ParserUtils class and
+ * the dtds are packaged in 2 separate bundles. OSGi does not look in the
+ * dependencies' classloader when a resource is searched.
*
- * The workaround consists of setting the entity resolver. That is a patch
- * added to the version of glassfish-jasper-jetty. IT is also present in the latest
- * version of glassfish jasper. Could not use introspection to set new value
- * on a static friendly field :(
+ * The workaround consists of setting the entity resolver. That is a patch
+ * added to the version of glassfish-jasper-jetty. IT is also present in the
+ * latest version of glassfish jasper. Could not use introspection to set
+ * new value on a static friendly field :(
*
*/
- void fixupDtdResolution()
+ void fixupDtdResolution()
{
try
{
@@ -198,29 +208,23 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
}
/**
- * Instead of using the ParserUtil's classloader, we use a class that is indeed next to the resource for sure.
+ * Instead of using the ParserUtil's classloader, we use a class that is
+ * indeed next to the resource for sure.
*/
static class MyFixedupEntityResolver implements EntityResolver
{
/**
* Same values than in ParserUtils...
*/
- static final String[] CACHED_DTD_PUBLIC_IDS =
- { Constants.TAGLIB_DTD_PUBLIC_ID_11, Constants.TAGLIB_DTD_PUBLIC_ID_12,
- Constants.WEBAPP_DTD_PUBLIC_ID_22, Constants.WEBAPP_DTD_PUBLIC_ID_23, };
+ static final String[] CACHED_DTD_PUBLIC_IDS = { Constants.TAGLIB_DTD_PUBLIC_ID_11, Constants.TAGLIB_DTD_PUBLIC_ID_12,
+ Constants.WEBAPP_DTD_PUBLIC_ID_22, Constants.WEBAPP_DTD_PUBLIC_ID_23, };
- static final String[] CACHED_DTD_RESOURCE_PATHS =
- { Constants.TAGLIB_DTD_RESOURCE_PATH_11,
- Constants.TAGLIB_DTD_RESOURCE_PATH_12,
- Constants.WEBAPP_DTD_RESOURCE_PATH_22,
- Constants.WEBAPP_DTD_RESOURCE_PATH_23, };
+ static final String[] CACHED_DTD_RESOURCE_PATHS = { Constants.TAGLIB_DTD_RESOURCE_PATH_11, Constants.TAGLIB_DTD_RESOURCE_PATH_12,
+ Constants.WEBAPP_DTD_RESOURCE_PATH_22, Constants.WEBAPP_DTD_RESOURCE_PATH_23, };
+
+ static final String[] CACHED_SCHEMA_RESOURCE_PATHS = { Constants.TAGLIB_SCHEMA_RESOURCE_PATH_20, Constants.TAGLIB_SCHEMA_RESOURCE_PATH_21,
+ Constants.WEBAPP_SCHEMA_RESOURCE_PATH_24, Constants.WEBAPP_SCHEMA_RESOURCE_PATH_25, };
- static final String[] CACHED_SCHEMA_RESOURCE_PATHS = {
- Constants.TAGLIB_SCHEMA_RESOURCE_PATH_20,
- Constants.TAGLIB_SCHEMA_RESOURCE_PATH_21,
- Constants.WEBAPP_SCHEMA_RESOURCE_PATH_24,
- Constants.WEBAPP_SCHEMA_RESOURCE_PATH_25,
- };
public InputSource resolveEntity(String publicId, String systemId) throws SAXException
{
for (int i = 0; i < CACHED_DTD_PUBLIC_IDS.length; i++)
@@ -241,10 +245,7 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
input = this.getClass().getResourceAsStream(resourcePath);
}
}
- if (input == null)
- {
- throw new SAXException(Localizer.getMessage("jsp.error.internal.filenotfound",resourcePath));
- }
+ if (input == null) { throw new SAXException(Localizer.getMessage("jsp.error.internal.filenotfound", resourcePath)); }
InputSource isrc = new InputSource(input);
return isrc;
}
@@ -253,5 +254,5 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
return null;
}
}
-
+
}
diff --git a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/FragmentActivator.java b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/FragmentActivator.java
index 99a567cd70d..3f8f2874e65 100644
--- a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/FragmentActivator.java
+++ b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/FragmentActivator.java
@@ -19,15 +19,14 @@ import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
/**
- * Pseudo fragment activator.
- * Called by the main org.eclipse.jetty.osgi.boot bundle.
- * Please note: this is not a real BundleActivator. Simply something called back by
- * the host bundle.
+ * Pseudo fragment activator. Called by the main org.eclipse.jetty.osgi.boot
+ * bundle. Please note: this is not a real BundleActivator. Simply something
+ * called back by the host bundle.
*
- * It must be placed in the org.eclipse.jetty.osgi.boot.jsp package:
- * this is because org.eclipse.jetty.osgi.boot.jsp is the sympbolic-name
- * of this fragment. From that name, the PackageadminTracker will call
- * this class. IN a different package it won't be called.
+ * It must be placed in the org.eclipse.jetty.osgi.boot.jsp package: this is
+ * because org.eclipse.jetty.osgi.boot.jsp is the sympbolic-name of this
+ * fragment. From that name, the PackageadminTracker will call this class. IN a
+ * different package it won't be called.
*
*/
public class FragmentActivator implements BundleActivator
@@ -35,8 +34,9 @@ public class FragmentActivator implements BundleActivator
/**
*
*/
- public void start(BundleContext context) throws Exception {
- System.setProperty("org.apache.jasper.compiler.disablejsr199", Boolean.TRUE.toString());
+ public void start(BundleContext context) throws Exception
+ {
+ System.setProperty("org.apache.jasper.compiler.disablejsr199", Boolean.TRUE.toString());
WebBundleDeployerHelper.JSP_REGISTRATION_HELPERS.add(new WebappRegistrationCustomizerImpl());
WebBundleDeployerHelper.JSP_REGISTRATION_HELPERS.add(new PluggableWebAppRegistrationCustomizerImpl());
}
@@ -44,7 +44,8 @@ public class FragmentActivator implements BundleActivator
/**
*
*/
- public void stop(BundleContext context) throws Exception {
-
+ public void stop(BundleContext context) throws Exception
+ {
+
}
}
diff --git a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/TagLibOSGiConfiguration.java b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/TagLibOSGiConfiguration.java
index 510261db4d0..ad31de22e7f 100644
--- a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/TagLibOSGiConfiguration.java
+++ b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/TagLibOSGiConfiguration.java
@@ -35,123 +35,120 @@ import org.osgi.util.tracker.ServiceTracker;
* Replacement for {@link TagLibConfiguration} for the OSGi integration.
*
*
- * In the case of a WAB, tlds can be located in OSGi bundles that are dependencies
- * of the WAB.
- * It is expected that each WAB lists the symbolic-names of the bundles that contain
- * tld files. The list is defined as the value of the header 'Require-TldBundle'
+ * In the case of a WAB, tlds can be located in OSGi bundles that are
+ * dependencies of the WAB. It is expected that each WAB lists the
+ * symbolic-names of the bundles that contain tld files. The list is defined as
+ * the value of the header 'Require-TldBundle'
*
*
- * Discussions about this are logged in https://bugs.eclipse.org/bugs/show_bug.cgi?id=306971
+ * Discussions about this are logged in
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=306971
*
*/
public class TagLibOSGiConfiguration extends TagLibConfiguration
{
private static final Logger LOG = Log.getLogger(TagLibOSGiConfiguration.class);
- private ServiceTracker packageAdminServiceTracker = null;
-
- /**
- * Override the preConfigure; locates the bundles that contain
- * tld files according to the value of the manifest header Require-TldBundle.
- *
- * Set or add to the property TldProcessor.TLDResources the list of located jars
- * so that the super class will scan those.
- *
- */
+ private ServiceTracker packageAdminServiceTracker = null;
+
+ /**
+ * Override the preConfigure; locates the bundles that contain tld files
+ * according to the value of the manifest header Require-TldBundle.
+ *
+ * Set or add to the property TldProcessor.TLDResources the list of located
+ * jars so that the super class will scan those.
+ *
+ */
public void preConfigure(WebAppContext context) throws Exception
{
- String requireTldBundle = (String)context.getAttribute(OSGiWebappConstants.REQUIRE_TLD_BUNDLE);
- if (requireTldBundle != null)
- {
- Collection resources = getRequireTldBundleAsJettyResources(context, requireTldBundle);
- if (resources != null && !resources.isEmpty())
- {
- Collection previouslySet = (Collection)
- context.getAttribute(TagLibConfiguration.TLD_RESOURCES);
- if (previouslySet != null)
- {
- resources.addAll(previouslySet);
- }
- context.setAttribute(TagLibConfiguration.TLD_RESOURCES, resources);
- }
- }
- super.preConfigure(context);
+ String requireTldBundle = (String) context.getAttribute(OSGiWebappConstants.REQUIRE_TLD_BUNDLE);
+ if (requireTldBundle != null)
+ {
+ Collection resources = getRequireTldBundleAsJettyResources(context, requireTldBundle);
+ if (resources != null && !resources.isEmpty())
+ {
+ Collection previouslySet = (Collection) context.getAttribute(TagLibConfiguration.TLD_RESOURCES);
+ if (previouslySet != null)
+ {
+ resources.addAll(previouslySet);
+ }
+ context.setAttribute(TagLibConfiguration.TLD_RESOURCES, resources);
+ }
+ }
+ super.preConfigure(context);
}
/**
- * @param requireTldBundle The comma separated list of bundles' symbolic names
- * that contain tld for this osgi webapp.
+ * @param requireTldBundle The comma separated list of bundles' symbolic
+ * names that contain tld for this osgi webapp.
* @return The collection of jars or folders that match those bundles.
*/
- private Collection getRequireTldBundleAsJettyResources(
- WebAppContext context, String requireTldBundle)
+ private Collection getRequireTldBundleAsJettyResources(WebAppContext context, String requireTldBundle)
{
- Bundle bundle = (Bundle)
- context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
- PackageAdmin packAdmin = getBundleAdmin();
- String[] symbNames = requireTldBundle.split(", ");
- Collection tlds = new LinkedHashSet();
- for (String symbName : symbNames)
- {
- Bundle[] bs = packAdmin.getBundles(symbName, null);
- if (bs == null || bs.length == 0)
- {
- throw new IllegalArgumentException("Unable to locate the bundle '"
- + symbName + "' specified in the "
- + OSGiWebappConstants.REQUIRE_TLD_BUNDLE
- + " of the manifest of "
- + bundle.getSymbolicName());
- }
- //take the first one as it is the most recent version?
- Enumeration en = bs[0].findEntries("META-INF", "*.tld", false);
- boolean atLeastOneTldFound = false;
- while (en.hasMoreElements())
- {
- atLeastOneTldFound = true;
- URL oriUrl = en.nextElement();
- URL url = DefaultFileLocatorHelper.getLocalURL(oriUrl);
- Resource tldResource;
- try
- {
- tldResource = Resource.newResource(url);
- }
- catch (IOException e)
- {
- throw new IllegalArgumentException("Unable to locate the "
- + "tld resource in '"
- + url.toString()
- + "' in the bundle '" + bs[0].getSymbolicName()
- + "' while registering the "
- + OSGiWebappConstants.REQUIRE_TLD_BUNDLE
- + " of the manifest of "
- + bundle.getSymbolicName(), e);
- }
- tlds.add(tldResource);
- }
- if (!atLeastOneTldFound)
- {
- LOG.warn("No '/META-INF/*.tld' resources were found "
- + " in the bundle '" + bs[0].getSymbolicName()
- + "' while registering the "
- + OSGiWebappConstants.REQUIRE_TLD_BUNDLE
- + " of the manifest of "
- + bundle.getSymbolicName());
- }
- }
- return tlds;
+ Bundle bundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
+ PackageAdmin packAdmin = getBundleAdmin();
+ String[] symbNames = requireTldBundle.split(", ");
+ Collection tlds = new LinkedHashSet();
+ for (String symbName : symbNames)
+ {
+ Bundle[] bs = packAdmin.getBundles(symbName, null);
+ if (bs == null || bs.length == 0)
+ {
+ throw new IllegalArgumentException("Unable to locate the bundle '" + symbName
+ + "' specified in the "
+ + OSGiWebappConstants.REQUIRE_TLD_BUNDLE
+ + " of the manifest of "
+ + bundle.getSymbolicName());
+ }
+ // take the first one as it is the most recent version?
+ Enumeration en = bs[0].findEntries("META-INF", "*.tld", false);
+ boolean atLeastOneTldFound = false;
+ while (en.hasMoreElements())
+ {
+ atLeastOneTldFound = true;
+ URL oriUrl = en.nextElement();
+ URL url = DefaultFileLocatorHelper.getLocalURL(oriUrl);
+ Resource tldResource;
+ try
+ {
+ tldResource = Resource.newResource(url);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalArgumentException("Unable to locate the " + "tld resource in '"
+ + url.toString()
+ + "' in the bundle '"
+ + bs[0].getSymbolicName()
+ + "' while registering the "
+ + OSGiWebappConstants.REQUIRE_TLD_BUNDLE
+ + " of the manifest of "
+ + bundle.getSymbolicName(), e);
+ }
+ tlds.add(tldResource);
+ }
+ if (!atLeastOneTldFound)
+ {
+ LOG.warn("No '/META-INF/*.tld' resources were found " + " in the bundle '"
+ + bs[0].getSymbolicName()
+ + "' while registering the "
+ + OSGiWebappConstants.REQUIRE_TLD_BUNDLE
+ + " of the manifest of "
+ + bundle.getSymbolicName());
+ }
+ }
+ return tlds;
}
-
- private PackageAdmin getBundleAdmin()
- {
- if (packageAdminServiceTracker == null)
- {
- Bundle bootBundle = ((BundleReference)OSGiWebappConstants.class.getClassLoader()).getBundle();
- packageAdminServiceTracker = new ServiceTracker(bootBundle.getBundleContext(),
- PackageAdmin.class.getName(), null);
- packageAdminServiceTracker.open();
- }
- return (PackageAdmin) packageAdminServiceTracker.getService();
- }
-
+
+ private PackageAdmin getBundleAdmin()
+ {
+ if (packageAdminServiceTracker == null)
+ {
+ Bundle bootBundle = ((BundleReference) OSGiWebappConstants.class.getClassLoader()).getBundle();
+ packageAdminServiceTracker = new ServiceTracker(bootBundle.getBundleContext(), PackageAdmin.class.getName(), null);
+ packageAdminServiceTracker.open();
+ }
+ return (PackageAdmin) packageAdminServiceTracker.getService();
+ }
+
}
diff --git a/jetty-osgi/jetty-osgi-boot-logback/META-INF/MANIFEST.MF b/jetty-osgi/jetty-osgi-boot-logback/META-INF/MANIFEST.MF
index 0400545f14d..39e193236cd 100644
--- a/jetty-osgi/jetty-osgi-boot-logback/META-INF/MANIFEST.MF
+++ b/jetty-osgi/jetty-osgi-boot-logback/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Jetty-OSGi-Logback integration
Fragment-Host: org.eclipse.jetty.osgi.boot
Bundle-SymbolicName: org.eclipse.jetty.osgi.boot.logback;singleton:=true
-Bundle-Version: 8.1.2.qualifier
+Bundle-Version: 8.1.3.qualifier
Bundle-Vendor: Mort Bay Consulting
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: ch.qos.logback.classic,
diff --git a/jetty-osgi/jetty-osgi-boot-warurl/META-INF/MANIFEST.MF b/jetty-osgi/jetty-osgi-boot-warurl/META-INF/MANIFEST.MF
index c8f2dcf1bd6..64712ef5f7e 100644
--- a/jetty-osgi/jetty-osgi-boot-warurl/META-INF/MANIFEST.MF
+++ b/jetty-osgi/jetty-osgi-boot-warurl/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Support for rfc66 war url scheme
Bundle-SymbolicName: org.eclipse.jetty.osgi.boot.warurl;singleton:=true
-Bundle-Version: 8.1.2.qualifier
+Bundle-Version: 8.1.3.qualifier
Bundle-Activator: org.eclipse.jetty.osgi.boot.warurl.WarUrlActivator
Bundle-Vendor: Mort Bay Consulting
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/jetty-osgi/jetty-osgi-boot-warurl/src/main/java/org/eclipse/jetty/osgi/boot/warurl/WarUrlStreamHandler.java b/jetty-osgi/jetty-osgi-boot-warurl/src/main/java/org/eclipse/jetty/osgi/boot/warurl/WarUrlStreamHandler.java
index 654fb9b078f..0f861629a81 100644
--- a/jetty-osgi/jetty-osgi-boot-warurl/src/main/java/org/eclipse/jetty/osgi/boot/warurl/WarUrlStreamHandler.java
+++ b/jetty-osgi/jetty-osgi-boot-warurl/src/main/java/org/eclipse/jetty/osgi/boot/warurl/WarUrlStreamHandler.java
@@ -24,12 +24,13 @@ import java.util.jar.Manifest;
import org.eclipse.jetty.osgi.boot.warurl.internal.WarBundleManifestGenerator;
import org.eclipse.jetty.osgi.boot.warurl.internal.WarURLConnection;
import org.eclipse.jetty.util.URIUtil;
+import org.eclipse.jetty.util.resource.Resource;
import org.osgi.service.url.AbstractURLStreamHandlerService;
/**
- * RFC-66: support for the "war" protocol
- * We are reusing the parsing of the query string from jetty.
- * If we wanted to not depend on jetty at all we could duplicate that method here
+ * RFC-66: support for the "war" protocol We are reusing the parsing of the
+ * query string from jetty. If we wanted to not depend on jetty at all we could
+ * duplicate that method here
*/
public class WarUrlStreamHandler extends AbstractURLStreamHandlerService
{
@@ -40,11 +41,11 @@ public class WarUrlStreamHandler extends AbstractURLStreamHandlerService
@Override
public URLConnection openConnection(URL url) throws IOException
{
- //remove the war scheme.
+ // remove the war scheme.
URL actual = new URL(url.toString().substring("war:".length()));
-
- //let's do some basic tests: see if this is a folder or not.
- //if it is a folder. we will try to support it.
+
+ // let's do some basic tests: see if this is a folder or not.
+ // if it is a folder. we will try to support it.
if (actual.getProtocol().equals("file"))
{
File file = new File(URIUtil.encodePath(actual.getPath()));
@@ -52,34 +53,48 @@ public class WarUrlStreamHandler extends AbstractURLStreamHandlerService
{
if (file.isDirectory())
{
- //TODO (not mandatory for rfc66 though)
+ // TODO (not mandatory for rfc66 though)
}
}
}
-
- // if (actual.toString().startsWith("file:/") && ! actual.to)
+
+ // if (actual.toString().startsWith("file:/") && ! actual.to)
URLConnection ori = (URLConnection) actual.openConnection();
+ ori.setDefaultUseCaches(Resource.getDefaultUseCaches());
JarURLConnection jarOri = null;
- try {
+ try
+ {
if (ori instanceof JarURLConnection)
{
- jarOri = (JarURLConnection)ori;
+ jarOri = (JarURLConnection) ori;
}
else
{
- jarOri = (JarURLConnection) new URL("jar:"+actual.toString() + "!/").openConnection();
+ jarOri = (JarURLConnection) new URL("jar:" + actual.toString() + "!/").openConnection();
+ jarOri.setDefaultUseCaches(Resource.getDefaultUseCaches());
}
- Manifest mf = WarBundleManifestGenerator.createBundleManifest(
- jarOri.getManifest(), url, jarOri.getJarFile());
- try { jarOri.getJarFile().close(); jarOri = null; } catch (Throwable t) {}
- return new WarURLConnection(actual,mf);
+ Manifest mf = WarBundleManifestGenerator.createBundleManifest(jarOri.getManifest(), url, jarOri.getJarFile());
+ try
+ {
+ jarOri.getJarFile().close();
+ jarOri = null;
+ }
+ catch (Throwable t)
+ {
+ }
+ return new WarURLConnection(actual, mf);
}
finally
{
- if (jarOri != null) try { jarOri.getJarFile().close(); } catch (Throwable t) {}
+ if (jarOri != null) try
+ {
+ jarOri.getJarFile().close();
+ }
+ catch (Throwable t)
+ {
+ }
}
-
+
}
-
}
diff --git a/jetty-osgi/jetty-osgi-boot-warurl/src/main/java/org/eclipse/jetty/osgi/boot/warurl/internal/WarURLConnection.java b/jetty-osgi/jetty-osgi-boot-warurl/src/main/java/org/eclipse/jetty/osgi/boot/warurl/internal/WarURLConnection.java
index 744a43c2ecc..c19a2fa6bfe 100644
--- a/jetty-osgi/jetty-osgi-boot-warurl/src/main/java/org/eclipse/jetty/osgi/boot/warurl/internal/WarURLConnection.java
+++ b/jetty-osgi/jetty-osgi-boot-warurl/src/main/java/org/eclipse/jetty/osgi/boot/warurl/internal/WarURLConnection.java
@@ -31,6 +31,7 @@ import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.util.resource.Resource;
/**
* Facade for a URLConnection that will read a jar and substitute its
@@ -106,6 +107,7 @@ public class WarURLConnection extends URLConnection
{
super(url);
_conn = url.openConnection();
+ _conn.setDefaultUseCaches(Resource.getDefaultUseCaches());
_mf = mf;
}
@Override
diff --git a/jetty-osgi/jetty-osgi-boot/META-INF/MANIFEST.MF b/jetty-osgi/jetty-osgi-boot/META-INF/MANIFEST.MF
index b5390842caf..4cf661c47f0 100644
--- a/jetty-osgi/jetty-osgi-boot/META-INF/MANIFEST.MF
+++ b/jetty-osgi/jetty-osgi-boot/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Jetty OSGi bootstrap
Bundle-SymbolicName: org.eclipse.jetty.osgi.boot
Bundle-Vendor: Mort Bay Consulting
-Bundle-Version: 8.1.2.qualifier
+Bundle-Version: 8.1.3.qualifier
Bundle-Activator: org.eclipse.jetty.osgi.boot.JettyBootstrapActivator
Import-Package: javax.mail;version="1.4.0";resolution:=optional,
javax.mail.event;version="1.4.0";resolution:=optional,
@@ -14,20 +14,20 @@ Import-Package: javax.mail;version="1.4.0";resolution:=optional,
javax.servlet.http;version="2.6",
javax.transaction;version="1.1.0";resolution:=optional,
javax.transaction.xa;version="1.1.0";resolution:=optional,
- org.eclipse.jetty.annotations;version="8.1.2";resolution:=optional,
- org.eclipse.jetty.deploy;version="8.1.2",
- org.eclipse.jetty.deploy.providers;version="8.1.2",
- org.eclipse.jetty.http;version="8.1.2",
- org.eclipse.jetty.nested;version="8.1.2";resolution:=optional,
- org.eclipse.jetty.server;version="8.1.2",
- org.eclipse.jetty.server.handler;version="8.1.2",
- org.eclipse.jetty.servlet;version="8.1.2",
- org.eclipse.jetty.util;version="8.1.2",
- org.eclipse.jetty.util.component;version="8.1.2",
- org.eclipse.jetty.util.log;version="8.1.2",
- org.eclipse.jetty.util.resource;version="8.1.2",
- org.eclipse.jetty.webapp;version="8.1.2",
- org.eclipse.jetty.xml;version="8.1.2",
+ org.eclipse.jetty.annotations;version="8.1.3";resolution:=optional,
+ org.eclipse.jetty.deploy;version="8.1.3",
+ org.eclipse.jetty.deploy.providers;version="8.1.3",
+ org.eclipse.jetty.http;version="8.1.3",
+ org.eclipse.jetty.nested;version="8.1.3";resolution:=optional,
+ org.eclipse.jetty.server;version="8.1.3",
+ org.eclipse.jetty.server.handler;version="8.1.3",
+ org.eclipse.jetty.servlet;version="8.1.3",
+ org.eclipse.jetty.util;version="8.1.3",
+ org.eclipse.jetty.util.component;version="8.1.3",
+ org.eclipse.jetty.util.log;version="8.1.3",
+ org.eclipse.jetty.util.resource;version="8.1.3",
+ org.eclipse.jetty.webapp;version="8.1.3",
+ org.eclipse.jetty.xml;version="8.1.3",
org.osgi.framework,
org.osgi.service.cm;version="1.2.0",
org.osgi.service.packageadmin,
@@ -41,8 +41,8 @@ Import-Package: javax.mail;version="1.4.0";resolution:=optional,
org.xml.sax.helpers
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Classpath: .
-Export-Package: org.eclipse.jetty.osgi.boot;version="8.1.2",
- org.eclipse.jetty.osgi.nested;version="8.1.2",
- org.eclipse.jetty.osgi.boot.utils;version="8.1.2",
- org.eclipse.jetty.osgi.annotations;version="8.1.2"
+Export-Package: org.eclipse.jetty.osgi.boot;version="8.1.3",
+ org.eclipse.jetty.osgi.nested;version="8.1.3",
+ org.eclipse.jetty.osgi.boot.utils;version="8.1.3",
+ org.eclipse.jetty.osgi.annotations;version="8.1.3"
DynamicImport-Package: org.eclipse.jetty.*;version="[8.1,9)"
diff --git a/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-default.xml b/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-default.xml
index 1202ae7023c..f8d1b680645 100644
--- a/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-default.xml
+++ b/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-default.xml
@@ -21,6 +21,7 @@
10200
+ false
@@ -45,19 +46,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -82,10 +70,6 @@
-
-
-
-
@@ -95,7 +79,7 @@
org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern
- .*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$
+ .*/servlet-api-[^/]*\.jar$
@@ -126,8 +110,12 @@
truetrue1000
+ false
+ false
-
+
+
+
java.naming.factory.initial
diff --git a/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-nested-default.xml b/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-nested-default.xml
index 67d84e9df8f..b5eeaf3ab06 100644
--- a/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-nested-default.xml
+++ b/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-nested-default.xml
@@ -54,10 +54,6 @@
-
-
-
-
@@ -67,7 +63,7 @@
org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern
- .*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$
+ .*/servlet-api-[^/]*\.jar$
@@ -82,7 +78,7 @@
contain custom tag libraries (*.tld files)
if those bundles don't exist or can't be loaded no errors or warning will be issued!
this default value is to plug the tld files of the reference implementation of JSF -->
-
@@ -99,8 +95,12 @@
truetrue1000
+ false
+ false
-
+
+
+
java.naming.factory.initial
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/JettyBootstrapActivator.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/JettyBootstrapActivator.java
index e3c0f9040db..78d27131836 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/JettyBootstrapActivator.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/JettyBootstrapActivator.java
@@ -66,15 +66,19 @@ public class JettyBootstrapActivator implements BundleActivator
}
private ServiceRegistration _registeredServer;
+
private Server _server;
+
private JettyContextHandlerServiceTracker _jettyContextHandlerTracker;
+
private PackageAdminServiceTracker _packageAdminServiceTracker;
+
private BundleTracker _webBundleTracker;
+
private BundleContext _bundleContext;
-
-// private ServiceRegistration _jettyServerFactoryService;
+
+ // private ServiceRegistration _jettyServerFactoryService;
private JettyServerServiceTracker _jettyServerServiceTracker;
-
/**
* Setup a new jetty Server, registers it as a service. Setup the Service
@@ -93,30 +97,31 @@ public class JettyBootstrapActivator implements BundleActivator
// should activate.
_packageAdminServiceTracker = new PackageAdminServiceTracker(context);
- _jettyServerServiceTracker = new JettyServerServiceTracker();
- context.addServiceListener(_jettyServerServiceTracker,"(objectclass=" + Server.class.getName() + ")");
+ _jettyServerServiceTracker = new JettyServerServiceTracker();
+ context.addServiceListener(_jettyServerServiceTracker, "(objectclass=" + Server.class.getName() + ")");
+
+ // Register the Jetty Server Factory as a ManagedServiceFactory:
+ // Properties jettyServerMgdFactoryServiceProps = new Properties();
+ // jettyServerMgdFactoryServiceProps.put("pid",
+ // OSGiWebappConstants.MANAGED_JETTY_SERVER_FACTORY_PID);
+ // _jettyServerFactoryService = context.registerService(
+ // ManagedServiceFactory.class.getName(), new
+ // JettyServersManagedFactory(),
+ // jettyServerMgdFactoryServiceProps);
- //Register the Jetty Server Factory as a ManagedServiceFactory:
-// Properties jettyServerMgdFactoryServiceProps = new Properties();
-// jettyServerMgdFactoryServiceProps.put("pid", OSGiWebappConstants.MANAGED_JETTY_SERVER_FACTORY_PID);
-// _jettyServerFactoryService = context.registerService(
-// ManagedServiceFactory.class.getName(), new JettyServersManagedFactory(),
-// jettyServerMgdFactoryServiceProps);
-
_jettyContextHandlerTracker = new JettyContextHandlerServiceTracker(_jettyServerServiceTracker);
// the tracker in charge of the actual deployment
// and that will configure and start the jetty server.
- context.addServiceListener(_jettyContextHandlerTracker,"(objectclass=" + ContextHandler.class.getName() + ")");
+ context.addServiceListener(_jettyContextHandlerTracker, "(objectclass=" + ContextHandler.class.getName() + ")");
- //see if we shoult start a default jetty instance right now.
+ // see if we shoult start a default jetty instance right now.
DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context);
-
- // now ready to support the Extender pattern:
- _webBundleTracker = new BundleTracker(context,
- Bundle.ACTIVE | Bundle.STOPPING, new WebBundleTrackerCustomizer());
+
+ // now ready to support the Extender pattern:
+ _webBundleTracker = new BundleTracker(context, Bundle.ACTIVE | Bundle.STOPPING, new WebBundleTrackerCustomizer());
_webBundleTracker.open();
-
+
}
/*
@@ -129,12 +134,12 @@ public class JettyBootstrapActivator implements BundleActivator
{
try
{
-
- if (_webBundleTracker != null)
- {
- _webBundleTracker.close();
- _webBundleTracker = null;
- }
+
+ if (_webBundleTracker != null)
+ {
+ _webBundleTracker.close();
+ _webBundleTracker = null;
+ }
if (_jettyContextHandlerTracker != null)
{
_jettyContextHandlerTracker.stop();
@@ -143,7 +148,7 @@ public class JettyBootstrapActivator implements BundleActivator
}
if (_jettyServerServiceTracker != null)
{
- _jettyServerServiceTracker.stop();
+ _jettyServerServiceTracker.stop();
context.removeServiceListener(_jettyServerServiceTracker);
_jettyServerServiceTracker = null;
}
@@ -165,31 +170,31 @@ public class JettyBootstrapActivator implements BundleActivator
}
finally
{
- _registeredServer = null;
+ _registeredServer = null;
}
}
-// if (_jettyServerFactoryService != null)
-// {
-// try
-// {
-// _jettyServerFactoryService.unregister();
-// }
-// catch (IllegalArgumentException ill)
-// {
-// // already unregistered.
-// }
-// finally
-// {
-// _jettyServerFactoryService = null;
-// }
-// }
+ // if (_jettyServerFactoryService != null)
+ // {
+ // try
+ // {
+ // _jettyServerFactoryService.unregister();
+ // }
+ // catch (IllegalArgumentException ill)
+ // {
+ // // already unregistered.
+ // }
+ // finally
+ // {
+ // _jettyServerFactoryService = null;
+ // }
+ // }
}
finally
{
if (_server != null)
{
- _server.stop();
+ _server.stop();
}
INSTANCE = null;
}
@@ -200,27 +205,25 @@ public class JettyBootstrapActivator implements BundleActivator
* registers it as an OSGi service. The tracker
* {@link JettyContextHandlerServiceTracker} will do the actual deployment.
*
- * @param contributor
- * The bundle
- * @param webappFolderPath
- * The path to the root of the webapp. Must be a path relative to
- * bundle; either an absolute path.
- * @param contextPath
- * The context path. Must start with "/"
+ * @param contributor The bundle
+ * @param webappFolderPath The path to the root of the webapp. Must be a
+ * path relative to bundle; either an absolute path.
+ * @param contextPath The context path. Must start with "/"
* @throws Exception
*/
public static void registerWebapplication(Bundle contributor, String webappFolderPath, String contextPath) throws Exception
{
- checkBundleActivated();
- WebAppContext contextHandler = new WebAppContext();
+ checkBundleActivated();
+ WebAppContext contextHandler = new WebAppContext();
Dictionary dic = new Hashtable();
- dic.put(OSGiWebappConstants.SERVICE_PROP_WAR,webappFolderPath);
- dic.put(OSGiWebappConstants.SERVICE_PROP_CONTEXT_PATH,contextPath);
- String requireTldBundle = (String)contributor.getHeaders().get(OSGiWebappConstants.REQUIRE_TLD_BUNDLE);
- if (requireTldBundle != null) {
- dic.put(OSGiWebappConstants.SERVICE_PROP_REQUIRE_TLD_BUNDLE, requireTldBundle);
+ dic.put(OSGiWebappConstants.SERVICE_PROP_WAR, webappFolderPath);
+ dic.put(OSGiWebappConstants.SERVICE_PROP_CONTEXT_PATH, contextPath);
+ String requireTldBundle = (String) contributor.getHeaders().get(OSGiWebappConstants.REQUIRE_TLD_BUNDLE);
+ if (requireTldBundle != null)
+ {
+ dic.put(OSGiWebappConstants.SERVICE_PROP_REQUIRE_TLD_BUNDLE, requireTldBundle);
}
- contributor.getBundleContext().registerService(ContextHandler.class.getName(),contextHandler,dic);
+ contributor.getBundleContext().registerService(ContextHandler.class.getName(), contextHandler, dic);
}
/**
@@ -228,24 +231,20 @@ public class JettyBootstrapActivator implements BundleActivator
* registers it as an OSGi service. The tracker
* {@link JettyContextHandlerServiceTracker} will do the actual deployment.
*
- * @param contributor
- * The bundle
- * @param webappFolderPath
- * The path to the root of the webapp. Must be a path relative to
- * bundle; either an absolute path.
- * @param contextPath
- * The context path. Must start with "/"
- * @param dic
- * TODO: parameter description
+ * @param contributor The bundle
+ * @param webappFolderPath The path to the root of the webapp. Must be a
+ * path relative to bundle; either an absolute path.
+ * @param contextPath The context path. Must start with "/"
+ * @param dic TODO: parameter description
* @throws Exception
*/
public static void registerWebapplication(Bundle contributor, String webappFolderPath, String contextPath, Dictionary dic) throws Exception
{
- checkBundleActivated();
+ checkBundleActivated();
WebAppContext contextHandler = new WebAppContext();
- dic.put(OSGiWebappConstants.SERVICE_PROP_WAR,webappFolderPath);
- dic.put(OSGiWebappConstants.SERVICE_PROP_CONTEXT_PATH,contextPath);
- contributor.getBundleContext().registerService(ContextHandler.class.getName(),contextHandler,dic);
+ dic.put(OSGiWebappConstants.SERVICE_PROP_WAR, webappFolderPath);
+ dic.put(OSGiWebappConstants.SERVICE_PROP_CONTEXT_PATH, contextPath);
+ contributor.getBundleContext().registerService(ContextHandler.class.getName(), contextHandler, dic);
}
/**
@@ -253,16 +252,14 @@ public class JettyBootstrapActivator implements BundleActivator
* registers it as an OSGi service. The tracker
* {@link JettyContextHandlerServiceTracker} will do the actual deployment.
*
- * @param contributor
- * The bundle that registers a new context
- * @param contextFilePath
- * The path to the file inside the bundle that defines the
- * context.
+ * @param contributor The bundle that registers a new context
+ * @param contextFilePath The path to the file inside the bundle that
+ * defines the context.
* @throws Exception
*/
public static void registerContext(Bundle contributor, String contextFilePath) throws Exception
{
- registerContext(contributor,contextFilePath,new Hashtable());
+ registerContext(contributor, contextFilePath, new Hashtable());
}
/**
@@ -270,33 +267,30 @@ public class JettyBootstrapActivator implements BundleActivator
* registers it as an OSGi service. The tracker
* {@link JettyContextHandlerServiceTracker} will do the actual deployment.
*
- * @param contributor
- * The bundle that registers a new context
- * @param contextFilePath
- * The path to the file inside the bundle that defines the
- * context.
- * @param dic
- * TODO: parameter description
+ * @param contributor The bundle that registers a new context
+ * @param contextFilePath The path to the file inside the bundle that
+ * defines the context.
+ * @param dic TODO: parameter description
* @throws Exception
*/
public static void registerContext(Bundle contributor, String contextFilePath, Dictionary dic) throws Exception
{
- checkBundleActivated();
+ checkBundleActivated();
ContextHandler contextHandler = new ContextHandler();
- dic.put(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH,contextFilePath);
- dic.put(IWebBundleDeployerHelper.INTERNAL_SERVICE_PROP_UNKNOWN_CONTEXT_HANDLER_TYPE,Boolean.TRUE.toString());
- contributor.getBundleContext().registerService(ContextHandler.class.getName(),contextHandler,dic);
+ dic.put(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH, contextFilePath);
+ dic.put(IWebBundleDeployerHelper.INTERNAL_SERVICE_PROP_UNKNOWN_CONTEXT_HANDLER_TYPE, Boolean.TRUE.toString());
+ contributor.getBundleContext().registerService(ContextHandler.class.getName(), contextHandler, dic);
}
public static void unregister(String contextPath)
{
// todo
}
-
+
/**
* Since org.eclipse.jetty.osgi.boot does not have a lazy activation policy
- * when one fo the static methods to register a webapp is called we should make sure that
- * the bundle is started.
+ * when one fo the static methods to register a webapp is called we should
+ * make sure that the bundle is started.
*/
private static void checkBundleActivated()
{
@@ -313,7 +307,7 @@ public class JettyBootstrapActivator implements BundleActivator
}
}
}
-
+
/**
* @return The bundle context for this bundle.
*/
@@ -322,6 +316,5 @@ public class JettyBootstrapActivator implements BundleActivator
checkBundleActivated();
return INSTANCE._bundleContext;
}
-
}
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java
index 2debdc43418..5df56950d0e 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java
@@ -348,7 +348,7 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
}
catch (IOException e)
{
- e.printStackTrace();
+ LOG.warn(e);
return null;
}
}
@@ -369,11 +369,11 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
}
catch (IOException e)
{
- e.printStackTrace();
+ LOG.warn(e);
return null;
}
}
-
+
public boolean isExtract()
{
return _extractWars;
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..17ea8d22cc7 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,25 @@ public class DefaultJettyAtJettyHomeHelper {
*/
private static String getJettyConfigurationURLs(File jettyhome)
{
- String jettyetc = System.getProperty(SYS_PROP_JETTY_ETC_FILES,"etc/jetty.xml");
- StringTokenizer tokenizer = new StringTokenizer(jettyetc,";,", false);
+ 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)
+ {
+ LOG.warn(e);
+ continue;
+ }
+ }
+ appendToCommaSeparatedList(res, next);
}
return res.toString();
}
@@ -202,108 +200,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())
+ {
+ LOG.warn("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