diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-06-27 19:41:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-27 19:41:01 +0200 |
commit | 25d20ee1cdf3b28f867ad55a5436e1aac65ccc84 (patch) | |
tree | 5f6438be0413592768013cec1b5f2e3299039364 | |
parent | 4079da9c4ee89197a367138a8a46a386540d19b9 (diff) | |
parent | 0b06d28200588582fcec62f2b51d05da78bb9441 (diff) |
Merge pull request #6302 from vespa-engine/mpolden/avoid-parsing-proxied-content
Avoid parsing proxied content
2 files changed, 27 insertions, 10 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/statuspage/StatusPageClient.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/statuspage/StatusPageClient.java index 93213172048..ecb2f611171 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/statuspage/StatusPageClient.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/statuspage/StatusPageClient.java @@ -1,8 +1,6 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.restapi.statuspage; -import com.yahoo.slime.Slime; -import com.yahoo.vespa.config.SlimeUtils; import org.apache.http.HttpStatus; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; @@ -38,8 +36,8 @@ public class StatusPageClient { this.key = Objects.requireNonNull(key, "key cannot be null"); } - /** GET given page and return response body as slime */ - public Slime get(String page, Optional<String> since) { + /** GET given page and return response body */ + public byte[] get(String page, Optional<String> since) { HttpGet get = new HttpGet(pageUrl(page, since)); try (CloseableHttpClient client = client()) { try (CloseableHttpResponse response = client.execute(get)) { @@ -47,8 +45,7 @@ public class StatusPageClient { throw new IllegalArgumentException("Received status " + response.getStatusLine().getStatusCode() + " from StatusPage"); } - byte[] body = EntityUtils.toByteArray(response.getEntity()); - return SlimeUtils.jsonToSlime(body); + return EntityUtils.toByteArray(response.getEntity()); } } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/statuspage/StatusPageProxyHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/statuspage/StatusPageProxyHandler.java index ad69681fe7e..e652e293c26 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/statuspage/StatusPageProxyHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/statuspage/StatusPageProxyHandler.java @@ -6,13 +6,13 @@ import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.jdisc.LoggingRequestHandler; import com.yahoo.container.jdisc.secretstore.SecretStore; -import com.yahoo.slime.Slime; import com.yahoo.vespa.hosted.controller.restapi.ErrorResponse; import com.yahoo.vespa.hosted.controller.restapi.Path; -import com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse; import com.yahoo.vespa.hosted.controller.statuspage.config.StatuspageConfig; import com.yahoo.yolean.Exceptions; +import java.io.IOException; +import java.io.OutputStream; import java.net.URI; import java.util.Optional; import java.util.logging.Level; @@ -60,8 +60,28 @@ public class StatusPageProxyHandler extends LoggingRequestHandler { } StatusPageClient client = StatusPageClient.create(apiUrl, secretStore.getSecret(secretKey)); Optional<String> since = Optional.ofNullable(request.getProperty("since")); - Slime statusPageResponse = client.get(path.get("page"), since); - return new SlimeJsonResponse(statusPageResponse); + byte[] response = client.get(path.get("page"), since); + return new ByteArrayHttpResponse(response); + } + + private static class ByteArrayHttpResponse extends HttpResponse { + + private final byte[] data; + + public ByteArrayHttpResponse(byte[] data) { + super(200); + this.data = data; + } + + @Override + public void render(OutputStream out) throws IOException { + out.write(data); + } + + @Override + public String getContentType() { + return "application/json"; + } } } |