Polish contribution

See gh-25300
This commit is contained in:
Sam Brannen 2020-06-26 19:20:54 +02:00
parent 43df06b905
commit df673e65e8
2 changed files with 19 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.Callable;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.http.HttpHeaders;
@ -74,26 +73,26 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
@Override
protected ListenableFuture<ClientHttpResponse> executeInternal(
final HttpHeaders headers, final byte[] bufferedOutput) throws IOException {
HttpHeaders headers, byte[] bufferedOutput) throws IOException {
return this.taskExecutor.submitListenable(() -> {
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers);
// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
if (getMethod() == HttpMethod.DELETE && bufferedOutput.length == 0) {
connection.setDoOutput(false);
this.connection.setDoOutput(false);
}
if (connection.getDoOutput() && outputStreaming) {
connection.setFixedLengthStreamingMode(bufferedOutput.length);
if (this.connection.getDoOutput() && outputStreaming) {
this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
}
connection.connect();
if (connection.getDoOutput()) {
FileCopyUtils.copy(bufferedOutput, connection.getOutputStream());
this.connection.connect();
if (this.connection.getDoOutput()) {
FileCopyUtils.copy(bufferedOutput, this.connection.getOutputStream());
}
else {
// Immediately trigger the request in a no-output scenario as well
connection.getResponseCode();
this.connection.getResponseCode();
}
return new SimpleClientHttpResponse(connection);
return new SimpleClientHttpResponse(this.connection);
});
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,7 +21,6 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.Callable;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.http.HttpHeaders;
@ -102,23 +101,23 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt
}
@Override
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) throws IOException {
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers) throws IOException {
return this.taskExecutor.submitListenable(() -> {
try {
if (body != null) {
body.close();
if (this.body != null) {
this.body.close();
}
else {
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
connection.connect();
SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers);
this.connection.connect();
// Immediately trigger the request in a no-output scenario as well
connection.getResponseCode();
this.connection.getResponseCode();
}
}
catch (IOException ex) {
// ignore
}
return new SimpleClientHttpResponse(connection);
return new SimpleClientHttpResponse(this.connection);
});
}