Only Serve API if using WebServer on Bungee

This commit is contained in:
Rsl1122 2017-09-17 12:37:50 +03:00
parent e048fb6d64
commit 7c154bbb5e
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,39 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.webserver;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
import java.io.IOException;
/**
* HttpHandler for webserver request management.
*
* @author Rsl1122
*/
public class APIRequestHandler implements HttpHandler {
private final APIResponseHandler responseHandler;
APIRequestHandler(WebAPIManager webAPI) {
responseHandler = new APIResponseHandler(webAPI);
}
@Override
public void handle(HttpExchange exchange) throws IOException {
Request request = new Request(exchange);
try {
Response response = responseHandler.getAPIResponse(request);
response.send(exchange);
} finally {
exchange.close();
}
}
}

View File

@ -91,7 +91,11 @@ public class WebServer {
server = HttpServer.create(new InetSocketAddress(port), 10); server = HttpServer.create(new InetSocketAddress(port), 10);
} }
server.createContext("/", new RequestHandler(plugin, this)); if (plugin.getInfoManager().isUsingBungeeWebServer()) {
server.createContext("/", new APIRequestHandler(getWebAPI()));
} else {
server.createContext("/", new RequestHandler(plugin, this));
}
server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100))); server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)));
server.start(); server.start();