Update Jetty

This commit is contained in:
RyotaK 2020-01-13 00:03:57 +00:00
parent 360916f5aa
commit 3991170245
8 changed files with 66 additions and 35 deletions

View File

@ -2,9 +2,10 @@ description = "DynmapCore"
dependencies {
compile project(path: ':DynmapCoreAPI', configuration: 'shadow')
compile 'org.eclipse.jetty:jetty-server:8.1.21.v20160908'
compile 'org.eclipse.jetty:jetty-servlet:8.1.21.v20160908'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'javax.servlet:javax.servlet-api:3.1'
compile 'org.eclipse.jetty:jetty-server:9.4.24.v20191120'
compile 'org.eclipse.jetty:jetty-servlet:9.4.24.v20191120'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'org.yaml:snakeyaml:1.23'
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20180219.1'
}
@ -34,9 +35,10 @@ jar {
shadowJar {
dependencies {
include(dependency('com.googlecode.json-simple:json-simple:'))
include(dependency('org.yaml:snakeyaml:'))
include(dependency('com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:'))
include(dependency('org.eclipse.jetty::'))
include(dependency('org.yaml:snakeyaml:'))
include(dependency('com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:'))
include(dependency('javax.servlet::'))
include(dependency('org.eclipse.jetty::'))
include(dependency('org.eclipse.jetty.orbit:javax.servlet:'))
include(dependency(':DynmapCoreAPI'))
}

View File

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
@ -65,10 +66,12 @@ import org.dynmap.web.CustomHeaderFilter;
import org.dynmap.web.FilterHandler;
import org.dynmap.web.HandlerRouter;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.NetworkTrafficServerConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.server.session.HashSessionIdManager;
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.resource.FileResource;
@ -768,21 +771,17 @@ public class DynmapCore implements DynmapCommonAPI {
webhostname = configuration.getString("webserver-bindaddress", ip);
webport = configuration.getInteger("webserver-port", 8123);
webServer = new Server();
webServer.setSessionIdManager(new HashSessionIdManager());
int maxconnections = configuration.getInteger("max-sessions", 30);
if(maxconnections < 2) maxconnections = 2;
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxconnections);
ExecutorThreadPool pool = new ExecutorThreadPool(2, maxconnections, 60, TimeUnit.SECONDS, queue);
webServer.setThreadPool(pool);
ExecutorThreadPool pool = new ExecutorThreadPool(maxconnections, 2, queue);
SelectChannelConnector connector=new SelectChannelConnector();
connector.setMaxIdleTime(5000);
connector.setAcceptors(1);
webServer = new Server(pool);
webServer.setSessionIdManager(new DefaultSessionIdManager(webServer));
NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(webServer);
connector.setIdleTimeout(5000);
connector.setAcceptQueueSize(50);
connector.setLowResourcesMaxIdleTime(1000);
connector.setLowResourcesConnections(maxconnections/2);
if(webhostname.equals("0.0.0.0") == false)
connector.setHost(webhostname);
connector.setPort(webport);
@ -790,15 +789,37 @@ public class DynmapCore implements DynmapCommonAPI {
webServer.setStopAtShutdown(true);
//webServer.setGracefulShutdown(1000);
final boolean allow_symlinks = configuration.getBoolean("allow-symlinks", false);
router = new HandlerRouter() {{
this.addHandler("/", new FileResourceHandler() {{
this.setAliases(allow_symlinks);
FileResourceHandler fileResourceHandler = new FileResourceHandler() {{
this.setWelcomeFiles(new String[] { "index.html" });
this.setRedirectWelcome(false);
this.setDirectoriesListed(true);
this.setBaseResource(createFileResource(getFile(getWebPath()).getAbsolutePath()));
}});
}};
try {
fileResourceHandler.doStart();
}catch (Exception ex){
ex.printStackTrace();
Log.severe("Failed to start resource handler: "+ex.getMessage());
}
ContextHandler fileResourceContext = new ContextHandler();
fileResourceContext.setHandler(fileResourceHandler);
fileResourceContext.clearAliasChecks();
if (allow_symlinks){
fileResourceContext.addAliasCheck(new ContextHandler.ApproveAliases());
fileResourceContext.addAliasCheck(new ContextHandler.ApproveNonExistentDirectoryAliases());
fileResourceContext.addAliasCheck(new AllowSymLinkAliasChecker());
}
try {
Class<?> handlerClass = fileResourceHandler.getClass().getSuperclass().getSuperclass();
Field field = handlerClass.getDeclaredField("_context");
field.setAccessible(true);
field.set(fileResourceHandler,fileResourceContext);
}catch (Exception e){
Log.severe("Failed to initialize resource handler: "+e.getMessage());
}
this.addHandler("/", fileResourceHandler);
this.addHandler("/tiles/*", new MapStorageResourceHandler() {{
this.setCore(DynmapCore.this);
}});

View File

@ -49,12 +49,7 @@ public class FileResourceHandler extends ResourceHandler {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Resource resource;
String normalizedTarget = getNormalizedPath(target);
try {
resource = getResource(normalizedTarget);
} catch(MalformedURLException ex) {
return;
}
resource = getResource(normalizedTarget);
if (resource == null) {
return;
}
@ -63,7 +58,7 @@ public class FileResourceHandler extends ResourceHandler {
return;
}
if(!target.equals(normalizedTarget)){
baseRequest.setRequestURI(normalizedTarget);
baseRequest.setURIPathQuery(normalizedTarget);
baseRequest.setPathInfo(normalizedTarget);
try{
Class<?> requestClass = request.getClass();

View File

@ -35,6 +35,10 @@ public class JettyNullLogger implements Logger {
public void debug(String s, Object... objects) {
}
@Override
public void debug(String s, long l) {
}
public void debug(Throwable throwable) {
}

View File

@ -1,5 +1,6 @@
package org.dynmap.web;
import org.dynmap.Log;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
@ -22,7 +23,14 @@ public class FilterHandler extends AbstractHandler {
public FilterHandler(Handler handler, Iterable<Filter> filters) {
this.handler = handler;
for(Filter f : filters) {
this.filters.add(new FilterHolder(f));
try {
FilterHolder holder = new FilterHolder(f);
holder.start();
holder.initialize();
this.filters.add(holder);
}catch (Exception e){
Log.severe("Failed to initialize filter holder: "+e.toString());
}
}
}

View File

@ -32,7 +32,7 @@ public class HandlerRouter extends AbstractHandler {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String pathInfo = request.getPathInfo();
PathMap.Entry e = pathMap.getMatch(pathInfo);
PathMap.MappedEntry e = pathMap.getMatch(pathInfo);
String mappedPath = e.getMapped();
String childPathInfo = pathInfo;

View File

@ -33,7 +33,7 @@ repositories {
}
minecraft {
mappings channel: 'snapshot', version: '20190215-1.13.1'
mappings channel: 'snapshot', version: '20190530-1.13.2'
runs {
server {
workingDirectory project.file('run').canonicalPath

View File

@ -1,5 +1,6 @@
#Mon Dec 23 11:14:00 JST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME