test/jdk/java/net/httpclient/HttpServerAdapters.java
branchhttp-client-branch
changeset 56209 43d5ad612710
parent 56165 8a6065d830b9
child 56218 fd7bd32963ef
--- a/test/jdk/java/net/httpclient/HttpServerAdapters.java	Tue Feb 27 19:26:25 2018 +0000
+++ b/test/jdk/java/net/httpclient/HttpServerAdapters.java	Wed Feb 28 15:48:46 2018 +0000
@@ -327,6 +327,15 @@
         }
     }
 
+    public static boolean expectException(HttpTestExchange e) {
+        HttpTestHeaders h = e.getRequestHeaders();
+        Optional<String> expectException = h.firstValue("X-expect-exception");
+        if (expectException.isPresent()) {
+            return expectException.get().equalsIgnoreCase("true");
+        }
+        return false;
+    }
+
     /**
      * A version agnostic adapter class for HTTP Server Filter Chains.
      */
@@ -351,9 +360,9 @@
                 try {
                     exchange.doFilter(chain);
                 } catch (Throwable t) {
-                    System.out.println("WARNING: exception caught in Http1Chain::doFilter" + t);
-                    System.err.println("WARNING: exception caught in Http1Chain::doFilter" + t);
-                    if (PRINTSTACK) t.printStackTrace();
+                    System.out.println("WARNING: exception caught in Http1Chain::doFilter " + t);
+                    System.err.println("WARNING: exception caught in Http1Chain::doFilter " + t);
+                    if (PRINTSTACK && !expectException(exchange)) t.printStackTrace();
                     throw t;
                 }
             }
@@ -375,9 +384,9 @@
                         handler.handle(exchange);
                     }
                 } catch (Throwable t) {
-                    System.out.println("WARNING: exception caught in Http2Chain::doFilter" + t);
-                    System.err.println("WARNING: exception caught in Http2Chain::doFilter" + t);
-                    if (PRINTSTACK) t.printStackTrace();
+                    System.out.println("WARNING: exception caught in Http2Chain::doFilter " + t);
+                    System.err.println("WARNING: exception caught in Http2Chain::doFilter " + t);
+                    if (PRINTSTACK && !expectException(exchange)) t.printStackTrace();
                     throw t;
                 }
             }