author | dfuchs |
Tue, 15 Jan 2019 11:34:20 +0000 | |
changeset 53300 | 54aa3ea04fe8 |
parent 52196 | 420445d16008 |
child 53387 | c9622e15ba29 |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
53300
54aa3ea04fe8
8216974: HttpConnection not returned to the pool after 204 response
dfuchs
parents:
52196
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
4 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
10 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
15 |
* accompanied this code). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
16 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
20 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
23 |
* questions. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
24 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
|
49765 | 26 |
package jdk.internal.net.http; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
27 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
28 |
import java.io.IOException; |
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
29 |
import java.io.UncheckedIOException; |
50681 | 30 |
import java.net.ConnectException; |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
31 |
import java.net.http.HttpConnectTimeoutException; |
49765 | 32 |
import java.util.Iterator; |
33 |
import java.util.LinkedList; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
34 |
import java.security.AccessControlContext; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
35 |
import java.util.concurrent.CompletableFuture; |
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
36 |
import java.util.concurrent.CompletionStage; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
import java.util.concurrent.CompletionException; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
38 |
import java.util.concurrent.ExecutionException; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
39 |
import java.util.concurrent.Executor; |
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
40 |
import java.util.concurrent.Flow; |
48083 | 41 |
import java.util.concurrent.atomic.AtomicInteger; |
42 |
import java.util.function.Function; |
|
49765 | 43 |
|
44 |
import java.net.http.HttpClient; |
|
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
45 |
import java.net.http.HttpHeaders; |
49765 | 46 |
import java.net.http.HttpRequest; |
47 |
import java.net.http.HttpResponse; |
|
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
48 |
import java.net.http.HttpResponse.BodySubscriber; |
49765 | 49 |
import java.net.http.HttpResponse.PushPromiseHandler; |
50 |
import java.net.http.HttpTimeoutException; |
|
51 |
import jdk.internal.net.http.common.Log; |
|
52 |
import jdk.internal.net.http.common.Logger; |
|
53 |
import jdk.internal.net.http.common.MinimalFuture; |
|
54 |
import jdk.internal.net.http.common.ConnectionExpiredException; |
|
55 |
import jdk.internal.net.http.common.Utils; |
|
56 |
import static jdk.internal.net.http.common.MinimalFuture.completedFuture; |
|
57 |
import static jdk.internal.net.http.common.MinimalFuture.failedFuture; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
58 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
59 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
60 |
* Encapsulates multiple Exchanges belonging to one HttpRequestImpl. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
61 |
* - manages filters |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
62 |
* - retries due to filters. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
63 |
* - I/O errors and most other exceptions get returned directly to user |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
64 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
65 |
* Creates a new Exchange for each request/response interaction |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
66 |
*/ |
49765 | 67 |
class MultiExchange<T> { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
68 |
|
49765 | 69 |
static final Logger debug = |
70 |
Utils.getDebugLogger("MultiExchange"::toString, Utils.DEBUG); |
|
48083 | 71 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
72 |
private final HttpRequest userRequest; // the user request |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
73 |
private final HttpRequestImpl request; // a copy of the user request |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
74 |
final AccessControlContext acc; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
75 |
final HttpClientImpl client; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
76 |
final HttpResponse.BodyHandler<T> responseHandler; |
50681 | 77 |
final HttpClientImpl.DelegatingExecutor executor; |
48083 | 78 |
final AtomicInteger attempts = new AtomicInteger(); |
49765 | 79 |
HttpRequestImpl currentreq; // used for retries & redirect |
80 |
HttpRequestImpl previousreq; // used for retries & redirect |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
81 |
Exchange<T> exchange; // the current exchange |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
82 |
Exchange<T> previous; |
48083 | 83 |
volatile Throwable retryCause; |
84 |
volatile boolean expiredOnce; |
|
85 |
volatile HttpResponse<T> response = null; |
|
86 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
87 |
// Maximum number of times a request will be retried/redirected |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
88 |
// for any reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
89 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
90 |
static final int DEFAULT_MAX_ATTEMPTS = 5; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
91 |
static final int max_attempts = Utils.getIntegerNetProperty( |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
92 |
"jdk.httpclient.redirects.retrylimit", DEFAULT_MAX_ATTEMPTS |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
93 |
); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
94 |
|
49765 | 95 |
private final LinkedList<HeaderFilter> filters; |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
96 |
ResponseTimerEvent responseTimerEvent; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
97 |
volatile boolean cancelled; |
49765 | 98 |
final PushGroup<T> pushGroup; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
99 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
100 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
101 |
* Filter fields. These are attached as required by filters |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
102 |
* and only used by the filter implementations. This could be |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
103 |
* generalised into Objects that are passed explicitly to the filters |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
104 |
* (one per MultiExchange object, and one per Exchange object possibly) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
105 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
106 |
volatile AuthenticationFilter.AuthInfo serverauth, proxyauth; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
107 |
// RedirectHandler |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
108 |
volatile int numberOfRedirects = 0; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
109 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
110 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
111 |
* MultiExchange with one final response. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
112 |
*/ |
48083 | 113 |
MultiExchange(HttpRequest userRequest, |
114 |
HttpRequestImpl requestImpl, |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
115 |
HttpClientImpl client, |
48083 | 116 |
HttpResponse.BodyHandler<T> responseHandler, |
49765 | 117 |
PushPromiseHandler<T> pushPromiseHandler, |
48083 | 118 |
AccessControlContext acc) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
119 |
this.previous = null; |
48083 | 120 |
this.userRequest = userRequest; |
121 |
this.request = requestImpl; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
122 |
this.currentreq = request; |
49765 | 123 |
this.previousreq = null; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
124 |
this.client = client; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
125 |
this.filters = client.filterChain(); |
48083 | 126 |
this.acc = acc; |
127 |
this.executor = client.theExecutor(); |
|
128 |
this.responseHandler = responseHandler; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
129 |
|
49765 | 130 |
if (pushPromiseHandler != null) { |
131 |
Executor executor = acc == null |
|
50681 | 132 |
? this.executor.delegate() |
133 |
: new PrivilegedExecutor(this.executor.delegate(), acc); |
|
49765 | 134 |
this.pushGroup = new PushGroup<>(pushPromiseHandler, request, executor); |
135 |
} else { |
|
136 |
pushGroup = null; |
|
137 |
} |
|
138 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
139 |
this.exchange = new Exchange<>(request, this); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
140 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
141 |
|
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
142 |
synchronized Exchange<T> getExchange() { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
143 |
return exchange; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
144 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
145 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
146 |
HttpClientImpl client() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
147 |
return client; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
148 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
149 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
150 |
HttpClient.Version version() { |
49765 | 151 |
HttpClient.Version vers = request.version().orElse(client.version()); |
152 |
if (vers == HttpClient.Version.HTTP_2 && !request.secure() && request.proxy() != null) |
|
153 |
vers = HttpClient.Version.HTTP_1_1; |
|
154 |
return vers; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
155 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
156 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
157 |
private synchronized void setExchange(Exchange<T> exchange) { |
48083 | 158 |
if (this.exchange != null && exchange != this.exchange) { |
159 |
this.exchange.released(); |
|
160 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
161 |
this.exchange = exchange; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
162 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
163 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
164 |
private void cancelTimer() { |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
165 |
if (responseTimerEvent != null) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
166 |
client.cancelTimer(responseTimerEvent); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
167 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
168 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
169 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
170 |
private void requestFilters(HttpRequestImpl r) throws IOException { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
171 |
Log.logTrace("Applying request filters"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
172 |
for (HeaderFilter filter : filters) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
173 |
Log.logTrace("Applying {0}", filter); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
174 |
filter.request(r, this); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
175 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
176 |
Log.logTrace("All filters applied"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
177 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
178 |
|
43984 | 179 |
private HttpRequestImpl responseFilters(Response response) throws IOException |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
180 |
{ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
181 |
Log.logTrace("Applying response filters"); |
49765 | 182 |
Iterator<HeaderFilter> reverseItr = filters.descendingIterator(); |
183 |
while (reverseItr.hasNext()) { |
|
184 |
HeaderFilter filter = reverseItr.next(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
185 |
Log.logTrace("Applying {0}", filter); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
186 |
HttpRequestImpl newreq = filter.response(response); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
187 |
if (newreq != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
188 |
Log.logTrace("New request: stopping filters"); |
43984 | 189 |
return newreq; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
190 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
191 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
192 |
Log.logTrace("All filters applied"); |
43984 | 193 |
return null; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
194 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
195 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
196 |
public void cancel(IOException cause) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
197 |
cancelled = true; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
198 |
getExchange().cancel(cause); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
199 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
200 |
|
50681 | 201 |
public CompletableFuture<HttpResponse<T>> responseAsync(Executor executor) { |
43984 | 202 |
CompletableFuture<Void> start = new MinimalFuture<>(); |
48083 | 203 |
CompletableFuture<HttpResponse<T>> cf = responseAsync0(start); |
43984 | 204 |
start.completeAsync( () -> null, executor); // trigger execution |
205 |
return cf; |
|
206 |
} |
|
207 |
||
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
208 |
// return true if the response is a type where a response body is never possible |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
209 |
// and therefore doesn't have to include header information which indicates no |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
210 |
// body is present. This is distinct from responses that also do not contain |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
211 |
// response bodies (possibly ever) but which are required to have content length |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
212 |
// info in the header (eg 205). Those cases do not have to be handled specially |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
213 |
|
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
214 |
private static boolean bodyNotPermitted(Response r) { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
215 |
return r.statusCode == 204; |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
216 |
} |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
217 |
|
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
218 |
private boolean bodyIsPresent(Response r) { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
219 |
HttpHeaders headers = r.headers(); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
220 |
if (headers.firstValue("Content-length").isPresent()) |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
221 |
return true; |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
222 |
if (headers.firstValue("Transfer-encoding").isPresent()) |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
223 |
return true; |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
224 |
return false; |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
225 |
} |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
226 |
|
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
227 |
// Call the user's body handler to get an empty body object |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
228 |
|
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
229 |
private CompletableFuture<HttpResponse<T>> handleNoBody(Response r, Exchange<T> exch) { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
230 |
BodySubscriber<T> bs = responseHandler.apply(new ResponseInfoImpl(r.statusCode(), |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
231 |
r.headers(), r.version())); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
232 |
CompletionStage<T> cs = bs.getBody(); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
233 |
bs.onSubscribe(new NullSubscription()); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
234 |
bs.onComplete(); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
235 |
MinimalFuture<HttpResponse<T>> result = new MinimalFuture<>(); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
236 |
cs.whenComplete((nullBody, exception) -> { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
237 |
if (exception != null) |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
238 |
result.completeExceptionally(exception); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
239 |
else { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
240 |
this.response = |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
241 |
new HttpResponseImpl<>(r.request(), r, this.response, nullBody, exch); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
242 |
result.complete(this.response); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
243 |
} |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
244 |
}); |
53300
54aa3ea04fe8
8216974: HttpConnection not returned to the pool after 204 response
dfuchs
parents:
52196
diff
changeset
|
245 |
// ensure that the connection is closed or returned to the pool. |
54aa3ea04fe8
8216974: HttpConnection not returned to the pool after 204 response
dfuchs
parents:
52196
diff
changeset
|
246 |
return result.whenComplete(exch::nullBody); |
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
247 |
} |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
248 |
|
48083 | 249 |
private CompletableFuture<HttpResponse<T>> |
250 |
responseAsync0(CompletableFuture<Void> start) { |
|
43984 | 251 |
return start.thenCompose( v -> responseAsyncImpl()) |
48083 | 252 |
.thenCompose((Response r) -> { |
253 |
Exchange<T> exch = getExchange(); |
|
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
254 |
if (bodyNotPermitted(r)) { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
255 |
if (bodyIsPresent(r)) { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
256 |
IOException ioe = new IOException( |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
257 |
"unexpected content length header with 204 response"); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
258 |
exch.cancel(ioe); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
259 |
return MinimalFuture.failedFuture(ioe); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
260 |
} else |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
261 |
return handleNoBody(r, exch); |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
262 |
} |
48083 | 263 |
return exch.readBodyAsync(responseHandler) |
264 |
.thenApply((T body) -> { |
|
265 |
this.response = |
|
49765 | 266 |
new HttpResponseImpl<>(r.request(), r, this.response, body, exch); |
48083 | 267 |
return this.response; |
268 |
}); |
|
269 |
}); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
270 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
271 |
|
52196
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
272 |
static class NullSubscription implements Flow.Subscription { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
273 |
@Override |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
274 |
public void request(long n) { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
275 |
} |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
276 |
|
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
277 |
@Override |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
278 |
public void cancel() { |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
279 |
} |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
280 |
} |
420445d16008
8211437: java.net.http.HttpClient hangs on 204 reply without Content-length 0
michaelm
parents:
51364
diff
changeset
|
281 |
|
43984 | 282 |
private CompletableFuture<Response> responseAsyncImpl() { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
283 |
CompletableFuture<Response> cf; |
48083 | 284 |
if (attempts.incrementAndGet() > max_attempts) { |
285 |
cf = failedFuture(new IOException("Too many retries", retryCause)); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
286 |
} else { |
48083 | 287 |
if (currentreq.timeout().isPresent()) { |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
288 |
responseTimerEvent = ResponseTimerEvent.of(this); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
289 |
client.registerTimer(responseTimerEvent); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
290 |
} |
43984 | 291 |
try { |
48083 | 292 |
// 1. apply request filters |
49765 | 293 |
// if currentreq == previousreq the filters have already |
294 |
// been applied once. Applying them a second time might |
|
295 |
// cause some headers values to be added twice: for |
|
296 |
// instance, the same cookie might be added again. |
|
297 |
if (currentreq != previousreq) { |
|
298 |
requestFilters(currentreq); |
|
299 |
} |
|
43984 | 300 |
} catch (IOException e) { |
48083 | 301 |
return failedFuture(e); |
43984 | 302 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
303 |
Exchange<T> exch = getExchange(); |
43984 | 304 |
// 2. get response |
305 |
cf = exch.responseAsync() |
|
48083 | 306 |
.thenCompose((Response response) -> { |
307 |
HttpRequestImpl newrequest; |
|
308 |
try { |
|
309 |
// 3. apply response filters |
|
310 |
newrequest = responseFilters(response); |
|
311 |
} catch (IOException e) { |
|
312 |
return failedFuture(e); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
313 |
} |
48083 | 314 |
// 4. check filter result and repeat or continue |
315 |
if (newrequest == null) { |
|
316 |
if (attempts.get() > 1) { |
|
317 |
Log.logError("Succeeded on attempt: " + attempts); |
|
318 |
} |
|
319 |
return completedFuture(response); |
|
320 |
} else { |
|
321 |
this.response = |
|
322 |
new HttpResponseImpl<>(currentreq, response, this.response, null, exch); |
|
323 |
Exchange<T> oldExch = exch; |
|
324 |
return exch.ignoreBody().handle((r,t) -> { |
|
49765 | 325 |
previousreq = currentreq; |
48083 | 326 |
currentreq = newrequest; |
327 |
expiredOnce = false; |
|
328 |
setExchange(new Exchange<>(currentreq, this, acc)); |
|
329 |
return responseAsyncImpl(); |
|
330 |
}).thenCompose(Function.identity()); |
|
331 |
} }) |
|
332 |
.handle((response, ex) -> { |
|
333 |
// 5. handle errors and cancel any timer set |
|
334 |
cancelTimer(); |
|
335 |
if (ex == null) { |
|
336 |
assert response != null; |
|
337 |
return completedFuture(response); |
|
338 |
} |
|
339 |
// all exceptions thrown are handled here |
|
340 |
CompletableFuture<Response> errorCF = getExceptionalCF(ex); |
|
341 |
if (errorCF == null) { |
|
342 |
return responseAsyncImpl(); |
|
343 |
} else { |
|
344 |
return errorCF; |
|
345 |
} }) |
|
346 |
.thenCompose(Function.identity()); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
347 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
348 |
return cf; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
349 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
350 |
|
49765 | 351 |
private static boolean retryPostValue() { |
352 |
String s = Utils.getNetProperty("jdk.httpclient.enableAllMethodRetry"); |
|
50681 | 353 |
if (s == null) |
354 |
return false; |
|
355 |
return s.isEmpty() ? true : Boolean.parseBoolean(s); |
|
356 |
} |
|
357 |
||
358 |
private static boolean retryConnect() { |
|
359 |
String s = Utils.getNetProperty("jdk.httpclient.disableRetryConnect"); |
|
360 |
if (s == null) |
|
361 |
return false; |
|
362 |
return s.isEmpty() ? true : Boolean.parseBoolean(s); |
|
49765 | 363 |
} |
364 |
||
365 |
/** True if ALL ( even non-idempotent ) requests can be automatic retried. */ |
|
366 |
private static final boolean RETRY_ALWAYS = retryPostValue(); |
|
50681 | 367 |
/** True if ConnectException should cause a retry. Enabled by default */ |
368 |
private static final boolean RETRY_CONNECT = retryConnect(); |
|
49765 | 369 |
|
370 |
/** Returns true is given request has an idempotent method. */ |
|
371 |
private static boolean isIdempotentRequest(HttpRequest request) { |
|
372 |
String method = request.method(); |
|
373 |
switch (method) { |
|
374 |
case "GET" : |
|
375 |
case "HEAD" : |
|
376 |
return true; |
|
377 |
default : |
|
378 |
return false; |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
/** Returns true if the given request can be automatically retried. */ |
|
383 |
private static boolean canRetryRequest(HttpRequest request) { |
|
50681 | 384 |
if (RETRY_ALWAYS) |
385 |
return true; |
|
49765 | 386 |
if (isIdempotentRequest(request)) |
387 |
return true; |
|
388 |
return false; |
|
389 |
} |
|
390 |
||
50681 | 391 |
private boolean retryOnFailure(Throwable t) { |
392 |
return t instanceof ConnectionExpiredException |
|
393 |
|| (RETRY_CONNECT && (t instanceof ConnectException)); |
|
394 |
} |
|
395 |
||
396 |
private Throwable retryCause(Throwable t) { |
|
397 |
Throwable cause = t instanceof ConnectionExpiredException ? t.getCause() : t; |
|
398 |
return cause == null ? t : cause; |
|
399 |
} |
|
400 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
401 |
/** |
48083 | 402 |
* Takes a Throwable and returns a suitable CompletableFuture that is |
403 |
* completed exceptionally, or null. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
404 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
405 |
private CompletableFuture<Response> getExceptionalCF(Throwable t) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
406 |
if ((t instanceof CompletionException) || (t instanceof ExecutionException)) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
407 |
if (t.getCause() != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
408 |
t = t.getCause(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
409 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
410 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
411 |
if (cancelled && t instanceof IOException) { |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
412 |
if (!(t instanceof HttpTimeoutException)) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
413 |
t = toTimeoutException((IOException)t); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
414 |
} |
50681 | 415 |
} else if (retryOnFailure(t)) { |
416 |
Throwable cause = retryCause(t); |
|
49765 | 417 |
|
50681 | 418 |
if (!(t instanceof ConnectException)) { |
419 |
if (!canRetryRequest(currentreq)) { |
|
420 |
return failedFuture(cause); // fails with original cause |
|
421 |
} |
|
49765 | 422 |
} |
423 |
||
48083 | 424 |
// allow the retry mechanism to do its work |
49765 | 425 |
retryCause = cause; |
48083 | 426 |
if (!expiredOnce) { |
49765 | 427 |
if (debug.on()) |
50681 | 428 |
debug.log(t.getClass().getSimpleName() + " (async): retrying...", t); |
48083 | 429 |
expiredOnce = true; |
49765 | 430 |
// The connection was abruptly closed. |
431 |
// We return null to retry the same request a second time. |
|
432 |
// The request filters have already been applied to the |
|
433 |
// currentreq, so we set previousreq = currentreq to |
|
434 |
// prevent them from being applied again. |
|
435 |
previousreq = currentreq; |
|
48083 | 436 |
return null; |
437 |
} else { |
|
50681 | 438 |
if (debug.on()) { |
439 |
debug.log(t.getClass().getSimpleName() |
|
440 |
+ " (async): already retried once.", t); |
|
441 |
} |
|
442 |
t = cause; |
|
48083 | 443 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
444 |
} |
48083 | 445 |
return failedFuture(t); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
446 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
447 |
|
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
448 |
private HttpTimeoutException toTimeoutException(IOException ioe) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
449 |
HttpTimeoutException t = null; |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
450 |
|
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
451 |
// more specific, "request timed out", when connected |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
452 |
Exchange<?> exchange = getExchange(); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
453 |
if (exchange != null) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
454 |
ExchangeImpl<?> exchangeImpl = exchange.exchImpl; |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
455 |
if (exchangeImpl != null) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
456 |
if (exchangeImpl.connection().connected()) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
457 |
t = new HttpTimeoutException("request timed out"); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
458 |
t.initCause(ioe); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
459 |
} |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
460 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
461 |
} |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
462 |
if (t == null) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
463 |
t = new HttpConnectTimeoutException("HTTP connect timed out"); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
464 |
t.initCause(new ConnectException("HTTP connect timed out")); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
465 |
} |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
50681
diff
changeset
|
466 |
return t; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
467 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
468 |
} |