author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 44534 | jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java@a076dffbc2c1 |
child 47411 | 45a84b0b59b9 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
44534 | 2 |
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
* NOTE: This class lives in the package sun.net.www.protocol.https. |
|
28 |
* There is a copy in com.sun.net.ssl.internal.www.protocol.https for JSSE |
|
29 |
* 1.0.2 compatibility. It is 100% identical except the package and extends |
|
30 |
* lines. Any changes should be made to be class in sun.net.* and then copied |
|
31 |
* to com.sun.net.*. |
|
32 |
*/ |
|
33 |
||
34 |
// For both copies of the file, uncomment one line and comment the other |
|
35 |
package sun.net.www.protocol.https; |
|
36 |
// package com.sun.net.ssl.internal.www.protocol.https; |
|
37 |
||
38 |
import java.net.URL; |
|
39 |
import java.net.Proxy; |
|
40 |
import java.net.ProtocolException; |
|
41 |
import java.io.*; |
|
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
29615
diff
changeset
|
42 |
import java.net.Authenticator; |
2 | 43 |
import javax.net.ssl.*; |
44 |
import java.security.Permission; |
|
45 |
import java.security.Principal; |
|
46 |
import java.util.Map; |
|
47 |
import java.util.List; |
|
48 |
import sun.net.www.http.HttpClient; |
|
49 |
||
50 |
/** |
|
51 |
* A class to represent an HTTP connection to a remote object. |
|
52 |
* |
|
53 |
* Ideally, this class should subclass and inherit the http handler |
|
54 |
* implementation, but it can't do so because that class have the |
|
55 |
* wrong Java Type. Thus it uses the delegate (aka, the |
|
56 |
* Adapter/Wrapper design pattern) to reuse code from the http |
|
57 |
* handler. |
|
58 |
* |
|
59 |
* Since it would use a delegate to access |
|
60 |
* sun.net.www.protocol.http.HttpURLConnection functionalities, it |
|
61 |
* needs to implement all public methods in it's super class and all |
|
62 |
* the way to Object. |
|
63 |
* |
|
64 |
*/ |
|
65 |
||
66 |
// For both copies of the file, uncomment one line and comment the |
|
67 |
// other. The differences between the two copies are introduced for |
|
68 |
// plugin, and it is marked as such. |
|
69 |
public class HttpsURLConnectionImpl |
|
70 |
extends javax.net.ssl.HttpsURLConnection { |
|
71 |
// public class HttpsURLConnectionOldImpl |
|
72 |
// extends com.sun.net.ssl.HttpsURLConnection { |
|
73 |
||
74 |
// NOTE: made protected for plugin so that subclass can set it. |
|
75 |
protected DelegateHttpsURLConnection delegate; |
|
76 |
||
77 |
// For both copies of the file, uncomment one line and comment the other |
|
78 |
HttpsURLConnectionImpl(URL u, Handler handler) throws IOException { |
|
79 |
// HttpsURLConnectionOldImpl(URL u, Handler handler) throws IOException { |
|
80 |
this(u, null, handler); |
|
81 |
} |
|
82 |
||
83 |
// For both copies of the file, uncomment one line and comment the other |
|
84 |
HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException { |
|
85 |
// HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException { |
|
86 |
super(u); |
|
87 |
delegate = new DelegateHttpsURLConnection(url, p, handler, this); |
|
88 |
} |
|
89 |
||
90 |
// NOTE: introduced for plugin |
|
91 |
// subclass needs to overwrite this to set delegate to |
|
92 |
// the appropriate delegatee |
|
93 |
protected HttpsURLConnectionImpl(URL u) throws IOException { |
|
94 |
super(u); |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Create a new HttpClient object, bypassing the cache of |
|
99 |
* HTTP client objects/connections. |
|
100 |
* |
|
101 |
* @param url the URL being accessed |
|
102 |
*/ |
|
103 |
protected void setNewClient(URL url) throws IOException { |
|
104 |
delegate.setNewClient(url, false); |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Obtain a HttpClient object. Use the cached copy if specified. |
|
109 |
* |
|
110 |
* @param url the URL being accessed |
|
111 |
* @param useCache whether the cached connection should be used |
|
112 |
* if present |
|
113 |
*/ |
|
114 |
protected void setNewClient(URL url, boolean useCache) |
|
115 |
throws IOException { |
|
116 |
delegate.setNewClient(url, useCache); |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
* Create a new HttpClient object, set up so that it uses |
|
121 |
* per-instance proxying to the given HTTP proxy. This |
|
122 |
* bypasses the cache of HTTP client objects/connections. |
|
123 |
* |
|
124 |
* @param url the URL being accessed |
|
125 |
* @param proxyHost the proxy host to use |
|
126 |
* @param proxyPort the proxy port to use |
|
127 |
*/ |
|
128 |
protected void setProxiedClient(URL url, String proxyHost, int proxyPort) |
|
129 |
throws IOException { |
|
130 |
delegate.setProxiedClient(url, proxyHost, proxyPort); |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Obtain a HttpClient object, set up so that it uses per-instance |
|
135 |
* proxying to the given HTTP proxy. Use the cached copy of HTTP |
|
136 |
* client objects/connections if specified. |
|
137 |
* |
|
138 |
* @param url the URL being accessed |
|
139 |
* @param proxyHost the proxy host to use |
|
140 |
* @param proxyPort the proxy port to use |
|
141 |
* @param useCache whether the cached connection should be used |
|
142 |
* if present |
|
143 |
*/ |
|
144 |
protected void setProxiedClient(URL url, String proxyHost, int proxyPort, |
|
145 |
boolean useCache) throws IOException { |
|
146 |
delegate.setProxiedClient(url, proxyHost, proxyPort, useCache); |
|
147 |
} |
|
148 |
||
149 |
/** |
|
150 |
* Implements the HTTP protocol handler's "connect" method, |
|
151 |
* establishing an SSL connection to the server as necessary. |
|
152 |
*/ |
|
153 |
public void connect() throws IOException { |
|
154 |
delegate.connect(); |
|
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Used by subclass to access "connected" variable. Since we are |
|
159 |
* delegating the actual implementation to "delegate", we need to |
|
160 |
* delegate the access of "connected" as well. |
|
161 |
*/ |
|
162 |
protected boolean isConnected() { |
|
163 |
return delegate.isConnected(); |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
* Used by subclass to access "connected" variable. Since we are |
|
168 |
* delegating the actual implementation to "delegate", we need to |
|
169 |
* delegate the access of "connected" as well. |
|
170 |
*/ |
|
171 |
protected void setConnected(boolean conn) { |
|
172 |
delegate.setConnected(conn); |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Returns the cipher suite in use on this connection. |
|
177 |
*/ |
|
178 |
public String getCipherSuite() { |
|
179 |
return delegate.getCipherSuite(); |
|
180 |
} |
|
181 |
||
182 |
/** |
|
183 |
* Returns the certificate chain the client sent to the |
|
184 |
* server, or null if the client did not authenticate. |
|
185 |
*/ |
|
186 |
public java.security.cert.Certificate [] |
|
187 |
getLocalCertificates() { |
|
188 |
return delegate.getLocalCertificates(); |
|
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
* Returns the server's certificate chain, or throws |
|
193 |
* SSLPeerUnverified Exception if |
|
194 |
* the server did not authenticate. |
|
195 |
*/ |
|
196 |
public java.security.cert.Certificate [] |
|
197 |
getServerCertificates() throws SSLPeerUnverifiedException { |
|
198 |
return delegate.getServerCertificates(); |
|
199 |
} |
|
200 |
||
201 |
/** |
|
202 |
* Returns the principal with which the server authenticated itself, |
|
203 |
* or throw a SSLPeerUnverifiedException if the server did not authenticate. |
|
204 |
*/ |
|
205 |
public Principal getPeerPrincipal() |
|
206 |
throws SSLPeerUnverifiedException |
|
207 |
{ |
|
208 |
return delegate.getPeerPrincipal(); |
|
209 |
} |
|
210 |
||
211 |
/** |
|
212 |
* Returns the principal the client sent to the |
|
213 |
* server, or null if the client did not authenticate. |
|
214 |
*/ |
|
215 |
public Principal getLocalPrincipal() |
|
216 |
{ |
|
217 |
return delegate.getLocalPrincipal(); |
|
218 |
} |
|
219 |
||
220 |
/* |
|
221 |
* Allowable input/output sequences: |
|
222 |
* [interpreted as POST/PUT] |
|
223 |
* - get output, [write output,] get input, [read input] |
|
224 |
* - get output, [write output] |
|
225 |
* [interpreted as GET] |
|
226 |
* - get input, [read input] |
|
227 |
* Disallowed: |
|
228 |
* - get input, [read input,] get output, [write output] |
|
229 |
*/ |
|
230 |
||
231 |
public synchronized OutputStream getOutputStream() throws IOException { |
|
232 |
return delegate.getOutputStream(); |
|
233 |
} |
|
234 |
||
235 |
public synchronized InputStream getInputStream() throws IOException { |
|
236 |
return delegate.getInputStream(); |
|
237 |
} |
|
238 |
||
239 |
public InputStream getErrorStream() { |
|
240 |
return delegate.getErrorStream(); |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Disconnect from the server. |
|
245 |
*/ |
|
246 |
public void disconnect() { |
|
247 |
delegate.disconnect(); |
|
248 |
} |
|
249 |
||
250 |
public boolean usingProxy() { |
|
251 |
return delegate.usingProxy(); |
|
252 |
} |
|
253 |
||
254 |
/** |
|
255 |
* Returns an unmodifiable Map of the header fields. |
|
256 |
* The Map keys are Strings that represent the |
|
257 |
* response-header field names. Each Map value is an |
|
258 |
* unmodifiable List of Strings that represents |
|
259 |
* the corresponding field values. |
|
260 |
* |
|
261 |
* @return a Map of header fields |
|
262 |
* @since 1.4 |
|
263 |
*/ |
|
264 |
public Map<String,List<String>> getHeaderFields() { |
|
265 |
return delegate.getHeaderFields(); |
|
266 |
} |
|
267 |
||
268 |
/** |
|
269 |
* Gets a header field by name. Returns null if not known. |
|
270 |
* @param name the name of the header field |
|
271 |
*/ |
|
272 |
public String getHeaderField(String name) { |
|
273 |
return delegate.getHeaderField(name); |
|
274 |
} |
|
275 |
||
276 |
/** |
|
277 |
* Gets a header field by index. Returns null if not known. |
|
278 |
* @param n the index of the header field |
|
279 |
*/ |
|
280 |
public String getHeaderField(int n) { |
|
281 |
return delegate.getHeaderField(n); |
|
282 |
} |
|
283 |
||
284 |
/** |
|
285 |
* Gets a header field by index. Returns null if not known. |
|
286 |
* @param n the index of the header field |
|
287 |
*/ |
|
288 |
public String getHeaderFieldKey(int n) { |
|
289 |
return delegate.getHeaderFieldKey(n); |
|
290 |
} |
|
291 |
||
292 |
/** |
|
293 |
* Sets request property. If a property with the key already |
|
294 |
* exists, overwrite its value with the new value. |
|
295 |
* @param value the value to be set |
|
296 |
*/ |
|
297 |
public void setRequestProperty(String key, String value) { |
|
298 |
delegate.setRequestProperty(key, value); |
|
299 |
} |
|
300 |
||
301 |
/** |
|
302 |
* Adds a general request property specified by a |
|
303 |
* key-value pair. This method will not overwrite |
|
304 |
* existing values associated with the same key. |
|
305 |
* |
|
306 |
* @param key the keyword by which the request is known |
|
307 |
* (e.g., "<code>accept</code>"). |
|
308 |
* @param value the value associated with it. |
|
309 |
* @see #getRequestProperties(java.lang.String) |
|
310 |
* @since 1.4 |
|
311 |
*/ |
|
312 |
public void addRequestProperty(String key, String value) { |
|
313 |
delegate.addRequestProperty(key, value); |
|
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* Overwrite super class method |
|
318 |
*/ |
|
319 |
public int getResponseCode() throws IOException { |
|
320 |
return delegate.getResponseCode(); |
|
321 |
} |
|
322 |
||
323 |
public String getRequestProperty(String key) { |
|
324 |
return delegate.getRequestProperty(key); |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
* Returns an unmodifiable Map of general request |
|
329 |
* properties for this connection. The Map keys |
|
330 |
* are Strings that represent the request-header |
|
331 |
* field names. Each Map value is a unmodifiable List |
|
332 |
* of Strings that represents the corresponding |
|
333 |
* field values. |
|
334 |
* |
|
335 |
* @return a Map of the general request properties for this connection. |
|
336 |
* @throws IllegalStateException if already connected |
|
337 |
* @since 1.4 |
|
338 |
*/ |
|
339 |
public Map<String,List<String>> getRequestProperties() { |
|
340 |
return delegate.getRequestProperties(); |
|
341 |
} |
|
342 |
||
343 |
/* |
|
344 |
* We support JDK 1.2.x so we can't count on these from JDK 1.3. |
|
345 |
* We override and supply our own version. |
|
346 |
*/ |
|
347 |
public void setInstanceFollowRedirects(boolean shouldFollow) { |
|
348 |
delegate.setInstanceFollowRedirects(shouldFollow); |
|
349 |
} |
|
350 |
||
351 |
public boolean getInstanceFollowRedirects() { |
|
352 |
return delegate.getInstanceFollowRedirects(); |
|
353 |
} |
|
354 |
||
355 |
public void setRequestMethod(String method) throws ProtocolException { |
|
356 |
delegate.setRequestMethod(method); |
|
357 |
} |
|
358 |
||
359 |
public String getRequestMethod() { |
|
360 |
return delegate.getRequestMethod(); |
|
361 |
} |
|
362 |
||
363 |
public String getResponseMessage() throws IOException { |
|
364 |
return delegate.getResponseMessage(); |
|
365 |
} |
|
366 |
||
367 |
public long getHeaderFieldDate(String name, long Default) { |
|
368 |
return delegate.getHeaderFieldDate(name, Default); |
|
369 |
} |
|
370 |
||
371 |
public Permission getPermission() throws IOException { |
|
372 |
return delegate.getPermission(); |
|
373 |
} |
|
374 |
||
375 |
public URL getURL() { |
|
376 |
return delegate.getURL(); |
|
377 |
} |
|
378 |
||
379 |
public int getContentLength() { |
|
380 |
return delegate.getContentLength(); |
|
381 |
} |
|
382 |
||
383 |
public long getContentLengthLong() { |
|
384 |
return delegate.getContentLengthLong(); |
|
385 |
} |
|
386 |
||
387 |
public String getContentType() { |
|
388 |
return delegate.getContentType(); |
|
389 |
} |
|
390 |
||
391 |
public String getContentEncoding() { |
|
392 |
return delegate.getContentEncoding(); |
|
393 |
} |
|
394 |
||
395 |
public long getExpiration() { |
|
396 |
return delegate.getExpiration(); |
|
397 |
} |
|
398 |
||
399 |
public long getDate() { |
|
400 |
return delegate.getDate(); |
|
401 |
} |
|
402 |
||
403 |
public long getLastModified() { |
|
404 |
return delegate.getLastModified(); |
|
405 |
} |
|
406 |
||
407 |
public int getHeaderFieldInt(String name, int Default) { |
|
408 |
return delegate.getHeaderFieldInt(name, Default); |
|
409 |
} |
|
410 |
||
411 |
public long getHeaderFieldLong(String name, long Default) { |
|
412 |
return delegate.getHeaderFieldLong(name, Default); |
|
413 |
} |
|
414 |
||
415 |
public Object getContent() throws IOException { |
|
416 |
return delegate.getContent(); |
|
417 |
} |
|
418 |
||
20754 | 419 |
@SuppressWarnings("rawtypes") |
2 | 420 |
public Object getContent(Class[] classes) throws IOException { |
421 |
return delegate.getContent(classes); |
|
422 |
} |
|
423 |
||
424 |
public String toString() { |
|
425 |
return delegate.toString(); |
|
426 |
} |
|
427 |
||
428 |
public void setDoInput(boolean doinput) { |
|
429 |
delegate.setDoInput(doinput); |
|
430 |
} |
|
431 |
||
432 |
public boolean getDoInput() { |
|
433 |
return delegate.getDoInput(); |
|
434 |
} |
|
435 |
||
436 |
public void setDoOutput(boolean dooutput) { |
|
437 |
delegate.setDoOutput(dooutput); |
|
438 |
} |
|
439 |
||
440 |
public boolean getDoOutput() { |
|
441 |
return delegate.getDoOutput(); |
|
442 |
} |
|
443 |
||
444 |
public void setAllowUserInteraction(boolean allowuserinteraction) { |
|
445 |
delegate.setAllowUserInteraction(allowuserinteraction); |
|
446 |
} |
|
447 |
||
448 |
public boolean getAllowUserInteraction() { |
|
449 |
return delegate.getAllowUserInteraction(); |
|
450 |
} |
|
451 |
||
452 |
public void setUseCaches(boolean usecaches) { |
|
453 |
delegate.setUseCaches(usecaches); |
|
454 |
} |
|
455 |
||
456 |
public boolean getUseCaches() { |
|
457 |
return delegate.getUseCaches(); |
|
458 |
} |
|
459 |
||
460 |
public void setIfModifiedSince(long ifmodifiedsince) { |
|
461 |
delegate.setIfModifiedSince(ifmodifiedsince); |
|
462 |
} |
|
463 |
||
464 |
public long getIfModifiedSince() { |
|
465 |
return delegate.getIfModifiedSince(); |
|
466 |
} |
|
467 |
||
468 |
public boolean getDefaultUseCaches() { |
|
469 |
return delegate.getDefaultUseCaches(); |
|
470 |
} |
|
471 |
||
472 |
public void setDefaultUseCaches(boolean defaultusecaches) { |
|
473 |
delegate.setDefaultUseCaches(defaultusecaches); |
|
474 |
} |
|
475 |
||
476 |
/* |
|
477 |
* finalize (dispose) the delegated object. Otherwise |
|
478 |
* sun.net.www.protocol.http.HttpURLConnection's finalize() |
|
479 |
* would have to be made public. |
|
480 |
*/ |
|
44534 | 481 |
@SuppressWarnings("deprecation") |
2 | 482 |
protected void finalize() throws Throwable { |
483 |
delegate.dispose(); |
|
484 |
} |
|
485 |
||
486 |
public boolean equals(Object obj) { |
|
26221 | 487 |
return this == obj || ((obj instanceof HttpsURLConnectionImpl) && |
488 |
delegate.equals(((HttpsURLConnectionImpl)obj).delegate)); |
|
2 | 489 |
} |
490 |
||
491 |
public int hashCode() { |
|
492 |
return delegate.hashCode(); |
|
493 |
} |
|
494 |
||
495 |
public void setConnectTimeout(int timeout) { |
|
496 |
delegate.setConnectTimeout(timeout); |
|
497 |
} |
|
498 |
||
499 |
public int getConnectTimeout() { |
|
500 |
return delegate.getConnectTimeout(); |
|
501 |
} |
|
502 |
||
503 |
public void setReadTimeout(int timeout) { |
|
504 |
delegate.setReadTimeout(timeout); |
|
505 |
} |
|
506 |
||
507 |
public int getReadTimeout() { |
|
508 |
return delegate.getReadTimeout(); |
|
509 |
} |
|
510 |
||
511 |
public void setFixedLengthStreamingMode (int contentLength) { |
|
512 |
delegate.setFixedLengthStreamingMode(contentLength); |
|
513 |
} |
|
514 |
||
1576
b697b141012d
6755625: Add HttpURLConnection.setFixedLengthStreamingMode(long)
chegar
parents:
2
diff
changeset
|
515 |
public void setFixedLengthStreamingMode(long contentLength) { |
b697b141012d
6755625: Add HttpURLConnection.setFixedLengthStreamingMode(long)
chegar
parents:
2
diff
changeset
|
516 |
delegate.setFixedLengthStreamingMode(contentLength); |
b697b141012d
6755625: Add HttpURLConnection.setFixedLengthStreamingMode(long)
chegar
parents:
2
diff
changeset
|
517 |
} |
b697b141012d
6755625: Add HttpURLConnection.setFixedLengthStreamingMode(long)
chegar
parents:
2
diff
changeset
|
518 |
|
2 | 519 |
public void setChunkedStreamingMode (int chunklen) { |
520 |
delegate.setChunkedStreamingMode(chunklen); |
|
521 |
} |
|
42351
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
29615
diff
changeset
|
522 |
|
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
29615
diff
changeset
|
523 |
@Override |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
29615
diff
changeset
|
524 |
public void setAuthenticator(Authenticator auth) { |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
29615
diff
changeset
|
525 |
delegate.setAuthenticator(auth); |
85ed90be0ae1
8169495: Add a method to set an Authenticator on a HttpURLConnection.
dfuchs
parents:
29615
diff
changeset
|
526 |
} |
2 | 527 |
} |