author | mbaesken |
Thu, 28 Nov 2019 13:02:39 +0100 | |
changeset 59323 | ae2eb76c486d |
parent 51364 | 31d9e82b2e64 |
child 56868 | 67c7659ecda5 |
permissions | -rw-r--r-- |
48083 | 1 |
/* |
49765 | 2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
48083 | 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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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 |
||
49765 | 26 |
package jdk.internal.net.http; |
48083 | 27 |
|
28 |
import java.io.IOException; |
|
29 |
import java.lang.ref.Reference; |
|
30 |
import java.net.Authenticator; |
|
31 |
import java.net.CookieHandler; |
|
32 |
import java.net.ProxySelector; |
|
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49765
diff
changeset
|
33 |
import java.time.Duration; |
48083 | 34 |
import java.util.Optional; |
35 |
import java.util.concurrent.CompletableFuture; |
|
36 |
import java.util.concurrent.Executor; |
|
37 |
import javax.net.ssl.SSLContext; |
|
38 |
import javax.net.ssl.SSLParameters; |
|
49765 | 39 |
import java.net.http.HttpClient; |
40 |
import java.net.http.HttpRequest; |
|
41 |
import java.net.http.HttpResponse; |
|
42 |
import java.net.http.HttpResponse.BodyHandler; |
|
43 |
import java.net.http.HttpResponse.PushPromiseHandler; |
|
44 |
import java.net.http.WebSocket; |
|
45 |
import jdk.internal.net.http.common.OperationTrackers.Trackable; |
|
46 |
import jdk.internal.net.http.common.OperationTrackers.Tracker; |
|
48083 | 47 |
|
48 |
/** |
|
49 |
* An HttpClientFacade is a simple class that wraps an HttpClient implementation |
|
50 |
* and delegates everything to its implementation delegate. |
|
51 |
*/ |
|
49765 | 52 |
final class HttpClientFacade extends HttpClient implements Trackable { |
48083 | 53 |
|
54 |
final HttpClientImpl impl; |
|
55 |
||
56 |
/** |
|
57 |
* Creates an HttpClientFacade. |
|
58 |
*/ |
|
59 |
HttpClientFacade(HttpClientImpl impl) { |
|
60 |
this.impl = impl; |
|
61 |
} |
|
62 |
||
49765 | 63 |
@Override // for tests |
64 |
public Tracker getOperationsTracker() { |
|
65 |
return impl.getOperationsTracker(); |
|
66 |
} |
|
67 |
||
48083 | 68 |
@Override |
69 |
public Optional<CookieHandler> cookieHandler() { |
|
70 |
return impl.cookieHandler(); |
|
71 |
} |
|
72 |
||
73 |
@Override |
|
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49765
diff
changeset
|
74 |
public Optional<Duration> connectTimeout() { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49765
diff
changeset
|
75 |
return impl.connectTimeout(); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49765
diff
changeset
|
76 |
} |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49765
diff
changeset
|
77 |
|
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49765
diff
changeset
|
78 |
@Override |
48083 | 79 |
public Redirect followRedirects() { |
80 |
return impl.followRedirects(); |
|
81 |
} |
|
82 |
||
83 |
@Override |
|
84 |
public Optional<ProxySelector> proxy() { |
|
85 |
return impl.proxy(); |
|
86 |
} |
|
87 |
||
88 |
@Override |
|
89 |
public SSLContext sslContext() { |
|
90 |
return impl.sslContext(); |
|
91 |
} |
|
92 |
||
93 |
@Override |
|
94 |
public SSLParameters sslParameters() { |
|
95 |
return impl.sslParameters(); |
|
96 |
} |
|
97 |
||
98 |
@Override |
|
99 |
public Optional<Authenticator> authenticator() { |
|
100 |
return impl.authenticator(); |
|
101 |
} |
|
102 |
||
103 |
@Override |
|
104 |
public HttpClient.Version version() { |
|
105 |
return impl.version(); |
|
106 |
} |
|
107 |
||
108 |
@Override |
|
109 |
public Optional<Executor> executor() { |
|
110 |
return impl.executor(); |
|
111 |
} |
|
112 |
||
113 |
@Override |
|
114 |
public <T> HttpResponse<T> |
|
115 |
send(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler) |
|
116 |
throws IOException, InterruptedException |
|
117 |
{ |
|
118 |
try { |
|
119 |
return impl.send(req, responseBodyHandler); |
|
120 |
} finally { |
|
121 |
Reference.reachabilityFence(this); |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
@Override |
|
126 |
public <T> CompletableFuture<HttpResponse<T>> |
|
127 |
sendAsync(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler) { |
|
128 |
try { |
|
129 |
return impl.sendAsync(req, responseBodyHandler); |
|
130 |
} finally { |
|
131 |
Reference.reachabilityFence(this); |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
@Override |
|
49765 | 136 |
public <T> CompletableFuture<HttpResponse<T>> |
137 |
sendAsync(HttpRequest req, |
|
138 |
BodyHandler<T> responseBodyHandler, |
|
139 |
PushPromiseHandler<T> pushPromiseHandler){ |
|
48083 | 140 |
try { |
49765 | 141 |
return impl.sendAsync(req, responseBodyHandler, pushPromiseHandler); |
48083 | 142 |
} finally { |
143 |
Reference.reachabilityFence(this); |
|
144 |
} |
|
145 |
} |
|
146 |
||
147 |
@Override |
|
148 |
public WebSocket.Builder newWebSocketBuilder() { |
|
149 |
try { |
|
150 |
return impl.newWebSocketBuilder(); |
|
151 |
} finally { |
|
152 |
Reference.reachabilityFence(this); |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
@Override |
|
157 |
public String toString() { |
|
158 |
// Used by tests to get the client's id. |
|
159 |
return impl.toString(); |
|
160 |
} |
|
161 |
} |