From 078c497525d11ce92af340d69ba180e88c06fb7b Mon Sep 17 00:00:00 2001 From: xuelei Date: Sat, 10 Apr 2010 09:13:12 +0800 Subject: [PATCH] 6941936: Broken pipe error of test case DNSIdentities.java Reviewed-by: chegar --- .../HttpsURLConnection/DNSIdentities.java | 33 +++++++--- .../https/HttpsURLConnection/HttpsPost.java | 65 ++++++++++++------- .../IPAddressDNSIdentities.java | 23 +++++-- .../IPAddressIPIdentities.java | 25 +++++-- .../HttpsURLConnection/IPIdentities.java | 25 +++++-- .../https/HttpsURLConnection/Identities.java | 25 +++++-- .../https/HttpsURLConnection/Redirect.java | 62 +++++++++++------- 7 files changed, 179 insertions(+), 79 deletions(-) diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java index d8cdb2ea2..eddbd29e1 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java @@ -623,6 +623,11 @@ public class DNSIdentities { */ volatile static boolean serverReady = false; + /* + * Is the connection ready to close? + */ + volatile static boolean closeReady = false; + /* * Turn on SSL debugging? */ @@ -670,11 +675,14 @@ public class DNSIdentities { out.print("Testing\r\n"); out.flush(); } finally { - // close the socket - Thread.sleep(2000); - System.out.println("Server closing socket"); - sslSocket.close(); - serverReady = false; + // close the socket + while (!closeReady) { + Thread.sleep(50); + } + + System.out.println("Server closing socket"); + sslSocket.close(); + serverReady = false; } } @@ -704,12 +712,17 @@ public class DNSIdentities { URL url = new URL("https://localhost:" + serverPort+"/"); System.out.println("url is "+url.toString()); - http = (HttpsURLConnection)url.openConnection(); - - int respCode = http.getResponseCode(); - System.out.println("respCode = "+respCode); + try { + http = (HttpsURLConnection)url.openConnection(); - http.disconnect(); + int respCode = http.getResponseCode(); + System.out.println("respCode = "+respCode); + } finally { + if (http != null) { + http.disconnect(); + } + closeReady = true; + } } /* diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsPost.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsPost.java index 33ebfda58..0e55c60ee 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsPost.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsPost.java @@ -60,6 +60,11 @@ public class HttpsPost { */ volatile static boolean serverReady = false; + /* + * Is the connection ready to close? + */ + volatile static boolean closeReady = false; + /* * Turn on SSL debugging? */ @@ -98,25 +103,34 @@ public class HttpsPost { serverReady = true; SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept(); - InputStream sslIS = sslSocket.getInputStream(); - OutputStream sslOS = sslSocket.getOutputStream(); - BufferedReader br = new BufferedReader(new InputStreamReader(sslIS)); - PrintStream ps = new PrintStream(sslOS); - // process HTTP POST request from client - System.out.println("status line: "+br.readLine()); - String msg = null; - while ((msg = br.readLine()) != null && msg.length() > 0); - - msg = br.readLine(); - if (msg.equals(postMsg)) { - ps.println("HTTP/1.1 200 OK\n\n"); - } else { - ps.println("HTTP/1.1 500 Not OK\n\n"); + try { + InputStream sslIS = sslSocket.getInputStream(); + OutputStream sslOS = sslSocket.getOutputStream(); + BufferedReader br = + new BufferedReader(new InputStreamReader(sslIS)); + PrintStream ps = new PrintStream(sslOS); + + // process HTTP POST request from client + System.out.println("status line: "+br.readLine()); + String msg = null; + while ((msg = br.readLine()) != null && msg.length() > 0); + + msg = br.readLine(); + if (msg.equals(postMsg)) { + ps.println("HTTP/1.1 200 OK\n\n"); + } else { + ps.println("HTTP/1.1 500 Not OK\n\n"); + } + ps.flush(); + + // close the socket + while (!closeReady) { + Thread.sleep(50); + } + } finally { + sslSocket.close(); + sslServerSocket.close(); } - ps.flush(); - Thread.sleep(2000); - sslSocket.close(); - sslServerSocket.close(); } /* @@ -144,12 +158,17 @@ public class HttpsPost { http.setRequestMethod("POST"); PrintStream ps = new PrintStream(http.getOutputStream()); - ps.println(postMsg); - ps.flush(); - if (http.getResponseCode() != 200) { - throw new RuntimeException("test Failed"); + try { + ps.println(postMsg); + ps.flush(); + if (http.getResponseCode() != 200) { + throw new RuntimeException("test Failed"); + } + } finally { + ps.close(); + http.disconnect(); + closeReady = true; } - ps.close(); } static class NameVerifier implements HostnameVerifier { diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java index c4d48cc10..4cc3a0f05 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java @@ -623,6 +623,11 @@ public class IPAddressDNSIdentities { */ volatile static boolean serverReady = false; + /* + * Is the connection ready to close? + */ + volatile static boolean closeReady = false; + /* * Turn on SSL debugging? */ @@ -670,11 +675,14 @@ public class IPAddressDNSIdentities { out.print("Testing\r\n"); out.flush(); } finally { - // close the socket - Thread.sleep(2000); - System.out.println("Server closing socket"); - sslSocket.close(); - serverReady = false; + // close the socket + while (!closeReady) { + Thread.sleep(50); + } + + System.out.println("Server closing socket"); + sslSocket.close(); + serverReady = false; } } @@ -716,7 +724,10 @@ public class IPAddressDNSIdentities { // no subject alternative names matching IP address 127.0.0.1 found // that's the expected exception, ignore it. } finally { - http.disconnect(); + if (http != null) { + http.disconnect(); + } + closeReady = true; } } diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java index 4bafaf24b..d30efd81e 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java @@ -624,6 +624,11 @@ public class IPAddressIPIdentities { */ volatile static boolean serverReady = false; + /* + * Is the connection ready to close? + */ + volatile static boolean closeReady = false; + /* * Turn on SSL debugging? */ @@ -672,7 +677,10 @@ public class IPAddressIPIdentities { out.flush(); } finally { // close the socket - Thread.sleep(2000); + while (!closeReady) { + Thread.sleep(50); + } + System.out.println("Server closing socket"); sslSocket.close(); serverReady = false; @@ -705,12 +713,17 @@ public class IPAddressIPIdentities { URL url = new URL("https://127.0.0.1:" + serverPort+"/"); System.out.println("url is "+url.toString()); - http = (HttpsURLConnection)url.openConnection(); - - int respCode = http.getResponseCode(); - System.out.println("respCode = "+respCode); + try { + http = (HttpsURLConnection)url.openConnection(); - http.disconnect(); + int respCode = http.getResponseCode(); + System.out.println("respCode = "+respCode); + } finally { + if (http != null) { + http.disconnect(); + } + closeReady = true; + } } /* diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java index 7e1d48fdf..10dc8d830 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java @@ -624,6 +624,11 @@ public class IPIdentities { */ volatile static boolean serverReady = false; + /* + * Is the connection ready to close? + */ + volatile static boolean closeReady = false; + /* * Turn on SSL debugging? */ @@ -672,7 +677,10 @@ public class IPIdentities { out.flush(); } finally { // close the socket - Thread.sleep(2000); + while (!closeReady) { + Thread.sleep(50); + } + System.out.println("Server closing socket"); sslSocket.close(); serverReady = false; @@ -705,12 +713,17 @@ public class IPIdentities { URL url = new URL("https://localhost:" + serverPort+"/"); System.out.println("url is "+url.toString()); - http = (HttpsURLConnection)url.openConnection(); - - int respCode = http.getResponseCode(); - System.out.println("respCode = "+respCode); + try { + http = (HttpsURLConnection)url.openConnection(); - http.disconnect(); + int respCode = http.getResponseCode(); + System.out.println("respCode = "+respCode); + } finally { + if (http != null) { + http.disconnect(); + } + closeReady = true; + } } /* diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java index 0bde45f90..79224b0ac 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java @@ -623,6 +623,11 @@ public class Identities { */ volatile static boolean serverReady = false; + /* + * Is the connection ready to close? + */ + volatile static boolean closeReady = false; + /* * Turn on SSL debugging? */ @@ -671,7 +676,10 @@ public class Identities { out.flush(); } finally { // close the socket - Thread.sleep(2000); + while (!closeReady) { + Thread.sleep(50); + } + System.out.println("Server closing socket"); sslSocket.close(); serverReady = false; @@ -704,12 +712,17 @@ public class Identities { URL url = new URL("https://localhost:" + serverPort+"/"); System.out.println("url is "+url.toString()); - http = (HttpsURLConnection)url.openConnection(); - - int respCode = http.getResponseCode(); - System.out.println("respCode = "+respCode); + try { + http = (HttpsURLConnection)url.openConnection(); - http.disconnect(); + int respCode = http.getResponseCode(); + System.out.println("respCode = "+respCode); + } finally { + if (http != null) { + http.disconnect(); + } + closeReady = true; + } } /* diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Redirect.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Redirect.java index 838647ab7..9321820f7 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Redirect.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Redirect.java @@ -60,6 +60,11 @@ public class Redirect { */ volatile static boolean serverReady = false; + /* + * Is the connection ready to close? + */ + volatile static boolean closeReady = false; + /* * Turn on SSL debugging? */ @@ -98,24 +103,33 @@ public class Redirect { serverReady = true; SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept(); - InputStream sslIS = sslSocket.getInputStream(); - OutputStream sslOS = sslSocket.getOutputStream(); - BufferedReader br = new BufferedReader(new InputStreamReader(sslIS)); - PrintStream ps = new PrintStream(sslOS); - // process HTTP POST request from client - System.out.println("status line: "+br.readLine()); - - ps.println("HTTP/1.1 307 Redirect"); - ps.println("Location: https://localhost:"+serverPort+"/index.html\n\n"); - ps.flush(); - sslSocket = (SSLSocket) sslServerSocket.accept(); - sslOS = sslSocket.getOutputStream(); - ps = new PrintStream(sslOS); - ps.println("HTTP/1.1 200 Redirect succeeded\n\n"); - ps.flush(); - Thread.sleep(2000); - sslSocket.close(); - sslServerSocket.close(); + try { + InputStream sslIS = sslSocket.getInputStream(); + OutputStream sslOS = sslSocket.getOutputStream(); + BufferedReader br = + new BufferedReader(new InputStreamReader(sslIS)); + PrintStream ps = new PrintStream(sslOS); + + // process HTTP POST request from client + System.out.println("status line: "+br.readLine()); + + ps.println("HTTP/1.1 307 Redirect"); + ps.println("Location: https://localhost:" + serverPort + + "/index.html\n\n"); + ps.flush(); + sslSocket = (SSLSocket) sslServerSocket.accept(); + sslOS = sslSocket.getOutputStream(); + ps = new PrintStream(sslOS); + ps.println("HTTP/1.1 200 Redirect succeeded\n\n"); + ps.flush(); + } finally { + // close the socket + while (!closeReady) { + Thread.sleep(50); + } + sslSocket.close(); + sslServerSocket.close(); + } } /* @@ -139,10 +153,14 @@ public class Redirect { HttpsURLConnection.setDefaultHostnameVerifier( new NameVerifier()); HttpsURLConnection http = (HttpsURLConnection)url.openConnection(); - - System.out.println("response header: "+http.getHeaderField(0)); - if (http.getResponseCode() != 200) { - throw new RuntimeException("test Failed"); + try { + System.out.println("response header: "+http.getHeaderField(0)); + if (http.getResponseCode() != 200) { + throw new RuntimeException("test Failed"); + } + } finally { + http.disconnect(); + closeReady = true; } } -- GitLab