< prev index next >
src/java.net.http/share/classes/jdk/internal/net/http/MultiExchange.java
Print this page
*** 25,35 ****
package jdk.internal.net.http;
import java.io.IOException;
import java.net.ConnectException;
! import java.time.Duration;
import java.util.Iterator;
import java.util.LinkedList;
import java.security.AccessControlContext;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
--- 25,35 ----
package jdk.internal.net.http;
import java.io.IOException;
import java.net.ConnectException;
! import java.net.http.HttpConnectTimeoutException;
import java.util.Iterator;
import java.util.LinkedList;
import java.security.AccessControlContext;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
*** 86,96 ****
static final int max_attempts = Utils.getIntegerNetProperty(
"jdk.httpclient.redirects.retrylimit", DEFAULT_MAX_ATTEMPTS
);
private final LinkedList<HeaderFilter> filters;
! TimedEvent timedEvent;
volatile boolean cancelled;
final PushGroup<T> pushGroup;
/**
* Filter fields. These are attached as required by filters
--- 86,96 ----
static final int max_attempts = Utils.getIntegerNetProperty(
"jdk.httpclient.redirects.retrylimit", DEFAULT_MAX_ATTEMPTS
);
private final LinkedList<HeaderFilter> filters;
! ResponseTimerEvent responseTimerEvent;
volatile boolean cancelled;
final PushGroup<T> pushGroup;
/**
* Filter fields. These are attached as required by filters
*** 132,142 ****
}
this.exchange = new Exchange<>(request, this);
}
! private synchronized Exchange<T> getExchange() {
return exchange;
}
HttpClientImpl client() {
return client;
--- 132,142 ----
}
this.exchange = new Exchange<>(request, this);
}
! synchronized Exchange<T> getExchange() {
return exchange;
}
HttpClientImpl client() {
return client;
*** 155,166 ****
}
this.exchange = exchange;
}
private void cancelTimer() {
! if (timedEvent != null) {
! client.cancelTimer(timedEvent);
}
}
private void requestFilters(HttpRequestImpl r) throws IOException {
Log.logTrace("Applying request filters");
--- 155,166 ----
}
this.exchange = exchange;
}
private void cancelTimer() {
! if (responseTimerEvent != null) {
! client.cancelTimer(responseTimerEvent);
}
}
private void requestFilters(HttpRequestImpl r) throws IOException {
Log.logTrace("Applying request filters");
*** 218,229 ****
CompletableFuture<Response> cf;
if (attempts.incrementAndGet() > max_attempts) {
cf = failedFuture(new IOException("Too many retries", retryCause));
} else {
if (currentreq.timeout().isPresent()) {
! timedEvent = new TimedEvent(currentreq.timeout().get());
! client.registerTimer(timedEvent);
}
try {
// 1. apply request filters
// if currentreq == previousreq the filters have already
// been applied once. Applying them a second time might
--- 218,229 ----
CompletableFuture<Response> cf;
if (attempts.incrementAndGet() > max_attempts) {
cf = failedFuture(new IOException("Too many retries", retryCause));
} else {
if (currentreq.timeout().isPresent()) {
! responseTimerEvent = ResponseTimerEvent.of(this);
! client.registerTimer(responseTimerEvent);
}
try {
// 1. apply request filters
// if currentreq == previousreq the filters have already
// been applied once. Applying them a second time might
*** 342,352 ****
if (t.getCause() != null) {
t = t.getCause();
}
}
if (cancelled && t instanceof IOException) {
! t = new HttpTimeoutException("request timed out");
} else if (retryOnFailure(t)) {
Throwable cause = retryCause(t);
if (!(t instanceof ConnectException)) {
if (!canRetryRequest(currentreq)) {
--- 342,354 ----
if (t.getCause() != null) {
t = t.getCause();
}
}
if (cancelled && t instanceof IOException) {
! if (!(t instanceof HttpTimeoutException)) {
! t = toTimeoutException((IOException)t);
! }
} else if (retryOnFailure(t)) {
Throwable cause = retryCause(t);
if (!(t instanceof ConnectException)) {
if (!canRetryRequest(currentreq)) {
*** 376,394 ****
}
}
return failedFuture(t);
}
! class TimedEvent extends TimeoutEvent {
! TimedEvent(Duration duration) {
! super(duration);
}
- @Override
- public void handle() {
- if (debug.on()) {
- debug.log("Cancelling MultiExchange due to timeout for request %s",
- request);
}
! cancel(new HttpTimeoutException("request timed out"));
}
}
}
--- 378,403 ----
}
}
return failedFuture(t);
}
! private HttpTimeoutException toTimeoutException(IOException ioe) {
! HttpTimeoutException t = null;
!
! // more specific, "request timed out", when connected
! Exchange<?> exchange = getExchange();
! if (exchange != null) {
! ExchangeImpl<?> exchangeImpl = exchange.exchImpl;
! if (exchangeImpl != null) {
! if (exchangeImpl.connection().connected()) {
! t = new HttpTimeoutException("request timed out");
! t.initCause(ioe); // TODO: remove this if all testing goes well
! }
}
}
! if (t == null) {
! t = new HttpConnectTimeoutException("HTTP connect timed out");
! t.initCause(new ConnectException("HTTP connect timed out"));
}
+ return t;
}
}
< prev index next >