Browse Source

Update undertow dependencies, code cleanup (#3288)

Michael Hixson 7 years ago
parent
commit
be9aef3ef7

+ 38 - 0
frameworks/Java/undertow/maven-version-rules.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ruleset comparisonMethod="maven"
+         xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
+
+  <rules>
+
+    <rule groupId="io.undertow" artifactId="undertow-core">
+      <ignoreVersions>
+        <ignoreVersion type="regex">.+\.Alpha[\d]+</ignoreVersion>
+        <ignoreVersion type="regex">.+\.Beta[\d]+</ignoreVersion>
+      </ignoreVersions>
+    </rule>
+
+    <rule groupId="com.fasterxml.jackson.*">
+      <ignoreVersions>
+        <ignoreVersion type="regex">.+\.pr[\d]+</ignoreVersion>
+      </ignoreVersions>
+    </rule>
+
+    <rule groupId="org.postgresql" artifactId="postgresql">
+      <ignoreVersions>
+        <ignoreVersion type="regex">.+\.jre6</ignoreVersion>
+        <ignoreVersion type="regex">.+\.jre7</ignoreVersion>
+      </ignoreVersions>
+    </rule>
+
+    <rule groupId="mysql" artifactId="mysql-connector-java">
+      <ignoreVersions>
+        <ignoreVersion type="regex">6\..*</ignoreVersion>
+        <ignoreVersion type="regex">8\..*</ignoreVersion>
+      </ignoreVersions>
+    </rule>
+
+  </rules>
+
+</ruleset>

+ 30 - 21
frameworks/Java/undertow/pom.xml

@@ -10,17 +10,18 @@
   <version>1.0-SNAPSHOT</version>
 
   <properties>
-    <maven.compiler.source>1.8</maven.compiler.source>
-    <maven.compiler.target>1.8</maven.compiler.target>
+    <maven.compiler.source>9</maven.compiler.source>
+    <maven.compiler.target>9</maven.compiler.target>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    <version.hikaricp>2.7.4</version.hikaricp>
-    <version.jackson>2.9.2</version.jackson>
-    <version.maven-shade-plugin>3.1.0</version.maven-shade-plugin>
-    <version.mongodb>3.6.0</version.mongodb>
-    <version.mustache>0.9.5</version.mustache>
-    <version.mysql>5.1.45</version.mysql>
-    <version.postgresql>42.1.4</version.postgresql>
-    <version.undertow>1.4.21.Final</version.undertow>
+    <hikaricp.version>2.7.7</hikaricp.version>
+    <jackson.version>2.9.4</jackson.version>
+    <maven-shade-plugin.version>3.1.0</maven-shade-plugin.version>
+    <mongodb.version>3.6.3</mongodb.version>
+    <mustache.version>0.9.5</mustache.version>
+    <mysql.version>5.1.45</mysql.version>
+    <postgresql.version>42.2.1</postgresql.version>
+    <undertow.version>1.4.22.Final</undertow.version>
+    <versions-maven-plugin.version>2.4</versions-maven-plugin.version>
   </properties>
 
   <prerequisites>
@@ -31,62 +32,70 @@
     <dependency>
       <groupId>io.undertow</groupId>
       <artifactId>undertow-core</artifactId>
-      <version>${version.undertow}</version>
+      <version>${undertow.version}</version>
     </dependency>
     <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
-      <version>${version.mysql}</version>
+      <version>${mysql.version}</version>
     </dependency>
     <dependency>
       <groupId>org.postgresql</groupId>
       <artifactId>postgresql</artifactId>
-      <version>${version.postgresql}</version>
+      <version>${postgresql.version}</version>
     </dependency>
     <dependency>
       <groupId>org.mongodb</groupId>
       <artifactId>mongodb-driver</artifactId>
-      <version>${version.mongodb}</version>
+      <version>${mongodb.version}</version>
     </dependency>
     <dependency>
       <groupId>org.mongodb</groupId>
       <artifactId>mongodb-driver-core</artifactId>
-      <version>${version.mongodb}</version>
+      <version>${mongodb.version}</version>
     </dependency>
     <dependency>
       <groupId>org.mongodb</groupId>
       <artifactId>mongodb-driver-async</artifactId>
-      <version>${version.mongodb}</version>
+      <version>${mongodb.version}</version>
     </dependency>
     <dependency>
       <groupId>org.mongodb</groupId>
       <artifactId>bson</artifactId>
-      <version>${version.mongodb}</version>
+      <version>${mongodb.version}</version>
     </dependency>
     <dependency>
       <groupId>com.zaxxer</groupId>
       <artifactId>HikariCP</artifactId>
-      <version>${version.hikaricp}</version>
+      <version>${hikaricp.version}</version>
     </dependency>
     <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-databind</artifactId>
-      <version>${version.jackson}</version>
+      <version>${jackson.version}</version>
     </dependency>
     <dependency>
       <groupId>com.github.spullara.mustache.java</groupId>
       <artifactId>compiler</artifactId>
-      <version>${version.mustache}</version>
+      <version>${mustache.version}</version>
     </dependency>
   </dependencies>
 
   <build>
     <finalName>hello-undertow</finalName>
     <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>versions-maven-plugin</artifactId>
+        <version>${versions-maven-plugin.version}</version>
+        <configuration>
+          <rulesUri>file://${basedir}/maven-version-rules.xml</rulesUri>
+        </configuration>
+      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
-        <version>${version.maven-shade-plugin}</version>
+        <version>${maven-shade-plugin.version}</version>
         <configuration>
           <createDependencyReducedPom>false</createDependencyReducedPom>
           <filters>

+ 36 - 36
frameworks/Java/undertow/src/main/java/hello/HelloWebServer.java

@@ -18,7 +18,7 @@ import io.undertow.server.handlers.BlockingHandler;
 import io.undertow.server.handlers.PathHandler;
 import io.undertow.server.handlers.SetHeaderHandler;
 import java.io.InputStream;
-import java.util.Collections;
+import java.util.List;
 import java.util.Properties;
 import javax.sql.DataSource;
 
@@ -31,18 +31,18 @@ public final class HelloWebServer {
   }
 
   public static void main(String[] args) throws Exception {
-    Mode mode = Mode.valueOf(args[0]);
-    Properties props = new Properties();
+    ServerMode serverMode = ServerMode.valueOf(args[0]);
+    Properties config = new Properties();
     try (InputStream in =
              Thread.currentThread()
                    .getContextClassLoader()
                    .getResourceAsStream("hello/server.properties")) {
-      props.load(in);
+      config.load(in);
     }
-    int port = Integer.parseInt(props.getProperty("undertow.port"));
-    String host = props.getProperty("undertow.host");
-    HttpHandler paths = mode.paths(props);
-    HttpHandler rootHandler = new SetHeaderHandler(paths, "Server", "U-tow");
+    int port = Integer.parseInt(config.getProperty("undertow.port"));
+    String host = config.getProperty("undertow.host");
+    HttpHandler pathHandler = serverMode.newPathHandler(config);
+    HttpHandler rootHandler = new SetHeaderHandler(pathHandler, "Server", "U-tow");
     Undertow.builder()
             .addHttpListener(port, host)
             // In HTTP/1.1, connections are persistent unless declared
@@ -54,14 +54,14 @@ public final class HelloWebServer {
             .start();
   }
 
-  enum Mode {
+  enum ServerMode {
     /**
      * The server will only implement the test types that do not require a
      * database.
      */
-    NO_DATABASE() {
+    NO_DATABASE {
       @Override
-      HttpHandler paths(Properties props) {
+      HttpHandler newPathHandler(Properties config) {
         return new PathHandler()
             .addExactPath("/plaintext", new PlaintextHandler())
             .addExactPath("/json",      new JsonHandler());
@@ -72,13 +72,13 @@ public final class HelloWebServer {
      * The server will use a MySQL database and will only implement the test
      * types that require a database.
      */
-    MYSQL() {
+    MYSQL {
       @Override
-      HttpHandler paths(Properties props) {
-        String jdbcUrl = props.getProperty("mysql.jdbcUrl");
-        String username = props.getProperty("mysql.username");
-        String password = props.getProperty("mysql.password");
-        int connections = Integer.parseInt(props.getProperty("mysql.connections"));
+      HttpHandler newPathHandler(Properties config) {
+        String jdbcUrl = config.getProperty("mysql.jdbcUrl");
+        String username = config.getProperty("mysql.username");
+        String password = config.getProperty("mysql.password");
+        int connections = Integer.parseInt(config.getProperty("mysql.connections"));
         DataSource db = newSqlDataSource(jdbcUrl, username, password, connections);
         return new PathHandler()
             .addExactPath("/db",       new BlockingHandler(new DbSqlHandler(db)))
@@ -92,13 +92,13 @@ public final class HelloWebServer {
      * The server will use a PostgreSQL database and will only implement the
      * test types that require a database.
      */
-    POSTGRESQL() {
+    POSTGRESQL {
       @Override
-      HttpHandler paths(Properties props) {
-        String jdbcUrl = props.getProperty("postgresql.jdbcUrl");
-        String username = props.getProperty("postgresql.username");
-        String password = props.getProperty("postgresql.password");
-        int connections = Integer.parseInt(props.getProperty("postgresql.connections"));
+      HttpHandler newPathHandler(Properties config) {
+        String jdbcUrl = config.getProperty("postgresql.jdbcUrl");
+        String username = config.getProperty("postgresql.username");
+        String password = config.getProperty("postgresql.password");
+        int connections = Integer.parseInt(config.getProperty("postgresql.connections"));
         DataSource db = newSqlDataSource(jdbcUrl, username, password, connections);
         return new PathHandler()
             .addExactPath("/db",       new BlockingHandler(new DbSqlHandler(db)))
@@ -112,12 +112,12 @@ public final class HelloWebServer {
      * The server will use a MongoDB database and will only implement the test
      * types that require a database.
      */
-    MONGODB() {
+    MONGODB {
       @Override
-      HttpHandler paths(Properties props) {
-        String host = props.getProperty("mongodb.host");
-        String databaseName = props.getProperty("mongodb.databaseName");
-        int connections = Integer.parseInt(props.getProperty("mongodb.connections"));
+      HttpHandler newPathHandler(Properties config) {
+        String host = config.getProperty("mongodb.host");
+        String databaseName = config.getProperty("mongodb.databaseName");
+        int connections = Integer.parseInt(config.getProperty("mongodb.connections"));
         MongoDatabase db = newMongoDatabase(host, databaseName, connections);
         return new PathHandler()
             .addExactPath("/db",       new BlockingHandler(new DbMongoHandler(db)))
@@ -131,12 +131,12 @@ public final class HelloWebServer {
      * The server will use a MongoDB database with an asynchronous API and will
      * only implement the test types that require a database.
      */
-    MONGODB_ASYNC() {
+    MONGODB_ASYNC {
       @Override
-      HttpHandler paths(Properties props) {
-        String host = props.getProperty("mongodb.host");
-        String databaseName = props.getProperty("mongodb.databaseName");
-        int connections = Integer.parseInt(props.getProperty("mongodb.connections"));
+      HttpHandler newPathHandler(Properties config) {
+        String host = config.getProperty("mongodb.host");
+        String databaseName = config.getProperty("mongodb.databaseName");
+        int connections = Integer.parseInt(config.getProperty("mongodb.connections"));
         com.mongodb.async.client.MongoDatabase db =
             newMongoDatabaseAsync(host, databaseName, connections);
         return new PathHandler()
@@ -151,9 +151,9 @@ public final class HelloWebServer {
      * Returns an HTTP handler that provides routing for all the
      * test-type-specific endpoints of the server.
      *
-     * @param props the server configuration
+     * @param config the server configuration
      */
-    abstract HttpHandler paths(Properties props);
+    abstract HttpHandler newPathHandler(Properties config);
 
     /**
      * Provides a source of connections to a SQL database.
@@ -196,7 +196,7 @@ public final class HelloWebServer {
           ClusterSettings
               .builder()
               .mode(ClusterConnectionMode.SINGLE)
-              .hosts(Collections.singletonList(new ServerAddress(host)))
+              .hosts(List.of(new ServerAddress(host)))
               .build();
       ConnectionPoolSettings connectionPoolSettings =
           ConnectionPoolSettings

+ 1 - 3
frameworks/Java/undertow/src/main/java/hello/JsonHandler.java

@@ -4,7 +4,6 @@ import static hello.Helper.sendJson;
 
 import io.undertow.server.HttpHandler;
 import io.undertow.server.HttpServerExchange;
-import java.util.Collections;
 import java.util.Map;
 
 /**
@@ -13,8 +12,7 @@ import java.util.Map;
 final class JsonHandler implements HttpHandler {
   @Override
   public void handleRequest(HttpServerExchange exchange) {
-    Map<String, String> value =
-        Collections.singletonMap("message", "Hello, World!");
+    Map<String, String> value = Map.of("message", "Hello, World!");
     sendJson(exchange, value);
   }
 }