test/jdk/sun/net/www/protocol/https/HttpsURLConnection/ReadTimeout.java
changeset 50768 68fa3d4026ea
parent 47216 71c04702a3d5
child 54938 8c977741c3c8
equal deleted inserted replaced
50767:356eaea05bf0 50768:68fa3d4026ea
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   173 
   173 
   174                 InputStream is = http.getInputStream();
   174                 InputStream is = http.getInputStream();
   175 
   175 
   176                 throw new Exception(
   176                 throw new Exception(
   177                         "system property timeout configuration does not work");
   177                         "system property timeout configuration does not work");
   178             } catch (SocketTimeoutException stex) {
   178             } catch (SSLException | SocketTimeoutException ex) {
   179                 System.out.println("Got expected timeout exception for " +
   179                 System.out.println("Got expected timeout exception for " +
   180                         "system property timeout configuration: " + stex);
   180                         "system property timeout configuration: " + getCause(ex));
   181             } finally {
   181             } finally {
   182                 done();
   182                 done();
   183                 http.disconnect();
   183                 http.disconnect();
   184             }
   184             }
   185 
   185 
   194 
   194 
   195                 InputStream is = http.getInputStream();
   195                 InputStream is = http.getInputStream();
   196 
   196 
   197                 throw new Exception(
   197                 throw new Exception(
   198                         "HttpsURLConnection.setReadTimeout() does not work");
   198                         "HttpsURLConnection.setReadTimeout() does not work");
   199             } catch (SocketTimeoutException stex) {
   199             } catch (SSLException | SocketTimeoutException ex) {
   200                 System.out.println("Got expected timeout exception for " +
   200                 System.out.println("Got expected timeout exception for " +
   201                         "HttpsURLConnection.setReadTimeout(): " + stex);
   201                         "HttpsURLConnection.setReadTimeout(): " + getCause(ex));
   202             } finally {
   202             } finally {
   203                 done();
   203                 done();
   204                 http.disconnect();
   204                 http.disconnect();
   205             }
   205             }
   206         } finally {
   206         } finally {
   207             HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
   207             HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
   208         }
   208         }
       
   209     }
       
   210 
       
   211     private Exception getCause(Exception ex) {
       
   212         Exception cause = null;
       
   213         if (ex instanceof SSLException) {
       
   214             cause = (Exception) ex.getCause();
       
   215             if (!(cause instanceof SocketTimeoutException)) {
       
   216                 throw new RuntimeException("Unexpected cause", cause);
       
   217             }
       
   218         } else {
       
   219             cause = ex;
       
   220         }
       
   221 
       
   222         return cause;
   209     }
   223     }
   210 
   224 
   211     static class NameVerifier implements HostnameVerifier {
   225     static class NameVerifier implements HostnameVerifier {
   212         public boolean verify(String hostname, SSLSession session) {
   226         public boolean verify(String hostname, SSLSession session) {
   213             return true;
   227             return true;