diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/config/AbstractServerConfiguration.java b/opencga-core/src/main/java/org/opencb/opencga/core/config/AbstractServerConfiguration.java index 060c72ceacc..cffc7fe68b8 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/config/AbstractServerConfiguration.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/config/AbstractServerConfiguration.java @@ -16,13 +16,13 @@ package org.opencb.opencga.core.config; + /** * Created by imedina on 25/04/16. */ public abstract class AbstractServerConfiguration { protected int port; - protected String logFile; public AbstractServerConfiguration() { } @@ -35,7 +35,6 @@ public AbstractServerConfiguration(int port) { public String toString() { final StringBuilder sb = new StringBuilder("ServerConfiguration{"); sb.append("port=").append(port); - sb.append(", logFile='").append(logFile).append('\''); sb.append('}'); return sb.toString(); } @@ -49,13 +48,9 @@ public AbstractServerConfiguration setPort(int port) { return this; } - public String getLogFile() { - return logFile; - } - - public AbstractServerConfiguration setLogFile(String logFile) { - this.logFile = logFile; - return this; + @Deprecated + protected void setLogFile(Object o) { + Configuration.reportUnusedField("configuration.yml#server.[rest|grpc].logFile", o); } } diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/config/Configuration.java b/opencga-core/src/main/java/org/opencb/opencga/core/config/Configuration.java index bb5057a76e2..be957b160a7 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/config/Configuration.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/config/Configuration.java @@ -66,6 +66,8 @@ public class Configuration { private static Logger logger; + private static final Set reportedFields = new HashSet<>(); + private static final String DEFAULT_CONFIGURATION_FORMAT = "yaml"; static { @@ -200,6 +202,16 @@ private static void overwriteWithEnvironmentVariables(Configuration configuratio } } + public static void reportUnusedField(String field, Object value) { + // Report only if the value is not null and not an empty string + if (value != null && !(value instanceof String && ((String) value).isEmpty())) { + if (reportedFields.add(field)) { + // Only log the first time a field is found + logger.warn("Ignored configuration option '{}' with value '{}'. The option was deprecated and removed.", field, value); + } + } + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("Configuration{"); @@ -246,9 +258,7 @@ public String getLogFile() { @Deprecated public Configuration setLogFile(String logFile) { - if (logFile != null) { - logger.warn("Deprecated option 'configuration.yml#logFile'"); - } + reportUnusedField("configuration.yml#logFile", logFile); return this; } diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/config/RestServerConfiguration.java b/opencga-core/src/main/java/org/opencb/opencga/core/config/RestServerConfiguration.java index 99ea3ada10c..f87075e9a02 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/config/RestServerConfiguration.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/config/RestServerConfiguration.java @@ -16,52 +16,132 @@ package org.opencb.opencga.core.config; +import java.util.Objects; + /** * Created by imedina on 22/05/16. */ public class RestServerConfiguration extends AbstractServerConfiguration { - private int defaultLimit; - private int maxLimit; - - + public HttpConfiguration httpConfiguration = new HttpConfiguration(); public RestServerConfiguration() { } public RestServerConfiguration(int port) { - this(port, 2000, 5000); - } - - public RestServerConfiguration(int port, int defaultLimit, int maxLimit) { super(port); - this.defaultLimit = defaultLimit; - this.maxLimit = maxLimit; } @Override public String toString() { final StringBuilder sb = new StringBuilder("RestServerConfiguration{"); - sb.append("defaultLimit=").append(defaultLimit); - sb.append(", maxLimit=").append(maxLimit); + sb.append("port=").append(port); + sb.append(", httpConfiguration=").append(httpConfiguration); sb.append('}'); return sb.toString(); } - public int getDefaultLimit() { - return defaultLimit; + @Deprecated + protected void setDefaultLimit(Object o) { + Configuration.reportUnusedField("configuration.yml#server.rest.defaultLimit", o); } - public RestServerConfiguration setDefaultLimit(int defaultLimit) { - this.defaultLimit = defaultLimit; - return this; + @Deprecated + protected void setMaxLimit(Object o) { + Configuration.reportUnusedField("configuration.yml#server.rest.maxLimit", o); } - public int getMaxLimit() { - return maxLimit; + public HttpConfiguration getHttpConfiguration() { + return httpConfiguration; } - public RestServerConfiguration setMaxLimit(int maxLimit) { - this.maxLimit = maxLimit; + public RestServerConfiguration setHttpConfiguration(HttpConfiguration httpConfiguration) { + this.httpConfiguration = httpConfiguration; return this; } + + public static class HttpConfiguration { + private int outputBufferSize = -1; + private int outputAggregationSize = -1; + private int requestHeaderSize = -1; + private int responseHeaderSize = -1; + private int headerCacheSize = -1; + + public int getOutputBufferSize() { + return outputBufferSize; + } + + public HttpConfiguration setOutputBufferSize(int outputBufferSize) { + this.outputBufferSize = outputBufferSize; + return this; + } + + public int getOutputAggregationSize() { + return outputAggregationSize; + } + + public HttpConfiguration setOutputAggregationSize(int outputAggregationSize) { + this.outputAggregationSize = outputAggregationSize; + return this; + } + + public int getRequestHeaderSize() { + return requestHeaderSize; + } + + public HttpConfiguration setRequestHeaderSize(int requestHeaderSize) { + this.requestHeaderSize = requestHeaderSize; + return this; + } + + public int getResponseHeaderSize() { + return responseHeaderSize; + } + + public HttpConfiguration setResponseHeaderSize(int responseHeaderSize) { + this.responseHeaderSize = responseHeaderSize; + return this; + } + + public int getHeaderCacheSize() { + return headerCacheSize; + } + + public HttpConfiguration setHeaderCacheSize(int headerCacheSize) { + this.headerCacheSize = headerCacheSize; + return this; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("HttpConfiguration{"); + sb.append("outputBufferSize=").append(outputBufferSize); + sb.append(", outputAggregationSize=").append(outputAggregationSize); + sb.append(", requestHeaderSize=").append(requestHeaderSize); + sb.append(", responseHeaderSize=").append(responseHeaderSize); + sb.append(", headerCacheSize=").append(headerCacheSize); + sb.append('}'); + return sb.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + HttpConfiguration that = (HttpConfiguration) o; + return outputBufferSize == that.outputBufferSize && + outputAggregationSize == that.outputAggregationSize && + requestHeaderSize == that.requestHeaderSize && + responseHeaderSize == that.responseHeaderSize && + headerCacheSize == that.headerCacheSize; + } + + @Override + public int hashCode() { + return Objects.hash(outputBufferSize, outputAggregationSize, requestHeaderSize, responseHeaderSize, headerCacheSize); + } + } } diff --git a/opencga-core/src/main/resources/configuration.yml b/opencga-core/src/main/resources/configuration.yml index dfc1526ab57..ad99aa68f79 100644 --- a/opencga-core/src/main/resources/configuration.yml +++ b/opencga-core/src/main/resources/configuration.yml @@ -73,12 +73,20 @@ authentication: server: rest: port: ${OPENCGA.SERVER.REST.PORT} - logFile: null - defaultLimit: 2000 - maxLimit: 5000 + httpConfiguration: + # The size in bytes of the output buffer used to aggregate HTTP output + outputBufferSize: 32768 + # The maximum size in bytes for HTTP output to be aggregated + outputAggregationSize: 8192 + # The maximum allowed size in bytes for a HTTP request header + requestHeaderSize: 8192 + # The maximum allowed size in bytes for a HTTP response header + responseHeaderSize: 8192 + # The maximum allowed size in bytes for a HTTP header field cache + headerCacheSize: 4096 + grpc: port: ${OPENCGA.SERVER.GRPC.PORT} - logFile: null optimizations: simplifyPermissions: ${OPENCGA_OPTIMIZATIONS_SIMPLIFY_PERMISSIONS} diff --git a/opencga-core/src/test/java/org/opencb/opencga/core/config/ConfigurationTest.java b/opencga-core/src/test/java/org/opencb/opencga/core/config/ConfigurationTest.java index a617f0049b0..5a65e947bf8 100644 --- a/opencga-core/src/test/java/org/opencb/opencga/core/config/ConfigurationTest.java +++ b/opencga-core/src/test/java/org/opencb/opencga/core/config/ConfigurationTest.java @@ -16,15 +16,15 @@ package org.opencb.opencga.core.config; -import org.apache.commons.lang3.StringUtils; import org.junit.Test; import org.junit.experimental.categories.Category; import org.opencb.opencga.core.testclassification.duration.ShortTests; -import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.text.SimpleDateFormat; import java.util.*; /** @@ -34,68 +34,7 @@ public class ConfigurationTest { @Test - public void test() { - String path1 = "a/b/c.txt"; - String path2 = "a/b/c/"; - String path3 = "p.txt"; - - System.out.println(path1 + " ---- " + getParentPath(path1)); - System.out.println(path2 + " ---- " + getParentPath(path2)); - System.out.println(path3 + " ---- " + getParentPath(path3)); - - System.out.println(path1 + " ---- " + calculateAllPossiblePaths(path1)); - System.out.println(path2 + " ---- " + calculateAllPossiblePaths(path2)); - System.out.println(path3 + " ---- " + calculateAllPossiblePaths(path3)); - System.out.println("'' ---- " + calculateAllPossiblePaths("")); - - System.out.println(path1 + " ---- " + getFileName(path1)); - System.out.println(path2 + " ---- " + getFileName(path2)); - System.out.println(path3 + " ---- " + getFileName(path3)); - System.out.println("'' ---- " + getFileName("")); - - } - - String getParentPath(String strPath) { - Path path = Paths.get(strPath); - Path parent = path.getParent(); - if (parent != null) { - return parent.toString() + "/"; - } else { - return ""; - } - } - - String getFileName(String strPath) { - if (StringUtils.isEmpty(strPath)) { - return "."; - } - return Paths.get(strPath).getFileName().toString(); - } - - public static List calculateAllPossiblePaths(String filePath) { - if (StringUtils.isEmpty(filePath) || "/".equals(filePath)) { - return Collections.singletonList(""); - } - StringBuilder pathBuilder = new StringBuilder(); - String[] split = filePath.split("/"); - List paths = new ArrayList<>(split.length + 1); - paths.add(""); //Add study root folder - //Add intermediate folders - //Do not add the last split, could be a file or a folder.. - //Depending on this, it could end with '/' or not. - for (int i = 0; i < split.length - 1; i++) { - String f = split[i]; - System.out.println(f); - pathBuilder = new StringBuilder(pathBuilder.toString()).append(f).append("/"); - paths.add(pathBuilder.toString()); - } - paths.add(filePath); //Add the file path - return paths; - } - - - @Test - public void testDefault() { + public void testDefault() throws IOException { Configuration configuration = new Configuration(); configuration.setLogLevel("INFO"); @@ -136,7 +75,7 @@ public void testDefault() { configuration.setAudit(audit); ServerConfiguration serverConfiguration = new ServerConfiguration(); - RestServerConfiguration rest = new RestServerConfiguration(1000, 100, 1000); + RestServerConfiguration rest = new RestServerConfiguration(1000); GrpcServerConfiguration grpc = new GrpcServerConfiguration(1001); serverConfiguration.setGrpc(grpc); serverConfiguration.setRest(rest); @@ -155,11 +94,10 @@ public void testDefault() { // catalogConfiguration.getStorageEngines().add(storageEngineConfiguration1); // catalogConfiguration.getStorageEngines().add(storageEngineConfiguration2); - try { - configuration.serialize(new FileOutputStream("/tmp/configuration-test.yml")); - } catch (IOException e) { - e.printStackTrace(); - } + Path outdir = Paths.get("target/test-data", "junit-opencga-" + + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss.SSS").format(new Date())); + Files.createDirectories(outdir); + configuration.serialize(Files.newOutputStream(outdir.resolve("configuration-test.yml").toFile().toPath())); } @Test diff --git a/opencga-core/src/test/resources/configuration-test.yml b/opencga-core/src/test/resources/configuration-test.yml index 4d8d3c10f25..dad67f8c5dc 100644 --- a/opencga-core/src/test/resources/configuration-test.yml +++ b/opencga-core/src/test/resources/configuration-test.yml @@ -46,7 +46,7 @@ authentication: server: rest: port: 8080 - logFile: null + logFile: "some_file_but_this_field_is_deprecated" defaultLimit: 2000 maxLimit: 5000 diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/AbstractStorageServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/AbstractStorageServer.java index e1e880f2d47..d4bcb75d575 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/AbstractStorageServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/AbstractStorageServer.java @@ -16,58 +16,29 @@ package org.opencb.opencga.server; -import org.apache.commons.lang3.StringUtils; import org.opencb.opencga.core.config.Configuration; import org.opencb.opencga.core.config.storage.StorageConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; /** * Created by imedina on 02/01/16. */ public abstract class AbstractStorageServer { - @Deprecated - protected Path configDir; protected Path opencgaHome; protected int port; protected Configuration configuration; protected StorageConfiguration storageConfiguration; - /** - * This is the default StorageEngine to use when it is not provided by the client. - */ - @Deprecated - protected String defaultStorageEngine; - protected Logger logger; - - @Deprecated - public AbstractStorageServer() { - initDefaultConfigurationFiles(); - } - - @Deprecated - public AbstractStorageServer(int port, String defaultStorageEngine) { - initDefaultConfigurationFiles(); - - this.port = port; - if (StringUtils.isNotEmpty(defaultStorageEngine)) { - this.defaultStorageEngine = defaultStorageEngine; - } else { - this.defaultStorageEngine = storageConfiguration.getVariant().getDefaultEngine(); - } - } - public AbstractStorageServer(Path opencgaHome) { this(opencgaHome, 0); } @@ -93,33 +64,15 @@ private void initConfigurationFiles(Path opencgaHome) { try { if (opencgaHome != null && Files.exists(opencgaHome) && Files.isDirectory(opencgaHome) && Files.exists(opencgaHome.resolve("conf"))) { - logger.info("Loading configuration files from '{}'", opencgaHome.toString()); -// generalConfiguration = GeneralConfiguration.load(GeneralConfiguration.class.getClassLoader().getResourceAsStream("configuration.yml")); - configuration = Configuration - .load(new FileInputStream(new File(opencgaHome.resolve("conf").toFile().getAbsolutePath() + "/configuration.yml"))); - storageConfiguration = StorageConfiguration - .load(new FileInputStream(new File(opencgaHome.resolve("conf").toFile().getAbsolutePath() + "/storage-configuration.yml"))); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Deprecated - private void initDefaultConfigurationFiles() { - try { - if (System.getenv("OPENCGA_HOME") != null) { - initConfigurationFiles(Paths.get(System.getenv("OPENCGA_HOME") + "/conf")); - } else { - logger.info("Loading configuration files from inside JAR file"); + logger.info("Loading configuration files from '{}'", opencgaHome); // generalConfiguration = GeneralConfiguration.load(GeneralConfiguration.class.getClassLoader().getResourceAsStream("configuration.yml")); configuration = Configuration - .load(Configuration.class.getClassLoader().getResourceAsStream("configuration.yml")); + .load(Files.newInputStream(opencgaHome.resolve("conf").resolve("configuration.yml").toFile().toPath())); storageConfiguration = StorageConfiguration - .load(StorageConfiguration.class.getClassLoader().getResourceAsStream("storage-configuration.yml")); + .load(Files.newInputStream(opencgaHome.resolve("conf").resolve("storage-configuration.yml").toFile().toPath())); } } catch (IOException e) { - e.printStackTrace(); + throw new UncheckedIOException(e); } } @@ -133,7 +86,6 @@ private void initDefaultConfigurationFiles() { public String toString() { final StringBuilder sb = new StringBuilder("StorageServer{"); sb.append("port=").append(port); - sb.append(", defaultStorageEngine='").append(defaultStorageEngine).append('\''); sb.append('}'); return sb.toString(); } @@ -146,12 +98,4 @@ public void setPort(int port) { this.port = port; } - public String getDefaultStorageEngine() { - return defaultStorageEngine; - } - - public void setDefaultStorageEngine(String defaultStorageEngine) { - this.defaultStorageEngine = defaultStorageEngine; - } - } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/RestServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/RestServer.java index 28bdffc8016..c3f87c68239 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/RestServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/RestServer.java @@ -16,8 +16,12 @@ package org.opencb.opencga.server; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.webapp.WebAppContext; +import org.opencb.opencga.core.config.RestServerConfiguration; import java.io.IOException; import java.nio.file.Files; @@ -44,9 +48,34 @@ public RestServer(Path opencgaHome, int port) { @Override public void start() throws Exception { - server = new Server(port); + initServer(); - WebAppContext webapp = new WebAppContext(); + Path war = getOpencgaWar(); + + initWebApp(war); + + server.start(); + logger.info("REST server started, listening on {}", server.getURI()); + + initHooks(); + +// // AdminWSServer server needs a reference to this class to cll to .stop() +// AdminRestWebService.setServer(this); + } + + protected Server initServer() { + server = new Server(); + + HttpConfiguration httpConfig = getHttpConfiguration(); + + ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); + httpConnector.setPort(port); + + server.addConnector(httpConnector); + return server; + } + + protected Path getOpencgaWar() throws Exception { Optional warPath; try (Stream stream = Files.list(opencgaHome)) { warPath = stream @@ -56,35 +85,36 @@ public void start() throws Exception { throw new Exception("Error accessing OpenCGA Home: " + opencgaHome.toString(), e); } // Check is a war file has been found in opencgaHome - if (warPath == null || !warPath.isPresent()) { + if (!warPath.isPresent()) { throw new Exception("No war file found at " + opencgaHome.toString()); } + return warPath.get(); + } - String opencgaVersion = warPath.get().toFile().getName().replace(".war", ""); + protected WebAppContext initWebApp(Path war) throws Exception { + String opencgaVersion = war.toFile().getName().replace(".war", ""); + WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/" + opencgaVersion); - webapp.setWar(warPath.get().toString()); + webapp.setWar(war.toString()); webapp.setClassLoader(this.getClass().getClassLoader()); webapp.setInitParameter("OPENCGA_HOME", opencgaHome.toFile().toString()); webapp.getServletContext().setAttribute("OPENCGA_HOME", opencgaHome.toFile().toString()); // webapp.setInitParameter("log4jConfiguration", opencgaHome.resolve("conf/log4j2.server.xml").toString()); server.setHandler(webapp); + return webapp; + } - server.start(); - logger.info("REST server started, listening on {}", port); - + protected void initHooks() { // A hook is added in case the JVM is shutting down - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - try { - if (server.isRunning()) { - stopJettyServer(); - } - } catch (Exception e) { - e.printStackTrace(); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + if (server.isRunning()) { + stopJettyServer(); } + } catch (Exception e) { + logger.error("Error stopping Jetty server", e); } - }); + })); // A separated thread is launched to shut down the server new Thread(() -> { @@ -97,12 +127,30 @@ public void run() { Thread.sleep(500); } } catch (Exception e) { - e.printStackTrace(); + logger.error("Error stopping Jetty server", e); } }).start(); + } -// // AdminWSServer server needs a reference to this class to cll to .stop() -// AdminRestWebService.setServer(this); + protected HttpConfiguration getHttpConfiguration() { + HttpConfiguration httpConfig = new HttpConfiguration(); + RestServerConfiguration.HttpConfiguration restHttpConf = configuration.getServer().getRest().getHttpConfiguration(); + if (restHttpConf.getOutputBufferSize() > 0) { + httpConfig.setOutputBufferSize(restHttpConf.getOutputBufferSize()); + } + if (restHttpConf.getOutputAggregationSize() > 0) { + httpConfig.setOutputAggregationSize(restHttpConf.getOutputAggregationSize()); + } + if (restHttpConf.getRequestHeaderSize() > 0) { + httpConfig.setRequestHeaderSize(restHttpConf.getRequestHeaderSize()); + } + if (restHttpConf.getResponseHeaderSize() > 0) { + httpConfig.setResponseHeaderSize(restHttpConf.getResponseHeaderSize()); + } + if (restHttpConf.getHeaderCacheSize() > 0) { + httpConfig.setHeaderCacheSize(restHttpConf.getHeaderCacheSize()); + } + return httpConfig; } @Override diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/grpc/GrpcServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/grpc/GrpcServer.java index 76b4c350a32..32ded068042 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/grpc/GrpcServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/grpc/GrpcServer.java @@ -19,7 +19,6 @@ import io.grpc.Server; import io.grpc.ServerBuilder; import org.opencb.opencga.server.AbstractStorageServer; -import org.opencb.opencga.core.config.storage.StorageConfiguration; import org.slf4j.LoggerFactory; import java.nio.file.Path; @@ -31,29 +30,11 @@ public class GrpcServer extends AbstractStorageServer { private Server server; - public GrpcServer() { -// this(storageConfiguration.getServer().getGrpc(), storageConfiguration.getDefaultStorageEngineId()); - } - - public GrpcServer(int port, String defaultStorageEngine) { - super(port, defaultStorageEngine); - - logger = LoggerFactory.getLogger(this.getClass()); - } - public GrpcServer(Path configDir) { super(configDir); init(); } - @Deprecated - public GrpcServer(StorageConfiguration storageConfiguration) { -// super(storageConfiguration.getServer().getGrpc(), storageConfiguration.getDefaultStorageEngineId()); - this.storageConfiguration = storageConfiguration; - - logger = LoggerFactory.getLogger(this.getClass()); - } - private void init() { logger = LoggerFactory.getLogger(this.getClass()); if (configuration != null) { diff --git a/opencga-storage/opencga-storage-core/src/main/resources/storage-configuration.yml b/opencga-storage/opencga-storage-core/src/main/resources/storage-configuration.yml index 226fc106783..4f64a3ad939 100644 --- a/opencga-storage/opencga-storage-core/src/main/resources/storage-configuration.yml +++ b/opencga-storage/opencga-storage-core/src/main/resources/storage-configuration.yml @@ -18,10 +18,8 @@ cellbase: server: rest: port: ${OPENCGA.SERVER.REST.PORT} - logFile: null grpc: port: ${OPENCGA.SERVER.GRPC.PORT} - logFile: null ## Solr Search Configuration search: diff --git a/opencga-storage/opencga-storage-server/src/main/java/org/opencb/opencga/storage/server/rest/RestStorageServer.java b/opencga-storage/opencga-storage-server/src/main/java/org/opencb/opencga/storage/server/rest/RestStorageServer.java index 226c8ab46ce..5343a17eb1d 100644 --- a/opencga-storage/opencga-storage-server/src/main/java/org/opencb/opencga/storage/server/rest/RestStorageServer.java +++ b/opencga-storage/opencga-storage-server/src/main/java/org/opencb/opencga/storage/server/rest/RestStorageServer.java @@ -16,11 +16,15 @@ package org.opencb.opencga.storage.server.rest; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; +import org.opencb.opencga.core.config.RestServerConfiguration; import org.opencb.opencga.core.config.storage.StorageConfiguration; import org.opencb.opencga.storage.server.common.AbstractStorageServer; import org.slf4j.LoggerFactory; @@ -60,7 +64,14 @@ public void start() throws Exception { ServletHolder sh = new ServletHolder("opencga", sc); logger.info("Server in port : {}", port); - server = new Server(port); + server = new Server(); + + HttpConfiguration httpConfig = getHttpConfiguration(); + + ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); + httpConnector.setPort(port); + + server.addConnector(httpConnector); ServletContextHandler context = new ServletContextHandler(server, null, ServletContextHandler.SESSIONS); context.addServlet(sh, "/opencga/webservices/rest/*"); @@ -103,6 +114,27 @@ public void run() { AdminRestWebService.setServer(this); } + private HttpConfiguration getHttpConfiguration() { + HttpConfiguration httpConfig = new HttpConfiguration(); + RestServerConfiguration.HttpConfiguration restHttpConf = storageConfiguration.getServer().getRest().getHttpConfiguration(); + if (restHttpConf.getOutputBufferSize() > 0) { + httpConfig.setOutputBufferSize(restHttpConf.getOutputBufferSize()); + } + if (restHttpConf.getOutputAggregationSize() > 0) { + httpConfig.setOutputAggregationSize(restHttpConf.getOutputAggregationSize()); + } + if (restHttpConf.getRequestHeaderSize() > 0) { + httpConfig.setRequestHeaderSize(restHttpConf.getRequestHeaderSize()); + } + if (restHttpConf.getResponseHeaderSize() > 0) { + httpConfig.setResponseHeaderSize(restHttpConf.getResponseHeaderSize()); + } + if (restHttpConf.getHeaderCacheSize() > 0) { + httpConfig.setHeaderCacheSize(restHttpConf.getHeaderCacheSize()); + } + return httpConfig; + } + @Override public void stop() throws Exception { // By setting exit to true the monitor thread will close the Jetty server