http-client-branch: Enable HTTP/1.1 server logging in DigestEchoClient.java http-client-branch
authordfuchs
Wed, 07 Mar 2018 15:39:25 +0000
branchhttp-client-branch
changeset 56262 d818a6a8295a
parent 56261 a339fe1aab55
child 56263 4933a477d628
http-client-branch: Enable HTTP/1.1 server logging in DigestEchoClient.java
src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java
test/jdk/java/net/httpclient/DigestEchoClient.java
test/jdk/java/net/httpclient/HttpServerAdapters.java
--- a/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java	Wed Mar 07 14:55:53 2018 +0000
+++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java	Wed Mar 07 15:39:25 2018 +0000
@@ -527,7 +527,7 @@
                     if (https) {
                         if (sslContext == null) {
                             logger.log (Level.WARNING,
-                                "SSL connection received. No https contxt created");
+                                "SSL connection received. No https context created");
                             throw new HttpError ("No SSL context established");
                         }
                         sslStreams = new SSLStreams (ServerImpl.this, sslContext, chan);
--- a/test/jdk/java/net/httpclient/DigestEchoClient.java	Wed Mar 07 14:55:53 2018 +0000
+++ b/test/jdk/java/net/httpclient/DigestEchoClient.java	Wed Mar 07 15:39:25 2018 +0000
@@ -244,6 +244,7 @@
     }
 
     public static void main(String[] args) throws Exception {
+        HttpServerAdapters.enableServerLogging();
         boolean useSSL = false;
         EnumSet<DigestEchoServer.HttpAuthType> types =
                 EnumSet.complementOf(EnumSet.of(DigestEchoServer.HttpAuthType.PROXY305));
--- a/test/jdk/java/net/httpclient/HttpServerAdapters.java	Wed Mar 07 14:55:53 2018 +0000
+++ b/test/jdk/java/net/httpclient/HttpServerAdapters.java	Wed Mar 07 15:39:25 2018 +0000
@@ -44,6 +44,9 @@
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Stream;
 
 /**
  * Defines an adaptation layers so that a test server handlers and filters
@@ -433,6 +436,15 @@
      * A version agnostic adapter class for HTTP Servers.
      */
     public static abstract class HttpTestServer {
+        private static final class ServerLogging {
+            private static final Logger logger = Logger.getLogger("com.sun.net.httpserver");
+            static void enableLogging() {
+                logger.setLevel(Level.FINE);
+                Stream.of(Logger.getLogger("").getHandlers())
+                        .forEach(h -> h.setLevel(Level.ALL));
+            }
+        }
+
         public abstract void start();
         public abstract void stop();
         public abstract HttpTestContext addHandler(HttpTestHandler handler, String root);
@@ -549,4 +561,10 @@
         }
     }
 
+    public static void enableServerLogging() {
+        System.setProperty("java.util.logging.SimpleFormatter.format",
+                "%4$s [%1$tb %1$td, %1$tl:%1$tM:%1$tS.%1$tN] %2$s: %5$s%6$s%n");
+        HttpTestServer.ServerLogging.enableLogging();
+    }
+
 }