Merge remote-tracking branch 'origin/jetty-9.4.x'

This commit is contained in:
Greg Wilkins 2016-05-04 11:45:23 +10:00
commit 1c292819fe
11 changed files with 128 additions and 86 deletions

View File

@ -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);

View File

@ -67,7 +67,7 @@ public interface HttpContent
Map<CompressedContentFormat,? extends HttpContent> getPrecompressedContents();
public interface Factory
public interface ContentFactory
{
/**
* @param path The path within the context to the resource

View File

@ -4,6 +4,12 @@
<!-- ============================================================= -->
<!-- SSL ContextFactory configuration -->
<!-- ============================================================= -->
<!--
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
-->
<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
<Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.keyStorePath" deprecated="jetty.keystore" default="etc/keystore"/></Set>
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" deprecated="jetty.keystore.password" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
@ -17,8 +23,7 @@
<Set name="EndpointIdentificationAlgorithm"></Set>
<Set name="NeedClientAuth"><Property name="jetty.sslContext.needClientAuth" deprecated="jetty.ssl.needClientAuth" default="false"/></Set>
<Set name="WantClientAuth"><Property name="jetty.sslContext.wantClientAuth" deprecated="jetty.ssl.wantClientAuth" default="false"/></Set>
<!-- 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 name="useCipherSuitesOrder"><Property name="jetty.sslContext.useCipherSuitesOrder" default="true"/></Set>
<Set name="sslSessionCacheSize"><Property name="jetty.sslContext.sslSessionCacheSize" default="-1"/></Set>
<Set name="sslSessionTimeout"><Property name="jetty.sslContext.sslSessionTimeout" default="-1"/></Set>
</Configure>

View File

@ -87,3 +87,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

View File

@ -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);

View File

@ -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;

View File

@ -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<String> _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);
}
}

View File

@ -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();
}

View File

@ -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;
* </pre>
*
*/
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<ServletHolder> 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<String> gzip_equivalent_file_extensions = new ArrayList<String>();
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<ServletHolder> 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;
}
}

View File

@ -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

View File

@ -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.