aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-04-04 15:38:42 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-04-04 15:38:42 -0700
commit7bea8d52acd3d9cd1fa9502229cc38faac6cf7bc (patch)
tree1f64a6ddf0d187a1f932aff93cd8ed8ea9582cef
parent92dc10c476141c4c524c07d6625009a8c6071c87 (diff)
downloadtrackermap-server-7bea8d52acd3d9cd1fa9502229cc38faac6cf7bc.tar.gz
trackermap-server-7bea8d52acd3d9cd1fa9502229cc38faac6cf7bc.tar.bz2
trackermap-server-7bea8d52acd3d9cd1fa9502229cc38faac6cf7bc.zip
Upgrade Jetty web server
-rw-r--r--build.gradle6
-rw-r--r--src/main/java/org/traccar/api/AsyncSocketServlet.java17
-rw-r--r--src/main/java/org/traccar/web/WebServer.java2
3 files changed, 15 insertions, 10 deletions
diff --git a/build.gradle b/build.gradle
index 20f329a45..f4649e10e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -11,7 +11,7 @@ repositories {
ext {
guiceVersion = "4.2.3"
- jettyVersion = "9.4.36.v20210114" // jetty 10 requires java 11, jetty 11 javax to jakarta
+ jettyVersion = "10.0.2" // jetty 11 javax to jakarta
jerseyVersion = "2.33" // jersey 3 javax to jakarta
jacksonVersion = "2.12.1" // same version as jersey-media-json-jackson dependency
protobufVersion = "3.14.0"
@@ -48,7 +48,7 @@ dependencies {
implementation "com.microsoft.sqlserver:mssql-jdbc:9.2.0.jre8"
implementation "com.zaxxer:HikariCP:4.0.1"
implementation "io.netty:netty-all:4.1.58.Final"
- implementation "org.slf4j:slf4j-jdk14:1.7.30"
+ implementation "org.slf4j:slf4j-jdk14:2.0.0-alpha1"
implementation "com.google.inject:guice:$guiceVersion"
implementation "com.google.inject.extensions:guice-assistedinject:$guiceVersion"
implementation "org.owasp.encoder:encoder:1.2.3"
@@ -58,7 +58,7 @@ dependencies {
implementation "org.eclipse.jetty:jetty-webapp:$jettyVersion"
implementation "org.eclipse.jetty:jetty-jndi:$jettyVersion"
implementation "org.eclipse.jetty:jetty-proxy:$jettyVersion"
- implementation "org.eclipse.jetty.websocket:websocket-server:$jettyVersion" // websocket-jetty-server from jetty 10
+ implementation "org.eclipse.jetty.websocket:websocket-jetty-server:$jettyVersion"
implementation "org.glassfish.jersey.containers:jersey-container-servlet:$jerseyVersion"
implementation "org.glassfish.jersey.media:jersey-media-json-jackson:$jerseyVersion"
implementation "org.glassfish.jersey.inject:jersey-hk2:$jerseyVersion"
diff --git a/src/main/java/org/traccar/api/AsyncSocketServlet.java b/src/main/java/org/traccar/api/AsyncSocketServlet.java
index 490fc89fc..a964ead10 100644
--- a/src/main/java/org/traccar/api/AsyncSocketServlet.java
+++ b/src/main/java/org/traccar/api/AsyncSocketServlet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2021 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,20 +15,23 @@
*/
package org.traccar.api;
-import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
-import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
+import org.eclipse.jetty.websocket.server.JettyWebSocketServlet;
+import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory;
import org.traccar.Context;
import org.traccar.api.resource.SessionResource;
import org.traccar.config.Keys;
-public class AsyncSocketServlet extends WebSocketServlet {
+import javax.servlet.http.HttpSession;
+import java.time.Duration;
+
+public class AsyncSocketServlet extends JettyWebSocketServlet {
@Override
- public void configure(WebSocketServletFactory factory) {
- factory.getPolicy().setIdleTimeout(Context.getConfig().getLong(Keys.WEB_TIMEOUT));
+ public void configure(JettyWebSocketServletFactory factory) {
+ factory.setIdleTimeout(Duration.ofMillis(Context.getConfig().getLong(Keys.WEB_TIMEOUT)));
factory.setCreator((req, resp) -> {
if (req.getSession() != null) {
- long userId = (Long) req.getSession().getAttribute(SessionResource.USER_ID_KEY);
+ long userId = (Long) ((HttpSession) req.getSession()).getAttribute(SessionResource.USER_ID_KEY);
return new AsyncSocket(userId);
} else {
return null;
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java
index 82e9397e4..ffa06adfd 100644
--- a/src/main/java/org/traccar/web/WebServer.java
+++ b/src/main/java/org/traccar/web/WebServer.java
@@ -29,6 +29,7 @@ import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
@@ -149,6 +150,7 @@ public class WebServer {
private void initApi(Config config, ServletContextHandler servletHandler) {
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/api/socket");
+ JettyWebSocketServletContainerInitializer.configure(servletHandler, null);
String mediaPath = config.getString(Keys.MEDIA_PATH);
if (mediaPath != null) {