src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java

Print this page




 342        calls getInputStream after disconnect */
 343     private Exception rememberedException = null;
 344 
 345     /* If we decide we want to reuse a client, we put it here */
 346     private HttpClient reuseClient = null;
 347 
 348     /* Tunnel states */
 349     enum TunnelState {
 350         /* No tunnel */
 351         NONE,
 352 
 353         /* Setting up a tunnel */
 354         SETUP,
 355 
 356         /* Tunnel has been successfully setup */
 357         TUNNELING
 358     }
 359 
 360     private TunnelState tunnelState = TunnelState.NONE;
 361 
 362     /* Redefine timeouts from java.net.URLConnection as we nee -1 to mean
 363      * not set. This is to ensure backward compatibility.
 364      */
 365     private int connectTimeout = -1;
 366     private int readTimeout = -1;
 367 
 368     /* Logging support */
 369     private static final PlatformLogger logger =
 370             PlatformLogger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
 371 
 372     /*
 373      * privileged request password authentication
 374      *
 375      */
 376     private static PasswordAuthentication
 377     privilegedRequestPasswordAuthentication(
 378                             final String host,
 379                             final InetAddress addr,
 380                             final int port,
 381                             final String protocol,
 382                             final String prompt,
 383                             final String scheme,
 384                             final URL url,
 385                             final RequestorType authType) {
 386         return java.security.AccessController.doPrivileged(


1024             if (!timedOut) {
1025                 // Can't use getResponseCode() yet
1026                 String resp = responses.getValue(0);
1027                 // Parse the response which is of the form:
1028                 // HTTP/1.1 417 Expectation Failed
1029                 // HTTP/1.1 100 Continue
1030                 if (resp != null && resp.startsWith("HTTP/")) {
1031                     String[] sa = resp.split("\\s+");
1032                     responseCode = -1;
1033                     try {
1034                         // Response code is 2nd token on the line
1035                         if (sa.length > 1)
1036                             responseCode = Integer.parseInt(sa[1]);
1037                     } catch (NumberFormatException numberFormatException) {
1038                     }
1039                 }
1040                 if (responseCode != 100) {
1041                     throw new ProtocolException("Server rejected operation");
1042                 }
1043             }
1044             if (oldTimeout > 0) {
1045                 http.setReadTimeout(oldTimeout);
1046             }
1047             responseCode = -1;
1048             responses.reset();
1049             // Proceed
1050     }
1051 
1052     /*
1053      * Allowable input/output sequences:
1054      * [interpreted as POST/PUT]
1055      * - get output, [write output,] get input, [read input]
1056      * - get output, [write output]
1057      * [interpreted as GET]
1058      * - get input, [read input]
1059      * Disallowed:
1060      * - get input, [read input,] get output, [write output]
1061      */
1062 
1063     @Override
1064     public synchronized OutputStream getOutputStream() throws IOException {
1065 
1066         try {




 342        calls getInputStream after disconnect */
 343     private Exception rememberedException = null;
 344 
 345     /* If we decide we want to reuse a client, we put it here */
 346     private HttpClient reuseClient = null;
 347 
 348     /* Tunnel states */
 349     enum TunnelState {
 350         /* No tunnel */
 351         NONE,
 352 
 353         /* Setting up a tunnel */
 354         SETUP,
 355 
 356         /* Tunnel has been successfully setup */
 357         TUNNELING
 358     }
 359 
 360     private TunnelState tunnelState = TunnelState.NONE;
 361 
 362     /* Redefine timeouts from java.net.URLConnection as we need -1 to mean
 363      * not set. This is to ensure backward compatibility.
 364      */
 365     private int connectTimeout = NetworkClient.DEFAULT_CONNECT_TIMEOUT;
 366     private int readTimeout = NetworkClient.DEFAULT_READ_TIMEOUT;
 367 
 368     /* Logging support */
 369     private static final PlatformLogger logger =
 370             PlatformLogger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
 371 
 372     /*
 373      * privileged request password authentication
 374      *
 375      */
 376     private static PasswordAuthentication
 377     privilegedRequestPasswordAuthentication(
 378                             final String host,
 379                             final InetAddress addr,
 380                             final int port,
 381                             final String protocol,
 382                             final String prompt,
 383                             final String scheme,
 384                             final URL url,
 385                             final RequestorType authType) {
 386         return java.security.AccessController.doPrivileged(


1024             if (!timedOut) {
1025                 // Can't use getResponseCode() yet
1026                 String resp = responses.getValue(0);
1027                 // Parse the response which is of the form:
1028                 // HTTP/1.1 417 Expectation Failed
1029                 // HTTP/1.1 100 Continue
1030                 if (resp != null && resp.startsWith("HTTP/")) {
1031                     String[] sa = resp.split("\\s+");
1032                     responseCode = -1;
1033                     try {
1034                         // Response code is 2nd token on the line
1035                         if (sa.length > 1)
1036                             responseCode = Integer.parseInt(sa[1]);
1037                     } catch (NumberFormatException numberFormatException) {
1038                     }
1039                 }
1040                 if (responseCode != 100) {
1041                     throw new ProtocolException("Server rejected operation");
1042                 }
1043             }
1044             
1045             http.setReadTimeout(oldTimeout);
1046 
1047             responseCode = -1;
1048             responses.reset();
1049             // Proceed
1050     }
1051 
1052     /*
1053      * Allowable input/output sequences:
1054      * [interpreted as POST/PUT]
1055      * - get output, [write output,] get input, [read input]
1056      * - get output, [write output]
1057      * [interpreted as GET]
1058      * - get input, [read input]
1059      * Disallowed:
1060      * - get input, [read input,] get output, [write output]
1061      */
1062 
1063     @Override
1064     public synchronized OutputStream getOutputStream() throws IOException {
1065 
1066         try {