提交 0b14a745 编写于 作者: X xuelei

7195733: TEST_BUG:...

7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
Reviewed-by: chegar, alanb, xuelei
Contributed-by: NEric Wang <yiming.wang@oracle.com>
上级 0a830205
/* /*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,10 +27,9 @@ ...@@ -27,10 +27,9 @@
* @library ../../../httpstest/ * @library ../../../httpstest/
* @build HttpCallback HttpServer ClosedChannelList HttpTransaction TunnelProxy * @build HttpCallback HttpServer ClosedChannelList HttpTransaction TunnelProxy
* @summary Redirect problem with HttpsURLConnection using a proxy * @summary Redirect problem with HttpsURLConnection using a proxy
* @run main/othervm B6216082
*
* SunJSSE does not support dynamic system properties, no way to re-use * SunJSSE does not support dynamic system properties, no way to re-use
* system properties in samevm/agentvm mode. * system properties in samevm/agentvm mode.
* @run main/othervm B6216082
*/ */
import java.io.*; import java.io.*;
...@@ -54,7 +53,9 @@ public class B6216082 { ...@@ -54,7 +53,9 @@ public class B6216082 {
try { try {
// XXX workaround for CNFE // XXX workaround for CNFE
Class.forName("java.nio.channels.ClosedByInterruptException"); Class.forName("java.nio.channels.ClosedByInterruptException");
setupEnv(); if (!setupEnv()) {
return;
}
startHttpServer(); startHttpServer();
...@@ -69,6 +70,12 @@ public class B6216082 { ...@@ -69,6 +70,12 @@ public class B6216082 {
throw new RuntimeException("Test failed : bad http request"); throw new RuntimeException("Test failed : bad http request");
} }
} finally { } finally {
if (proxy != null) {
proxy.terminate();
}
if (server != null) {
server.terminate();
}
HttpsURLConnection.setDefaultHostnameVerifier(reservedHV); HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
} }
} }
...@@ -80,18 +87,13 @@ public class B6216082 { ...@@ -80,18 +87,13 @@ public class B6216082 {
static String keyStoreFile = "keystore"; static String keyStoreFile = "keystore";
static String trustStoreFile = "truststore"; static String trustStoreFile = "truststore";
static String passwd = "passphrase"; static String passwd = "passphrase";
public static void setupEnv() { public static boolean setupEnv() throws Exception {
try {
firstNonLoAddress = getNonLoAddress(); firstNonLoAddress = getNonLoAddress();
if (firstNonLoAddress == null) { if (firstNonLoAddress == null) {
System.out.println("The test needs at least one non-loopback address to run. Quit now."); System.err.println("The test needs at least one non-loopback address to run. Quit now.");
System.exit(0); return false;
} }
System.out.println(firstNonLoAddress.getHostAddress()); System.out.println(firstNonLoAddress.getHostAddress());
} catch (Exception e) {
e.printStackTrace();
}
// will use proxy // will use proxy
System.setProperty( "https.proxyHost", firstNonLoAddress.getHostAddress()); System.setProperty( "https.proxyHost", firstNonLoAddress.getHostAddress());
...@@ -106,6 +108,7 @@ public class B6216082 { ...@@ -106,6 +108,7 @@ public class B6216082 {
System.setProperty("javax.net.ssl.trustStore", trustFilename); System.setProperty("javax.net.ssl.trustStore", trustFilename);
System.setProperty("javax.net.ssl.trustStorePassword", passwd); System.setProperty("javax.net.ssl.trustStorePassword", passwd);
HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());
return true;
} }
public static InetAddress getNonLoAddress() throws Exception { public static InetAddress getNonLoAddress() throws Exception {
...@@ -126,20 +129,15 @@ public class B6216082 { ...@@ -126,20 +129,15 @@ public class B6216082 {
return null; return null;
} }
public static void startHttpServer() { public static void startHttpServer() throws IOException {
try {
// Both the https server and the proxy let the // Both the https server and the proxy let the
// system pick up an ephemeral port. // system pick up an ephemeral port.
httpTrans = new SimpleHttpTransaction(); httpTrans = new SimpleHttpTransaction();
server = new HttpServer(httpTrans, 1, 10, 0); server = new HttpServer(httpTrans, 1, 10, 0);
proxy = new TunnelProxy(1, 10, 0); proxy = new TunnelProxy(1, 10, 0);
} catch (IOException e) {
e.printStackTrace();
}
} }
public static void makeHttpCall() { public static void makeHttpCall() throws Exception {
try {
System.out.println("https server listen on: " + server.getLocalPort()); System.out.println("https server listen on: " + server.getLocalPort());
System.out.println("https proxy listen on: " + proxy.getLocalPort()); System.out.println("https proxy listen on: " + proxy.getLocalPort());
URL url = new URL("https" , firstNonLoAddress.getHostAddress(), URL url = new URL("https" , firstNonLoAddress.getHostAddress(),
...@@ -147,12 +145,6 @@ public class B6216082 { ...@@ -147,12 +145,6 @@ public class B6216082 {
HttpURLConnection uc = (HttpURLConnection)url.openConnection(); HttpURLConnection uc = (HttpURLConnection)url.openConnection();
System.out.println(uc.getResponseCode()); System.out.println(uc.getResponseCode());
uc.disconnect(); uc.disconnect();
} catch (IOException e) {
e.printStackTrace();
} finally {
proxy.terminate();
server.terminate();
}
} }
static class NameVerifier implements HostnameVerifier { static class NameVerifier implements HostnameVerifier {
...@@ -189,7 +181,7 @@ class SimpleHttpTransaction implements HttpCallback { ...@@ -189,7 +181,7 @@ class SimpleHttpTransaction implements HttpCallback {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new RuntimeException(e);
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册