test/jdk/java/net/httpclient/ssltest/CertificateTest.java
branchhttp-client-branch
changeset 56682 9822bbe48b9b
parent 56451 9585061fdb04
child 56744 efbae6e5b3cd
--- a/test/jdk/java/net/httpclient/ssltest/CertificateTest.java	Wed Jun 06 15:52:48 2018 +0100
+++ b/test/jdk/java/net/httpclient/ssltest/CertificateTest.java	Wed Jun 06 15:01:02 2018 +0100
@@ -22,6 +22,7 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URI;
 import java.net.http.HttpClient;
 import java.net.http.HttpResponse.BodyHandlers;
@@ -30,6 +31,7 @@
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLParameters;
+import static java.net.http.HttpClient.Builder.NO_PROXY;
 
 /*
  * @test
@@ -112,6 +114,7 @@
         Exception exception = null;
         System.out.println("Making request to " + uri_s);
         HttpClient client = HttpClient.newBuilder()
+                .proxy(NO_PROXY)
                 .sslContext(ctx)
                 .sslParameters(params)
                 .build();
@@ -128,7 +131,9 @@
                 error = "Test failed: good: status should be 200";
             else if (!expectSuccess)
                 error = "Test failed: bad: status should not be 200";
-        } catch (SSLException e) {
+        } catch (IOException e) {
+            // there must be an SSLException as the exception or cause
+            checkExceptionOrCause(SSLException.class, e);
             System.err.println("Caught Exception " + e + ". expectSuccess = " + expectSuccess);
             exception = e;
             if (expectSuccess)
@@ -137,4 +142,15 @@
         if (error != null)
             throw new RuntimeException(error, exception);
     }
+
+    static void checkExceptionOrCause(Class<? extends Throwable> clazz, Throwable t) {
+        do {
+            if (clazz.isInstance(t)) {
+                System.out.println("Found expected exception/cause: " + t);
+                return; // found
+            }
+        } while ((t = t.getCause()) != null);
+        t.printStackTrace(System.out);
+        throw new RuntimeException("Expected " + clazz + "in " + t);
+    }
 }