diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2018-01-17 09:58:33 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2018-01-17 09:58:33 +0100 |
commit | 0085a8e0359537fb9e92ac05d55624926ef63de3 (patch) | |
tree | 2eb481ece6795c61b7efde02bcc38a4fb5f4c219 /controller-server | |
parent | fceb729ed94a195aef7c6fe9b8d471f1c136b755 (diff) |
Use EntityUtils.toString
Diffstat (limited to 'controller-server')
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java index bbb09615466..792f2af3a03 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Inject; import com.yahoo.config.provision.Environment; -import com.yahoo.io.IOUtils; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.vespa.hosted.controller.api.integration.athenz.AthenzIdentity; import com.yahoo.vespa.hosted.controller.api.integration.athenz.AthenzIdentityVerifier; @@ -27,6 +26,7 @@ import org.apache.http.conn.ssl.X509HostnameVerifier; import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; import javax.net.ssl.SSLException; import javax.net.ssl.SSLSession; @@ -34,7 +34,6 @@ import javax.net.ssl.SSLSocket; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.nio.charset.StandardCharsets; import java.security.cert.X509Certificate; import java.time.Duration; import java.util.ArrayList; @@ -139,7 +138,7 @@ public class ConfigServerRestExecutorImpl implements ConfigServerRestExecutor { if (response.getStatusLine().getStatusCode() / 100 == 5) { errorBuilder.append("Talking to server ").append(uri.getHost()); errorBuilder.append(", got ").append(response.getStatusLine().getStatusCode()).append(" ") - .append(streamToString(response.getEntity().getContent())).append("\n"); + .append(EntityUtils.toString(response.getEntity())).append("\n"); return Optional.empty(); } final Header contentHeader = response.getLastHeader("Content-Type"); @@ -151,7 +150,7 @@ public class ConfigServerRestExecutorImpl implements ConfigServerRestExecutor { } return Optional.of(new ProxyResponse( proxyRequest, - streamToString(response.getEntity().getContent()), + EntityUtils.toString(response.getEntity()), response.getStatusLine().getStatusCode(), Optional.of(uri), contentType)); @@ -204,17 +203,6 @@ public class ConfigServerRestExecutorImpl implements ConfigServerRestExecutor { } } - public static String streamToString(final InputStream inputStream) throws IOException { - final StringBuilder out = new StringBuilder(); - while (true) { - byte[] bytesFromStream = IOUtils.readBytes(inputStream, 1024); - if (bytesFromStream.length == 0) { - return out.toString(); - } - out.append(new String(bytesFromStream, StandardCharsets.UTF_8)); - } - } - /** * During upgrade, one server can be down, this is normal. Therefor we do a quick ping on the first server, * if it is not responding, we try the other servers first. False positive/negatives are not critical, |