Browse Source

Merge pull request #386 from stuartwdouglas/master

Update Undertow version and use non-snapshot version of netty
Michael Hixson 12 years ago
parent
commit
fcec59f2cd

+ 1 - 1
netty/pom.xml

@@ -12,7 +12,7 @@
     <dependency>
     	<groupId>io.netty</groupId>
     	<artifactId>netty-codec-http</artifactId>
-    	<version>4.0.0.CR7-SNAPSHOT</version>
+    	<version>4.0.0.CR7</version>
     </dependency>
 	 <dependency>
 		<groupId>com.fasterxml.jackson.core</groupId>

+ 1 - 1
undertow/pom.xml

@@ -13,7 +13,7 @@
         <dependency>
             <groupId>io.undertow</groupId>
             <artifactId>undertow-core</artifactId>
-            <version>1.0.0.Beta1</version>
+            <version>1.0.0.Beta3</version>
         </dependency>
         <dependency>
             <groupId>org.jboss.xnio</groupId>

+ 3 - 1
undertow/src/main/java/hello/CacheHandler.java

@@ -9,6 +9,8 @@ import io.undertow.util.Headers;
 
 import java.util.Objects;
 
+import static hello.HelloWebServer.JSON_UTF8;
+
 /**
  * Handles the cache access test.
  */
@@ -30,7 +32,7 @@ final class CacheHandler implements HttpHandler {
       worlds[i] = worldCache.get(Helper.randomWorld());
     }
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
+        Headers.CONTENT_TYPE, JSON_UTF8);
     exchange.getResponseSender().send(objectMapper.writeValueAsString(worlds));
   }
 }

+ 3 - 1
undertow/src/main/java/hello/DbMongoHandler.java

@@ -11,6 +11,8 @@ import io.undertow.util.Headers;
 
 import java.util.Objects;
 
+import static hello.HelloWebServer.JSON_UTF8;
+
 /**
  * Handles the single- and multiple-query database tests using MongoDB.
  */
@@ -43,7 +45,7 @@ final class DbMongoHandler implements HttpHandler {
           ((Number) object.get("randomNumber")).intValue());
     }
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
+        Headers.CONTENT_TYPE, JSON_UTF8);
     exchange.getResponseSender().send(objectMapper.writeValueAsString(worlds));
   }
 }

+ 3 - 1
undertow/src/main/java/hello/DbSqlHandler.java

@@ -12,6 +12,8 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.util.Objects;
 
+import static hello.HelloWebServer.JSON_UTF8;
+
 /**
  * Handles the single- and multiple-query database tests using a SQL database.
  */
@@ -48,7 +50,7 @@ final class DbSqlHandler implements HttpHandler {
       }
     }
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
+        Headers.CONTENT_TYPE, JSON_UTF8);
     exchange.getResponseSender().send(objectMapper.writeValueAsString(worlds));
   }
 }

+ 3 - 1
undertow/src/main/java/hello/FortunesMongoHandler.java

@@ -16,6 +16,8 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
+import static hello.HelloWebServer.HTML_UTF8;
+
 /**
  * Handles the fortunes test using MongoDB.
  */
@@ -48,7 +50,7 @@ final class FortunesMongoHandler implements HttpHandler {
     StringWriter writer = new StringWriter();
     mustache.execute(writer, fortunes);
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.HTML_UTF_8.toString());
+        Headers.CONTENT_TYPE, HTML_UTF8);
     exchange.getResponseSender().send(writer.toString());
   }
 }

+ 3 - 1
undertow/src/main/java/hello/FortunesSqlHandler.java

@@ -17,6 +17,8 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
+import static hello.HelloWebServer.HTML_UTF8;
+
 /**
  * Handles the fortunes test using a SQL database.
  */
@@ -54,7 +56,7 @@ final class FortunesSqlHandler implements HttpHandler {
     StringWriter writer = new StringWriter();
     mustache.execute(writer, fortunes);
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.HTML_UTF_8.toString());
+        Headers.CONTENT_TYPE, HTML_UTF8);
     exchange.getResponseSender().send(writer.toString());
   }
 }

+ 9 - 0
undertow/src/main/java/hello/HelloWebServer.java

@@ -6,6 +6,7 @@ import com.github.mustachejava.MustacheFactory;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
+import com.google.common.net.MediaType;
 import com.mongodb.DB;
 import com.mongodb.MongoClient;
 import io.undertow.Handlers;
@@ -34,6 +35,14 @@ import java.util.Properties;
  */
 public final class HelloWebServer {
 
+  //MediaType.toString() does non-trivial work and does not cache the result
+  //so we cache it here
+  public static final String JSON_UTF8 = MediaType.JSON_UTF_8.toString();
+
+  public static final String TEXT_PLAIN = MediaType.PLAIN_TEXT_UTF_8.toString();
+
+  public static final String HTML_UTF8 = MediaType.HTML_UTF_8.toString();
+
   public static void main(String[] args) throws Exception {
     new HelloWebServer();
   }

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

@@ -9,6 +9,8 @@ import io.undertow.util.Headers;
 import java.util.Collections;
 import java.util.Objects;
 
+import static hello.HelloWebServer.JSON_UTF8;
+
 /**
  * Handles the JSON test.
  */
@@ -22,7 +24,7 @@ final class JsonHandler implements HttpHandler {
   @Override
   public void handleRequest(HttpServerExchange exchange) throws Exception {
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
+        Headers.CONTENT_TYPE, JSON_UTF8);
     exchange.getResponseSender().send(
         objectMapper.writeValueAsString(
             Collections.singletonMap("message", "Hello, World!")));

+ 3 - 1
undertow/src/main/java/hello/PlaintextHandler.java

@@ -5,6 +5,8 @@ import io.undertow.server.HttpHandler;
 import io.undertow.server.HttpServerExchange;
 import io.undertow.util.Headers;
 
+import static hello.HelloWebServer.TEXT_PLAIN;
+
 /**
  * Handles the plaintext test.
  */
@@ -12,7 +14,7 @@ final class PlaintextHandler implements HttpHandler {
   @Override
   public void handleRequest(HttpServerExchange exchange) throws Exception {
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8.toString());
+        Headers.CONTENT_TYPE, TEXT_PLAIN);
     exchange.getResponseSender().send("Hello, World!");
   }
 }

+ 3 - 1
undertow/src/main/java/hello/UpdatesMongoHandler.java

@@ -11,6 +11,8 @@ import io.undertow.util.Headers;
 
 import java.util.Objects;
 
+import static hello.HelloWebServer.JSON_UTF8;
+
 /**
  * Handles the updates test using MongoDB.
  */
@@ -48,7 +50,7 @@ final class UpdatesMongoHandler implements HttpHandler {
       worlds[i] = new World(id, newRandomNumber);
     }
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
+        Headers.CONTENT_TYPE, JSON_UTF8);
     exchange.getResponseSender().send(objectMapper.writeValueAsString(worlds));
   }
 }

+ 3 - 1
undertow/src/main/java/hello/UpdatesSqlHandler.java

@@ -12,6 +12,8 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.util.Objects;
 
+import static hello.HelloWebServer.JSON_UTF8;
+
 /**
  * Handles the updates test using a SQL database.
  */
@@ -56,7 +58,7 @@ final class UpdatesSqlHandler implements HttpHandler {
       }
     }
     exchange.getResponseHeaders().put(
-        Headers.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
+        Headers.CONTENT_TYPE, JSON_UTF8);
     exchange.getResponseSender().send(objectMapper.writeValueAsString(worlds));
   }
 }