From e783777d1c3aa0d7431a8461d0089e15e6bbb966 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 4 May 2016 09:14:35 +1000 Subject: [PATCH 1/5] Issue #519 Disable SSL session caching Made caching parameters configurable --- .../src/main/config/etc/jetty-ssl-context.xml | 11 ++++++++--- jetty-server/src/main/config/modules/ssl.mod | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/jetty-server/src/main/config/etc/jetty-ssl-context.xml b/jetty-server/src/main/config/etc/jetty-ssl-context.xml index 7af6e66c606..1b266d1c744 100644 --- a/jetty-server/src/main/config/etc/jetty-ssl-context.xml +++ b/jetty-server/src/main/config/etc/jetty-ssl-context.xml @@ -4,6 +4,12 @@ + + + / @@ -17,8 +23,7 @@ - + + diff --git a/jetty-server/src/main/config/modules/ssl.mod b/jetty-server/src/main/config/modules/ssl.mod index 335667fae52..75263c6c994 100644 --- a/jetty-server/src/main/config/modules/ssl.mod +++ b/jetty-server/src/main/config/modules/ssl.mod @@ -89,3 +89,9 @@ https://raw.githubusercontent.com/eclipse/jetty.project/master/jetty-server/src/ ## To configure Includes / Excludes for Cipher Suites or Protocols see tweak-ssl.xml example at ## https://www.eclipse.org/jetty/documentation/current/configuring-ssl.html#configuring-sslcontextfactory-cipherSuites + +## Set the size of the SslSession cache +# jetty.sslContext.sslSessionCacheSize=-1 + +## Set the timeout (in seconds) of the SslSession cache timeout +# jetty.sslContext.sslSessionTimeout=-1 From 3066880cd2249cc65fa7890f2348cc35ddd64573 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 4 May 2016 09:53:00 +1000 Subject: [PATCH 2/5] fixed bad merge --- .../java/org/eclipse/jetty/util/thread/ExecutionStrategy.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java index 8128902f6ac..b3ea5a874dd 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java @@ -101,8 +101,6 @@ public interface ExecutionStrategy { return DefaultExecutionStrategyFactory.INSTANCE; } - * @param producer the execution strategy producer - * @param executor the execution strategy executor } public static class DefaultExecutionStrategyFactory implements Factory From 90110659e2bcd4bc13aa4e59b01de2d8e6b49d48 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 4 May 2016 10:49:22 +1000 Subject: [PATCH 3/5] fixed javadoc --- .../java/org/eclipse/jetty/util/thread/QueuedThreadPool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java index cc937ee5974..b52daa037f0 100755 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java @@ -286,7 +286,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo } /** - * Set the maximum number of threads. + * Get the maximum number of threads. * Delegated to the named or anonymous Pool. * * @return maximum number of threads. From a32e3a2091a12c0b3d0f9dfd7a7ae4c4d144da52 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 4 May 2016 10:53:05 +1000 Subject: [PATCH 4/5] avoided NPE in example --- .../main/java/org/eclipse/jetty/embedded/Http2Server.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Http2Server.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Http2Server.java index 28f8547a1ef..0502fb2f65c 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Http2Server.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Http2Server.java @@ -179,8 +179,10 @@ public class Http2Server content+="session="+session.getId()+(session.isNew()?"(New)\n":"\n"); content+="date="+new Date()+"\n"; - for (Cookie c : request.getCookies()) - content+="cookie "+c.getName()+"="+c.getValue()+"\n"; + Cookie[] cookies = request.getCookies(); + if (cookies!=null && cookies.length>0) + for (Cookie c : cookies) + content+="cookie "+c.getName()+"="+c.getValue()+"\n"; response.setContentLength(content.length()); response.getOutputStream().print(content); From 5b8f411ba9b6d868dbb25d5f8008649e9830142e Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 4 May 2016 11:08:49 +1000 Subject: [PATCH 5/5] Issue #539 Made ResourceService pluggable --- .../org/eclipse/jetty/http/HttpContent.java | 2 +- .../jetty/server/CachedContentFactory.java | 2 +- .../jetty/server/ResourceContentFactory.java | 4 +- .../eclipse/jetty/server/ResourceService.java | 48 ++++++++---- .../jetty/server/handler/ResourceHandler.java | 57 ++++++++------ .../eclipse/jetty/servlet/DefaultServlet.java | 74 ++++++++++--------- 6 files changed, 109 insertions(+), 78 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java index 5ef096a486f..94800b444de 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpContent.java @@ -67,7 +67,7 @@ public interface HttpContent Map getPrecompressedContents(); - public interface Factory + public interface ContentFactory { /** * @param path The path within the context to the resource diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/CachedContentFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/CachedContentFactory.java index 55818c55eeb..36561e453fa 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/CachedContentFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/CachedContentFactory.java @@ -52,7 +52,7 @@ import org.eclipse.jetty.util.resource.ResourceFactory; /** * Caching HttpContent.Factory */ -public class CachedContentFactory implements HttpContent.Factory +public class CachedContentFactory implements HttpContent.ContentFactory { private static final Logger LOG = Log.getLogger(CachedContentFactory.class); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceContentFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceContentFactory.java index 33a79ab7094..1de633ea9f1 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceContentFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceContentFactory.java @@ -24,7 +24,7 @@ import java.util.Map; import org.eclipse.jetty.http.CompressedContentFormat; import org.eclipse.jetty.http.HttpContent; -import org.eclipse.jetty.http.HttpContent.Factory; +import org.eclipse.jetty.http.HttpContent.ContentFactory; import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.http.ResourceHttpContent; import org.eclipse.jetty.util.resource.Resource; @@ -36,7 +36,7 @@ import org.eclipse.jetty.util.resource.ResourceFactory; * this factory are not intended to be cached, so memory limits for individual * HttpOutput streams are enforced. */ -public class ResourceContentFactory implements Factory +public class ResourceContentFactory implements ContentFactory { private final ResourceFactory _factory; private final MimeTypes _mimeTypes; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java index 5167fb0716d..19eaa3b5293 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java @@ -65,13 +65,14 @@ import org.eclipse.jetty.util.resource.Resource; * Abstract resource service, used by DefaultServlet and ResourceHandler * */ -public abstract class ResourceService +public class ResourceService { private static final Logger LOG = Log.getLogger(ResourceService.class); private static final PreEncodedHttpField ACCEPT_RANGES = new PreEncodedHttpField(HttpHeader.ACCEPT_RANGES, "bytes"); - private HttpContent.Factory _contentFactory; + private HttpContent.ContentFactory _contentFactory; + private WelcomeFactory _welcomeFactory; private boolean _acceptRanges=true; private boolean _dirAllowed=true; private boolean _redirectWelcome=false; @@ -83,16 +84,25 @@ public abstract class ResourceService private boolean _etags=false; private HttpField _cacheControl; private List _gzipEquivalentFileExtensions; - - public HttpContent.Factory getContentFactory() + + + public HttpContent.ContentFactory getContentFactory() { return _contentFactory; } - public void setContentFactory(HttpContent.Factory contentFactory) + public void setContentFactory(HttpContent.ContentFactory contentFactory) { _contentFactory = contentFactory; } + + public WelcomeFactory getWelcomeFactory() { + return _welcomeFactory; + } + + public void setWelcomeFactory(WelcomeFactory welcomeFactory) { + _welcomeFactory = welcomeFactory; + } public boolean isAcceptRanges() { @@ -384,7 +394,7 @@ public abstract class ResourceService } // look for a welcome file - String welcome=getWelcomeFile(pathInContext); + String welcome=_welcomeFactory==null?null:_welcomeFactory.getWelcomeFile(pathInContext); if (welcome!=null) { if (LOG.isDebugEnabled()) @@ -440,14 +450,10 @@ public abstract class ResourceService } /* ------------------------------------------------------------ */ - /** - * Finds a matching welcome file for the supplied {@link Resource}. - * @param pathInContext the path of the request - * @return The path of the matching welcome file in context or null. - */ - protected abstract String getWelcomeFile(String pathInContext); - - protected abstract void notFound(HttpServletRequest request, HttpServletResponse response) throws IOException; + protected void notFound(HttpServletRequest request, HttpServletResponse response) throws IOException + { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } /* ------------------------------------------------------------ */ /* Check modification date headers. @@ -871,4 +877,18 @@ public abstract class ResourceService } } + /* ------------------------------------------------------------ */ + /* ------------------------------------------------------------ */ + /* ------------------------------------------------------------ */ + public interface WelcomeFactory + { + /* ------------------------------------------------------------ */ + /** + * Finds a matching welcome file for the supplied {@link Resource}. + * @param pathInContext the path of the request + * @return The path of the matching welcome file in context or null. + */ + String getWelcomeFile(String pathInContext); + + } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java index 4a8b9ec155a..ead77e77cee 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java @@ -35,6 +35,7 @@ import org.eclipse.jetty.http.PreEncodedHttpField; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.ResourceContentFactory; import org.eclipse.jetty.server.ResourceService; +import org.eclipse.jetty.server.ResourceService.WelcomeFactory; import org.eclipse.jetty.server.handler.ContextHandler.Context; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.log.Log; @@ -51,7 +52,7 @@ import org.eclipse.jetty.util.resource.ResourceFactory; * * */ -public class ResourceHandler extends HandlerWrapper implements ResourceFactory +public class ResourceHandler extends HandlerWrapper implements ResourceFactory,WelcomeFactory { private static final Logger LOG = Log.getLogger(ResourceHandler.class); @@ -61,40 +62,47 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory MimeTypes _mimeTypes; private final ResourceService _resourceService; Resource _stylesheet; - String[] _welcomes = - { "index.html" }; + String[] _welcomes = { "index.html" }; + + /* ------------------------------------------------------------ */ + public ResourceHandler(ResourceService resourceService) + { + _resourceService=resourceService; + } /* ------------------------------------------------------------ */ public ResourceHandler() { - _resourceService = new ResourceService() + this(new ResourceService() { - @Override - protected String getWelcomeFile(String pathInContext) - { - if (_welcomes == null) - return null; - - String welcome_servlet = null; - for (int i = 0; i < _welcomes.length; i++) - { - String welcome_in_context = URIUtil.addPaths(pathInContext,_welcomes[i]); - Resource welcome = getResource(welcome_in_context); - if (welcome != null && welcome.exists()) - return _welcomes[i]; - } - return welcome_servlet; - } - @Override protected void notFound(HttpServletRequest request, HttpServletResponse response) throws IOException { } - }; - _resourceService.setGzipEquivalentFileExtensions(new ArrayList<>(Arrays.asList(new String[] - { ".svgz" }))); + }); + _resourceService.setGzipEquivalentFileExtensions(new ArrayList<>(Arrays.asList(new String[] { ".svgz" }))); } + + /* ------------------------------------------------------------ */ + @Override + public String getWelcomeFile(String pathInContext) + { + if (_welcomes == null) + return null; + + String welcome_servlet = null; + for (int i = 0; i < _welcomes.length; i++) + { + String welcome_in_context = URIUtil.addPaths(pathInContext,_welcomes[i]); + Resource welcome = getResource(welcome_in_context); + if (welcome != null && welcome.exists()) + return _welcomes[i]; + } + return welcome_servlet; + } + + /* ------------------------------------------------------------ */ @Override public void doStart() throws Exception @@ -104,6 +112,7 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory _mimeTypes = _context == null?new MimeTypes():_context.getMimeTypes(); _resourceService.setContentFactory(new ResourceContentFactory(this,_mimeTypes,_resourceService.getPrecompressedFormats())); + _resourceService.setWelcomeFactory(this); super.doStart(); } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java index af152b53976..20ad36c55ce 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java @@ -40,6 +40,7 @@ import org.eclipse.jetty.http.pathmap.MappedResource; import org.eclipse.jetty.server.CachedContentFactory; import org.eclipse.jetty.server.ResourceContentFactory; import org.eclipse.jetty.server.ResourceService; +import org.eclipse.jetty.server.ResourceService.WelcomeFactory; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.log.Log; @@ -126,7 +127,7 @@ import org.eclipse.jetty.util.resource.ResourceFactory; * * */ -public class DefaultServlet extends HttpServlet implements ResourceFactory +public class DefaultServlet extends HttpServlet implements ResourceFactory, WelcomeFactory { private static final Logger LOG = Log.getLogger(DefaultServlet.class); @@ -150,42 +151,16 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory private ServletHandler _servletHandler; private ServletHolder _defaultHolder; + /* ------------------------------------------------------------ */ + public DefaultServlet(ResourceService resourceService) + { + _resourceService=resourceService; + } + + /* ------------------------------------------------------------ */ public DefaultServlet() { - _resourceService = new ResourceService() - { - @Override - protected String getWelcomeFile(String pathInContext) - { - if (_welcomes==null) - return null; - - String welcome_servlet=null; - for (int i=0;i<_welcomes.length;i++) - { - String welcome_in_context=URIUtil.addPaths(pathInContext,_welcomes[i]); - Resource welcome=getResource(welcome_in_context); - if (welcome!=null && welcome.exists()) - return _welcomes[i]; - - if ((_welcomeServlets || _welcomeExactServlets) && welcome_servlet==null) - { - MappedResource entry=_servletHandler.getHolderEntry(welcome_in_context); - if (entry!=null && entry.getResource()!=_defaultHolder && - (_welcomeServlets || (_welcomeExactServlets && entry.getPathSpec().getDeclaration().equals(welcome_in_context)))) - welcome_servlet=welcome_in_context; - - } - } - return welcome_servlet; - } - - @Override - protected void notFound(HttpServletRequest request, HttpServletResponse response) throws IOException - { - response.sendError(HttpServletResponse.SC_NOT_FOUND); - } - }; + this(new ResourceService()); } /* ------------------------------------------------------------ */ @@ -299,7 +274,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory throw new UnavailableException(e.toString()); } - HttpContent.Factory contentFactory=_cache; + HttpContent.ContentFactory contentFactory=_cache; if (contentFactory==null) { contentFactory=new ResourceContentFactory(this,_mimeTypes,_resourceService.getPrecompressedFormats()); @@ -307,6 +282,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory _servletContext.setAttribute(resourceCache,contentFactory); } _resourceService.setContentFactory(contentFactory); + _resourceService.setWelcomeFactory(this); List gzip_equivalent_file_extensions = new ArrayList(); String otherGzipExtensions = getInitParameter("otherGzipFileExtensions"); @@ -518,4 +494,30 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory super.destroy(); } + /* ------------------------------------------------------------ */ + @Override + public String getWelcomeFile(String pathInContext) + { + if (_welcomes==null) + return null; + + String welcome_servlet=null; + for (int i=0;i<_welcomes.length;i++) + { + String welcome_in_context=URIUtil.addPaths(pathInContext,_welcomes[i]); + Resource welcome=getResource(welcome_in_context); + if (welcome!=null && welcome.exists()) + return _welcomes[i]; + + if ((_welcomeServlets || _welcomeExactServlets) && welcome_servlet==null) + { + MappedResource entry=_servletHandler.getHolderEntry(welcome_in_context); + if (entry!=null && entry.getResource()!=_defaultHolder && + (_welcomeServlets || (_welcomeExactServlets && entry.getPathSpec().getDeclaration().equals(welcome_in_context)))) + welcome_servlet=welcome_in_context; + + } + } + return welcome_servlet; + } }