From df673e65e8da47c8303b635a7d3a7a57671ab4f6 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 26 Jun 2020 19:20:54 +0200 Subject: [PATCH] Polish contribution See gh-25300 --- ...SimpleBufferingAsyncClientHttpRequest.java | 23 +++++++++---------- ...SimpleStreamingAsyncClientHttpRequest.java | 17 +++++++------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java index 25a4ca724449..c2cdaae97ea1 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java @@ -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.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 @@ public URI getURI() { @Override protected ListenableFuture 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); }); } diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java index effec019e66e..eb8ef1adf8d8 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java @@ -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.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 @@ protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { } @Override - protected ListenableFuture executeInternal(final HttpHeaders headers) throws IOException { + protected ListenableFuture 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); }); }