Skip to content

Commit

Permalink
Polish contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jun 26, 2020
1 parent 43df06b commit df673e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
@@ -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.
Expand All @@ -20,7 +20,6 @@
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;
Expand Down Expand Up @@ -74,26 +73,26 @@ public URI getURI() {

@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);
});
}

Expand Down
@@ -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.
Expand All @@ -21,7 +21,6 @@
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;
Expand Down Expand Up @@ -102,23 +101,23 @@ protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
}

@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);
});

}
Expand Down

0 comments on commit df673e6

Please sign in to comment.