< prev index next >

src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java

Print this page




  40 import sun.net.www.http.HttpClient;
  41 
  42 /**
  43  * A class to represent an HTTP connection to a remote object.
  44  *
  45  * Ideally, this class should subclass and inherit the http handler
  46  * implementation, but it can't do so because that class have the
  47  * wrong Java Type.  Thus it uses the delegate (aka, the
  48  * Adapter/Wrapper design pattern) to reuse code from the http
  49  * handler.
  50  *
  51  * Since it would use a delegate to access
  52  * sun.net.www.protocol.http.HttpURLConnection functionalities, it
  53  * needs to implement all public methods in it's super class and all
  54  * the way to Object.
  55  *
  56  */
  57 public class HttpsURLConnectionImpl
  58         extends javax.net.ssl.HttpsURLConnection {
  59 
  60     private final DelegateHttpsURLConnection delegate;

  61 
  62     HttpsURLConnectionImpl(URL u, Handler handler) throws IOException {
  63         this(u, null, handler);
  64     }
  65 
  66     static URL checkURL(URL u) throws IOException {
  67         if (u != null) {
  68             if (u.toExternalForm().indexOf('\n') > -1) {
  69                 throw new MalformedURLException("Illegal character in URL");
  70             }
  71         }
  72         return u;
  73     }
  74 
  75     HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException {
  76         super(checkURL(u));
  77         delegate = new DelegateHttpsURLConnection(url, p, handler, this);
  78     }
  79 







  80     /**
  81      * Create a new HttpClient object, bypassing the cache of
  82      * HTTP client objects/connections.
  83      *
  84      * @param url       the URL being accessed
  85      */
  86     protected void setNewClient(URL url) throws IOException {
  87         delegate.setNewClient(url, false);
  88     }
  89 
  90     /**
  91      * Obtain a HttpClient object. Use the cached copy if specified.
  92      *
  93      * @param url       the URL being accessed
  94      * @param useCache  whether the cached connection should be used
  95      *                  if present
  96      */
  97     protected void setNewClient(URL url, boolean useCache)
  98             throws IOException {
  99         delegate.setNewClient(url, useCache);


 194     /**
 195      * Returns the principal the client sent to the
 196      * server, or null if the client did not authenticate.
 197      */
 198     public Principal getLocalPrincipal()
 199     {
 200         return delegate.getLocalPrincipal();
 201     }
 202 
 203     /*
 204      * Allowable input/output sequences:
 205      * [interpreted as POST/PUT]
 206      * - get output, [write output,] get input, [read input]
 207      * - get output, [write output]
 208      * [interpreted as GET]
 209      * - get input, [read input]
 210      * Disallowed:
 211      * - get input, [read input,] get output, [write output]
 212      */
 213 
 214     public OutputStream getOutputStream() throws IOException {
 215         return delegate.getOutputStream();
 216     }
 217 
 218     public InputStream getInputStream() throws IOException {
 219         return delegate.getInputStream();
 220     }
 221 
 222     public InputStream getErrorStream() {
 223         return delegate.getErrorStream();
 224     }
 225 
 226     /**
 227      * Disconnect from the server.
 228      */
 229     public void disconnect() {
 230         delegate.disconnect();
 231     }
 232 
 233     public boolean usingProxy() {
 234         return delegate.usingProxy();
 235     }
 236 
 237     /**
 238      * Returns an unmodifiable Map of the header fields.




  40 import sun.net.www.http.HttpClient;
  41 
  42 /**
  43  * A class to represent an HTTP connection to a remote object.
  44  *
  45  * Ideally, this class should subclass and inherit the http handler
  46  * implementation, but it can't do so because that class have the
  47  * wrong Java Type.  Thus it uses the delegate (aka, the
  48  * Adapter/Wrapper design pattern) to reuse code from the http
  49  * handler.
  50  *
  51  * Since it would use a delegate to access
  52  * sun.net.www.protocol.http.HttpURLConnection functionalities, it
  53  * needs to implement all public methods in it's super class and all
  54  * the way to Object.
  55  *
  56  */
  57 public class HttpsURLConnectionImpl
  58         extends javax.net.ssl.HttpsURLConnection {
  59 
  60     // NOTE: made protected for plugin so that subclass can set it.
  61     protected DelegateHttpsURLConnection delegate;
  62 
  63     HttpsURLConnectionImpl(URL u, Handler handler) throws IOException {
  64         this(u, null, handler);
  65     }
  66 
  67     static URL checkURL(URL u) throws IOException {
  68         if (u != null) {
  69             if (u.toExternalForm().indexOf('\n') > -1) {
  70                 throw new MalformedURLException("Illegal character in URL");
  71             }
  72         }
  73         return u;
  74     }
  75 
  76     HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException {
  77         super(checkURL(u));
  78         delegate = new DelegateHttpsURLConnection(url, p, handler, this);
  79     }
  80 
  81     // NOTE: introduced for plugin
  82     // subclass needs to overwrite this to set delegate to
  83     // the appropriate delegatee
  84     protected HttpsURLConnectionImpl(URL u) throws IOException {
  85         super(u);
  86     }
  87 
  88     /**
  89      * Create a new HttpClient object, bypassing the cache of
  90      * HTTP client objects/connections.
  91      *
  92      * @param url       the URL being accessed
  93      */
  94     protected void setNewClient(URL url) throws IOException {
  95         delegate.setNewClient(url, false);
  96     }
  97 
  98     /**
  99      * Obtain a HttpClient object. Use the cached copy if specified.
 100      *
 101      * @param url       the URL being accessed
 102      * @param useCache  whether the cached connection should be used
 103      *                  if present
 104      */
 105     protected void setNewClient(URL url, boolean useCache)
 106             throws IOException {
 107         delegate.setNewClient(url, useCache);


 202     /**
 203      * Returns the principal the client sent to the
 204      * server, or null if the client did not authenticate.
 205      */
 206     public Principal getLocalPrincipal()
 207     {
 208         return delegate.getLocalPrincipal();
 209     }
 210 
 211     /*
 212      * Allowable input/output sequences:
 213      * [interpreted as POST/PUT]
 214      * - get output, [write output,] get input, [read input]
 215      * - get output, [write output]
 216      * [interpreted as GET]
 217      * - get input, [read input]
 218      * Disallowed:
 219      * - get input, [read input,] get output, [write output]
 220      */
 221 
 222     public synchronized OutputStream getOutputStream() throws IOException {
 223         return delegate.getOutputStream();
 224     }
 225 
 226     public synchronized InputStream getInputStream() throws IOException {
 227         return delegate.getInputStream();
 228     }
 229 
 230     public InputStream getErrorStream() {
 231         return delegate.getErrorStream();
 232     }
 233 
 234     /**
 235      * Disconnect from the server.
 236      */
 237     public void disconnect() {
 238         delegate.disconnect();
 239     }
 240 
 241     public boolean usingProxy() {
 242         return delegate.usingProxy();
 243     }
 244 
 245     /**
 246      * Returns an unmodifiable Map of the header fields.


< prev index next >