diff options
author | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-03-07 14:22:37 +0100 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-03-07 15:13:56 +0100 |
commit | 38ac2f93e366488f07d642f8635ad8e0c22950e9 (patch) | |
tree | f4632677a3b8259ec0eec476ef90c94ee98f80d7 /configserver/src | |
parent | 26b291c494537585ed0b74e015814b8bee9d62a7 (diff) |
Set Content-Type and Content-Encoding
Diffstat (limited to 'configserver/src')
3 files changed, 18 insertions, 83 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java index 61bbc145740..62103b51eaa 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java @@ -12,7 +12,6 @@ import com.yahoo.config.application.api.ApplicationMetaData; import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.model.api.ServiceInfo; -import com.yahoo.config.model.api.container.ContainerServiceType; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.HostFilter; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java index c04a2bc35c6..800ebb13095 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java @@ -2,54 +2,45 @@ package com.yahoo.vespa.config.server.http; import com.yahoo.container.jdisc.HttpResponse; +import org.apache.http.Header; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; -import java.util.logging.Logger; - +import java.io.UncheckedIOException; +import java.util.Optional; public class LogRetriever { - private final static Logger log = Logger.getLogger(LogRetriever.class.getName()); - public HttpResponse getLogs(String logServerHostname) { HttpGet get = new HttpGet(logServerHostname); try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { - org.apache.http.HttpResponse response = httpClient.execute(get); - String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8"); - return new LogsResponse(response.getStatusLine().getStatusCode()) { - @Override - public void render(OutputStream outputStream) throws IOException { - if (response.getEntity() != null ) outputStream.write(responseBody.getBytes()); - } - }; + return new ProxyResponse(httpClient.execute(get)); } catch (IOException e) { - log.log(Level.WARNING, "Failed to retrieve logs from log server", e); - return new LogsResponse(404) { - @Override - public void render(OutputStream outputStream) throws IOException { - outputStream.write(e.toString().getBytes()); - } - - }; + throw new UncheckedIOException(e); } - } - private abstract static class LogsResponse extends HttpResponse { + private static class ProxyResponse extends HttpResponse { + private final org.apache.http.HttpResponse clientResponse; - LogsResponse(int status) { - super(status); + private ProxyResponse(org.apache.http.HttpResponse clientResponse) { + super(clientResponse.getStatusLine().getStatusCode()); + this.clientResponse = clientResponse; } @Override public String getContentType() { - return "application/json"; + return Optional.ofNullable(clientResponse.getFirstHeader("Content-Type")) + .map(Header::getValue) + .orElseGet(super::getContentType); + } + + @Override + public void render(OutputStream outputStream) throws IOException { + clientResponse.getEntity().writeTo(outputStream); } } } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/LogRetrieverTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/LogRetrieverTest.java deleted file mode 100644 index a2c63047878..00000000000 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/LogRetrieverTest.java +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import com.yahoo.container.jdisc.HttpResponse; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.okJson; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; -import static org.junit.Assert.assertEquals; - -public class LogRetrieverTest { - - private LogRetriever logRetriever; - - @Rule - public final WireMockRule wireMock = new WireMockRule(options().dynamicPort(), true); - - @Before - public void setup() { - logRetriever = new LogRetriever(); - } - - @Test - public void testThatLogHandlerPropagatesResponseBody() throws IOException { - String expectedBody = "{logs-json}"; - stubFor(get(urlEqualTo("/")).willReturn(okJson(expectedBody))); - String logServerUri = "http://localhost:" + wireMock.port() +"/"; - HttpResponse response = logRetriever.getLogs(logServerUri); - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - response.render(byteArrayOutputStream); - assertEquals(expectedBody, byteArrayOutputStream.toString()); - assertEquals(200, response.getStatus()); - } - - @Test - public void testThatNotFoundLogServerReturns404() { - stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200))); - HttpResponse response = logRetriever.getLogs("http://wrong-host:" + wireMock.port() + "/"); - assertEquals(404, response.getStatus()); - } - - - -} |