< prev index next >

src/java.base/share/classes/sun/net/www/http/HttpClient.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.www.http;
  27 
  28 import java.io.*;
  29 import java.net.*;
  30 import java.util.Locale;

  31 import sun.net.NetworkClient;
  32 import sun.net.ProgressSource;
  33 import sun.net.www.MessageHeader;
  34 import sun.net.www.HeaderParser;
  35 import sun.net.www.MeteredStream;
  36 import sun.net.www.ParseUtil;
  37 import sun.net.www.protocol.http.HttpURLConnection;
  38 import sun.util.logging.PlatformLogger;
  39 import static sun.net.www.protocol.http.HttpURLConnection.TunnelState.*;

  40 
  41 /**
  42  * @author Herb Jellinek
  43  * @author Dave Brown
  44  */
  45 public class HttpClient extends NetworkClient {
  46     // whether this httpclient comes from the cache
  47     protected boolean cachedHttpClient = false;
  48 
  49     protected boolean inCache;
  50 
  51     // Http requests we send
  52     MessageHeader requests;
  53 
  54     // Http data we send with the headers
  55     PosterOutputStream poster = null;
  56 
  57     // true if we are in streaming mode (fixed length or chunked)
  58     boolean streaming;
  59 


 126     private static final PlatformLogger logger = HttpURLConnection.getHttpLogger();
 127     private static void logFinest(String msg) {
 128         if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
 129             logger.finest(msg);
 130         }
 131     }
 132 
 133     /**
 134      * A NOP method kept for backwards binary compatibility
 135      * @deprecated -- system properties are no longer cached.
 136      */
 137     @Deprecated
 138     public static synchronized void resetProperties() {
 139     }
 140 
 141     int getKeepAliveTimeout() {
 142         return keepAliveTimeout;
 143     }
 144 
 145     static {
 146         String keepAlive = java.security.AccessController.doPrivileged(
 147             new sun.security.action.GetPropertyAction("http.keepAlive"));
 148 
 149         String retryPost = java.security.AccessController.doPrivileged(
 150             new sun.security.action.GetPropertyAction("sun.net.http.retryPost"));
 151 
 152         if (keepAlive != null) {
 153             keepAliveProp = Boolean.valueOf(keepAlive).booleanValue();
 154         } else {
 155             keepAliveProp = true;
 156         }
 157 
 158         if (retryPost != null) {
 159             retryPostProp = Boolean.valueOf(retryPost).booleanValue();
 160         } else
 161             retryPostProp = true;
 162 
 163     }
 164 
 165     /**
 166      * @return true iff http keep alive is set (i.e. enabled).  Defaults
 167      *          to true if the system property http.keepAlive isn't set.
 168      */
 169     public boolean getHttpKeepAliveSet() {
 170         return keepAliveProp;
 171     }
 172 
 173 
 174     protected HttpClient() {
 175     }
 176 
 177     private HttpClient(URL url)
 178     throws IOException {
 179         this(url, (String)null, -1, false);




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.www.http;
  27 
  28 import java.io.*;
  29 import java.net.*;
  30 import java.util.Locale;
  31 import java.util.Properties;
  32 import sun.net.NetworkClient;
  33 import sun.net.ProgressSource;
  34 import sun.net.www.MessageHeader;
  35 import sun.net.www.HeaderParser;
  36 import sun.net.www.MeteredStream;
  37 import sun.net.www.ParseUtil;
  38 import sun.net.www.protocol.http.HttpURLConnection;
  39 import sun.util.logging.PlatformLogger;
  40 import static sun.net.www.protocol.http.HttpURLConnection.TunnelState.*;
  41 import sun.security.action.GetPropertyAction;
  42 
  43 /**
  44  * @author Herb Jellinek
  45  * @author Dave Brown
  46  */
  47 public class HttpClient extends NetworkClient {
  48     // whether this httpclient comes from the cache
  49     protected boolean cachedHttpClient = false;
  50 
  51     protected boolean inCache;
  52 
  53     // Http requests we send
  54     MessageHeader requests;
  55 
  56     // Http data we send with the headers
  57     PosterOutputStream poster = null;
  58 
  59     // true if we are in streaming mode (fixed length or chunked)
  60     boolean streaming;
  61 


 128     private static final PlatformLogger logger = HttpURLConnection.getHttpLogger();
 129     private static void logFinest(String msg) {
 130         if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
 131             logger.finest(msg);
 132         }
 133     }
 134 
 135     /**
 136      * A NOP method kept for backwards binary compatibility
 137      * @deprecated -- system properties are no longer cached.
 138      */
 139     @Deprecated
 140     public static synchronized void resetProperties() {
 141     }
 142 
 143     int getKeepAliveTimeout() {
 144         return keepAliveTimeout;
 145     }
 146 
 147     static {
 148         Properties props = GetPropertyAction.getProperties();
 149         String keepAlive = props.getProperty("http.keepAlive");
 150         String retryPost = props.getProperty("sun.net.http.retryPost");


 151 
 152         if (keepAlive != null) {
 153             keepAliveProp = Boolean.parseBoolean(keepAlive);
 154         } else {
 155             keepAliveProp = true;
 156         }
 157 
 158         if (retryPost != null) {
 159             retryPostProp = Boolean.parseBoolean(retryPost);
 160         } else
 161             retryPostProp = true;
 162 
 163     }
 164 
 165     /**
 166      * @return true iff http keep alive is set (i.e. enabled).  Defaults
 167      *          to true if the system property http.keepAlive isn't set.
 168      */
 169     public boolean getHttpKeepAliveSet() {
 170         return keepAliveProp;
 171     }
 172 
 173 
 174     protected HttpClient() {
 175     }
 176 
 177     private HttpClient(URL url)
 178     throws IOException {
 179         this(url, (String)null, -1, false);


< prev index next >