trace-server: Add SSL support to the trace server
It's now possible to run the trace server using https, using vm
arguments to specify the port and path to the keystore.
Documentation for SSL configuration of jetty can be found here:
https://www.eclipse.org/jetty/documentation/current/configuring-ssl.html
[Added] Trace Server now supports https
Change-Id: I09f48e3a4916ec3fd642a78c3b1922a7ce0b7cec
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/168623
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
diff --git a/README.md b/README.md
index 1a24cf7..1242a17 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,23 @@
-Eclipse Trace Compass Incubator
-===============================
+# Eclipse Trace Compass Incubator
This source tree contains the source code for Trace Compass Incubator plugins.
-Project rules and guidelines
-----------------------------
+For information on running the Trace Compass Trace Server, refer to the [README](trace-server/README.md) in the [trace-server](trace-server) directory.
+
+## Table of Contents
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+
+
+- [Project rules and guidelines](#project-rules-and-guidelines)
+- [Setting up the development environment](#setting-up-the-development-environment)
+- [Compiling manually](#compiling-manually)
+- [Maven profiles and properties](#maven-profiles-and-properties)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+## Project rules and guidelines
This project is an incubator which aims at rapid availability of new features and prototypes, to provide new functionnalities to end users and get feedback from them during the development process. As such, code style and design architecture will not be looked at too much during reviews, though some advices and ideas can be discussed. The features have to work as expected though and not break anything in Trace Compass.
@@ -16,8 +29,7 @@
When the code base of some feature gets more stable and mature, it may be ported to the main Trace Compass repository and only then will there be thorough code review and design discussion.
-Setting up the development environment
---------------------------------------
+## Setting up the development environment
To set up the environment to build Trace Compass from within Eclipse, see this
wiki page:
@@ -25,8 +37,7 @@
Once the Trace Compass environment set, import the projects from this repository.
-Compiling manually
-------------------
+## Compiling manually
The Maven project build requires version 3.3 or later. It can be downloaded from
<http://maven.apache.org> or from the package management system of your distro.
@@ -55,8 +66,7 @@
The javadoc html files will be under `target/site/apidocs`.
-Maven profiles and properties
------------------------------
+## Maven profiles and properties
The following Maven profiles and properties are defined in
the build system. You can set them by using `-P[profile name]` and
diff --git a/trace-server/README b/trace-server/README
deleted file mode 100644
index 5f10b17..0000000
--- a/trace-server/README
+++ /dev/null
@@ -1,76 +0,0 @@
-Eclipse Trace Compass Server
-============================
-
-Compiling manually
-------------------
-mvn clean install
-
-Running the server
-------------------
-cd trace-server/org.eclipse.tracecompass.incubator.trace.server.product/target/products/traceserver/linux/gtk/x86_64/trace-compass-server/
-./tracecompss-server
-
-OpenAPI REST specification:
-The REST API is documented using the OpenAPI specification in the API.json file.
-The file can be opened with an IDE plug-in, or Swagger tools.
-For more information, see https://swagger.io/docs/.
-
-Example REST Commands
----------------------
-* Open a trace
-
-curl -X POST \
- http://localhost:8080/tracecompass/traces \
- -H 'accept: application/json' \
- -H 'cache-control: no-cache' \
- -H 'content-type: application/x-www-form-urlencoded' \
- -d 'name=trace2&path=/home/user/git/tracecompass-test-traces/ctf/src/main//resources/trace2'
-
-* Getting list of traces
-
-curl -X GET \
- http://localhost:8080/tracecompass/traces \
- -H 'accept: application/json' \
- -H 'cache-control: no-cache'
-
-* Getting events (events table)
-
-curl -X GET \
- 'http://localhost:8080/tracecompass/eventTable?name=trace2&low=10000&size=20' \
- -H 'accept: application/json' \
- -H 'cache-control: no-cache' \
- -H 'content-type: application/x-www-form-urlencoded'
-
-* Getting Filtered events
-
-curl -X PUT \
- 'http://localhost:8080/tracecompass/eventTable?name=trace2&low=0&size=20' \
- -H 'accept: application/json' \
- -H 'cache-control: no-cache' \
- -H 'content-type: application/x-www-form-urlencoded' \
- -d 'Contents=ret.*'
-
-* Start DiskIOAnalsis
-
-curl -X POST \
- 'http://localhost:8080/tracecompass/DiskActivityView?name=trace2' \
- -H 'accept: application/json' \
- -H 'cache-control: no-cache' \
- -H 'content-type: application/x-www-form-urlencoded'
-
-* Get Disk IO Analysis
-
-curl -X GET \
- http://localhost:8080/tracecompass/DiskActivityView \
- -H 'accept: application/json' \
- -H 'cache-control: no-cache'
-
-
-* Get XY View data for Disk IO Analysis
-
-curl -X GET \
- 'http://localhost:8080/tracecompass/DiskActivityView/trace2?start=1331668247314038062&end=1331668247324038062&resolution=275520' \
- -H 'accept: application/json' \
- -H 'cache-control: no-cache' \
- -H 'content-type: application/x-www-form-urlencoded'
-
diff --git a/trace-server/README.md b/trace-server/README.md
new file mode 100644
index 0000000..55b3a11
--- /dev/null
+++ b/trace-server/README.md
@@ -0,0 +1,52 @@
+# Eclipse Trace Compass Server
+
+## Table of Contents
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+
+
+- [Compiling manually](#compiling-manually)
+- [Running the server](#running-the-server)
+- [Run the Server with SSL](#run-the-server-with-ssl)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+## Compiling manually
+
+`mvn clean install`
+
+## Running the server
+
+```
+$ cd trace-server/org.eclipse.tracecompass.incubator.trace.server.product/target/products/traceserver/linux/gtk/x86_64/trace-compass-server/
+$ ./tracecompss-server`
+```
+
+This server is an implementation of the [Trace Server Protocol](https://github.com/theia-ide/trace-server-protocol) whose [API is documented](https://theia-ide.github.io/trace-server-protocol/) using the OpenAPI REST specification.
+
+OpenAPI REST specification:
+The REST API is documented using the OpenAPI specification in the API.json file.
+The file can be opened with an IDE plug-in, or Swagger tools.
+For more information, see [https://swagger.io/docs/](https://swagger.io/docs/).
+
+## Run the Server with SSL
+
+The trace server can be run using SSL certificates. Jetty requires the certificate and private key to be in a keystore. Follow the instructions to [configure SSL on jetty](https://www.eclipse.org/jetty/documentation/current/configuring-ssl.html).
+
+Then, you can edit the `tracecompass-server.ini` file to pass the keystore data and SSL port as parameters after the -vmargs line. For example, here's a extract of the file:
+
+```
+[...]
+-vmargs
+[...]
+-Dtraceserver.port=8443
+-Dtraceserver.keystore=/path/to/keystore
+```
+
+The following properties are supported:
+
+* `traceserver.port`: Port to use. If not specified, the default http port is 8080 and SSL is 8443
+* `traceserver.useSSL`: Should be `true` or `false`. If `true`, the `traceserver.keystore` property must be set. If left unset, it will be inferred from the other properties. If `false`, the `traceserver.keystore` and `traceserver.keystorepass` will be ignored.
+* `traceserver.keystore`: Path to the keystore file.
+* `traceserver.keystorepass`: Password to open the keystore file. If left unset, the password will be prompted when running the trace server application.
\ No newline at end of file
diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/RestServerTest.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/RestServerTest.java
index 6adf0bb..73cead2 100644
--- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/RestServerTest.java
+++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/RestServerTest.java
@@ -31,6 +31,7 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.QueryParameters;
+import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp.TraceServerConfiguration;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp.WebApplication;
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.DataProviderDescriptorStub;
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.ExperimentModelStub;
@@ -53,7 +54,7 @@
*/
public abstract class RestServerTest {
private static final String SERVER = "http://localhost:8378/tsp/api"; //$NON-NLS-1$
- private static final WebApplication fWebApp = new WebApplication(WebApplication.TEST_PORT);
+ private static final WebApplication fWebApp = new WebApplication(new TraceServerConfiguration(TraceServerConfiguration.TEST_PORT, false, null, null));
/**
* Traces endpoint path (relative to application).
*/
diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/TraceServerConfigurationTest.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/TraceServerConfigurationTest.java
new file mode 100644
index 0000000..f8ea946
--- /dev/null
+++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/TraceServerConfigurationTest.java
@@ -0,0 +1,138 @@
+/**********************************************************************
+ * Copyright (c) 2020 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License 2.0 which
+ * accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ **********************************************************************/
+package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp.TraceServerConfiguration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test the {@link TraceServerConfiguration} class
+ *
+ * @author Geneviève Bastien
+ */
+public class TraceServerConfigurationTest {
+
+ private static final String PROPERTY_PORT = "traceserver.port"; //$NON-NLS-1$
+ private static final String PROPERTY_USESSL = "traceserver.useSSL"; //$NON-NLS-1$
+ private static final String PROPERTY_KEYSTORE = "traceserver.keystore"; //$NON-NLS-1$
+ private static final String PROPERTY_KEYSTORE_PASS = "traceserver.keystorepass"; //$NON-NLS-1$
+
+ /**
+ * Reset all properties at the end of the test
+ */
+ @Before
+ public void initializeProperties() {
+ System.setProperty(PROPERTY_PORT, "");
+ System.setProperty(PROPERTY_USESSL, "");
+ System.setProperty(PROPERTY_KEYSTORE, "");
+ System.setProperty(PROPERTY_KEYSTORE_PASS, "");
+ }
+
+ /**
+ * Reset all properties at the end of the test
+ */
+ @After
+ public void cleanUpProperties() {
+ System.setProperty(PROPERTY_PORT, "");
+ System.setProperty(PROPERTY_USESSL, "");
+ System.setProperty(PROPERTY_KEYSTORE, "");
+ System.setProperty(PROPERTY_KEYSTORE_PASS, "");
+ }
+
+ /**
+ * Test the default configuration
+ */
+ @Test
+ public void testDefaultHttp() {
+ assertConfiguration(new TraceServerConfiguration(8080, false, null, null), TraceServerConfiguration.create());
+ }
+
+ /**
+ * Test setting the http port
+ */
+ @Test
+ public void testHttp() {
+ int port = 8088;
+ System.setProperty(PROPERTY_PORT, String.valueOf(port));
+ assertConfiguration(new TraceServerConfiguration(port, false, null, null), TraceServerConfiguration.create());
+ }
+
+ /**
+ * Test valid https configurations
+ */
+ @Test
+ public void testHttps() {
+ // Set a keystore path, should use ssl on default port
+ String keystorePath = "/path/to/myfile";
+ System.setProperty(PROPERTY_KEYSTORE, keystorePath);
+ assertConfiguration(new TraceServerConfiguration(8443, true, keystorePath, null), TraceServerConfiguration.create());
+
+ // Set a different ssl port
+ int port = 8444;
+ System.setProperty(PROPERTY_PORT, String.valueOf(port));
+ assertConfiguration(new TraceServerConfiguration(port, true, keystorePath, null), TraceServerConfiguration.create());
+
+ // Add a keystore password
+ String keystorePass = "my password";
+ System.setProperty(PROPERTY_KEYSTORE_PASS, keystorePass);
+ assertConfiguration(new TraceServerConfiguration(port, true, keystorePath, keystorePass), TraceServerConfiguration.create());
+ }
+
+ /**
+ * Test forcing http even with https properties
+ */
+ @Test
+ public void testForceHttp() {
+ // Set a keystore path, should use ssl on default port
+ String keystorePath = "/path/to/myfile";
+ String keystorePass = "my password";
+ int port = 8444;
+ System.setProperty(PROPERTY_KEYSTORE, keystorePath);
+ System.setProperty(PROPERTY_PORT, String.valueOf(port));
+ System.setProperty(PROPERTY_KEYSTORE_PASS, keystorePass);
+ System.setProperty(PROPERTY_USESSL, String.valueOf(false));
+
+ assertConfiguration(new TraceServerConfiguration(port, false, keystorePath, keystorePass), TraceServerConfiguration.create());
+ }
+
+ /**
+ * Test ssl no keystore defaults to http
+ */
+ @Test
+ public void testHttpsNoKeystore() {
+ // Set use SSL, but without a keystore
+ System.setProperty(PROPERTY_USESSL, String.valueOf(true));
+
+ assertConfiguration(new TraceServerConfiguration(8080, false, null, null), TraceServerConfiguration.create());
+ }
+
+ /**
+ * Test invalid port
+ */
+ @Test
+ public void testInvalidPort() {
+ System.setProperty(PROPERTY_PORT, "not a number");
+ assertConfiguration(new TraceServerConfiguration(8080, false, null, null), TraceServerConfiguration.create());
+ }
+
+ private static void assertConfiguration(TraceServerConfiguration expected, TraceServerConfiguration actual) {
+ assertEquals(expected.getPort(), actual.getPort());
+ assertEquals(expected.getKeystore(), actual.getKeystore());
+ assertEquals(expected.getKeystorePass(), actual.getKeystorePass());
+ assertEquals(expected.useSSL(), actual.useSSL());
+
+ }
+
+}
diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/META-INF/MANIFEST.MF b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/META-INF/MANIFEST.MF
index 13ba52c..f23d8b0 100644
--- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/META-INF/MANIFEST.MF
+++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/META-INF/MANIFEST.MF
@@ -39,7 +39,8 @@
javax.xml.bind,
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional,
org.eclipse.tracecompass.tmf.analysis.xml.core
-Import-Package: com.google.common.base,
+Import-Package: com.google.common.annotations,
+ com.google.common.base,
com.google.common.collect,
com.google.common.primitives,
org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module,
diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/TraceServerConfiguration.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/TraceServerConfiguration.java
new file mode 100644
index 0000000..0f93f42
--- /dev/null
+++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/TraceServerConfiguration.java
@@ -0,0 +1,135 @@
+/**********************************************************************
+ * Copyright (c) 2020 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License 2.0 which
+ * accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ **********************************************************************/
+package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.Activator;
+
+/**
+ * Class that centralizes getting the configuration for the Trace Compass server
+ * and default values
+ *
+ * @author Geneviève Bastien
+ */
+public class TraceServerConfiguration {
+
+ /**
+ * Port value which boots the server in testing mode.
+ */
+ public static final int TEST_PORT = 8378;
+ private static final String PROPERTY_PORT = "traceserver.port"; //$NON-NLS-1$
+ private static final String PROPERTY_USESSL = "traceserver.useSSL"; //$NON-NLS-1$
+ private static final String PROPERTY_KEYSTORE = "traceserver.keystore"; //$NON-NLS-1$
+ private static final String PROPERTY_KEYSTORE_PASS = "traceserver.keystorepass"; //$NON-NLS-1$
+ private static final int DEFAULT_HTTP_PORT = 8080;
+ private static final int DEFAULT_SSL_PORT = 8443;
+
+ private final int fPort;
+ private final boolean fUseSSL;
+ private final @Nullable String fKeystore;
+ private final @Nullable String fKeystorePass;
+
+ /**
+ * Create the trace server configuration
+ *
+ * @return The trace server configuration
+ */
+ public static TraceServerConfiguration create() {
+ String portStr = System.getProperty(PROPERTY_PORT);
+ String usesslStr = System.getProperty(PROPERTY_USESSL);
+ usesslStr = usesslStr == null || usesslStr.isEmpty() ? null : usesslStr;
+ String keystore = System.getProperty(PROPERTY_KEYSTORE);
+ keystore = keystore == null || keystore.isEmpty() ? null : keystore;
+ String keystorePass = System.getProperty(PROPERTY_KEYSTORE_PASS);
+ keystorePass = keystorePass == null || keystorePass.isEmpty() ? null : keystorePass;
+ boolean useSSL = (usesslStr != null && !"false".equals(usesslStr)) ? true : false; //$NON-NLS-1$
+ if (keystore != null && usesslStr == null) {
+ useSSL = true;
+ } else if (useSSL) {
+ Activator.getInstance().logError(String.format("Server requested to use SSL, but no keystore specified. You must specify the keystore using the '%s' system property. Will use plain http instead.", PROPERTY_KEYSTORE)); //$NON-NLS-1$
+ useSSL = false;
+ }
+ int port = useSSL ? DEFAULT_SSL_PORT : DEFAULT_HTTP_PORT;
+ if (portStr != null && !portStr.isEmpty()) {
+ try {
+ port = Integer.parseInt(portStr);
+ } catch (NumberFormatException e) {
+ // Log an exception
+ Activator.getInstance().logWarning(String.format("Invalid port specified: %s. Will use default port %d", portStr, port)); //$NON-NLS-1$
+ }
+ }
+ return new TraceServerConfiguration(port, useSSL, keystore, keystorePass);
+ }
+
+ /**
+ * Constructor. Use only for unit tests, other use the {@link #create()} to
+ * automatically get the configuration parameters
+ *
+ * @param keystorePass
+ * The keystore password
+ * @param keystore
+ * The path to the SSL keystore
+ * @param useSSL
+ * Whether to use SSL
+ * @param port
+ * The port to use
+ */
+ @VisibleForTesting
+ public TraceServerConfiguration(int port, boolean useSSL, @Nullable String keystore, @Nullable String keystorePass) {
+ fPort = port;
+ fUseSSL = useSSL;
+ fKeystore = keystore;
+ fKeystorePass = keystorePass;
+ }
+
+ /**
+ * Get the port on which the server will run. The port can be specified
+ * using the system property {@link #PROPERTY_PORT}
+ *
+ * @return The port number
+ */
+ public int getPort() {
+ return fPort;
+ }
+
+ /**
+ * Get whether the server should use SSL
+ *
+ * @return if <code>true</code>, the server will use SSL
+ */
+ public boolean useSSL() {
+ return fUseSSL;
+ }
+
+ /**
+ * Get the keystore for SSL configuration. SSL keystore and certificates can
+ * be configured as per the jetty documentation
+ *
+ * @see <a href=
+ * "https://www.eclipse.org/jetty/documentation/current/configuring-ssl.html">https://www.eclipse.org/jetty/documentation/current/configuring-ssl.html</a>
+ *
+ * @return The path to the keystore
+ */
+ public @Nullable String getKeystore() {
+ return fKeystore;
+ }
+
+ /**
+ * Get the keystore password
+ *
+ * @return The keystore password
+ */
+ public @Nullable String getKeystorePass() {
+ return fKeystorePass;
+ }
+
+}
diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/WebApplication.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/WebApplication.java
index 2591e31..b7e6e4a 100644
--- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/WebApplication.java
+++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/WebApplication.java
@@ -14,9 +14,15 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jetty.http.HttpVersion;
+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.server.SslConnectionFactory;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.DataProviderService;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.ExperimentManagerService;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.FilterService;
@@ -47,30 +53,25 @@
private static final String CONTEXT_PATH = "/tsp/api"; //$NON-NLS-1$
private static final String PATH_SPEC = "/*"; //$NON-NLS-1$
- /**
- * Port value which boots the server in testing mode.
- */
- public static final int TEST_PORT = 8378;
-
- private int fPort;
private Server fServer;
+ private final TraceServerConfiguration fConfig;
/**
* Default Constructor
*/
public WebApplication() {
- this(8080);
+ this(TraceServerConfiguration.create());
}
/**
- * Constructor to to provide different port for server
+ * Constructor to provide a configuration to the server
*
- * @param port
- * the port to use
+ * @param config
+ * Server configuration
*/
- public WebApplication(int port) {
- fPort = port;
+ public WebApplication(TraceServerConfiguration config) {
+ fConfig = config;
}
/**
@@ -97,7 +98,12 @@
ServletHolder holder = new ServletHolder(sc);
sch.addServlet(holder, PATH_SPEC);
- fServer = new Server(fPort);
+ fServer = new Server();
+ // https://www.programcreek.com/java-api-examples/?api=org.eclipse.jetty.server.SslConnectionFactory
+
+ @SuppressWarnings("resource")
+ ServerConnector connector = getConnector(fServer, fConfig);
+ fServer.addConnector(connector);
fServer.setHandler(sch);
// create and open a default eclipse project.
@@ -122,11 +128,37 @@
}
fServer.start();
- if (fPort != TEST_PORT) {
+ if (fConfig.getPort() != TraceServerConfiguration.TEST_PORT) {
fServer.join();
}
}
+ private static ServerConnector getConnector(Server server, TraceServerConfiguration config) {
+ ServerConnector serverConnector = null;
+ if (config.useSSL()) {
+
+ SslContextFactory contextFactory = new SslContextFactory.Server();
+ contextFactory.setKeyStorePath(config.getKeystore());
+ contextFactory.setKeyStorePassword(config.getKeystorePass());
+ contextFactory.setTrustAll(true);
+
+ HttpConfiguration httpsConfig = new HttpConfiguration();
+ httpsConfig.setSecureScheme("https"); //$NON-NLS-1$
+ httpsConfig.setOutputBufferSize(32768);
+ httpsConfig.setRequestHeaderSize(8192 * 2);
+ httpsConfig.setResponseHeaderSize(8192 * 2);
+ httpsConfig.setSendServerVersion(true);
+ httpsConfig.setSendDateHeader(false);
+
+ SslConnectionFactory connector = new SslConnectionFactory(contextFactory, HttpVersion.HTTP_1_1.asString());
+ serverConnector = new ServerConnector(server, connector, new HttpConnectionFactory(httpsConfig));
+ } else {
+ serverConnector = new ServerConnector(server);
+ }
+ serverConnector.setPort(config.getPort());
+ return serverConnector;
+ }
+
private static JacksonJaxbJsonProvider registerCustomMappers() {
ObjectMapper mapper = new ObjectMapper();