package com.yahoo.vespa.config.server.http;

import com.yahoo.container.jdisc.HttpResponse;
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;


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 HttpResponse(response.getStatusLine().getStatusCode()) {
                @Override
                public void render(OutputStream outputStream) throws IOException {
                    if (response.getEntity() != null ) outputStream.write(responseBody.getBytes());
                }
            };
        } catch (IOException e) {
            log.log(Level.WARNING, "Failed to retrieve logs from log server", e);
            return new HttpResponse(404) {
                @Override
                public void render(OutputStream outputStream) throws IOException {
                    outputStream.write(e.toString().getBytes());
                }
            };
        }

    }
}

@@ -901,36 +901,36 @@
      return new 
-Http
+Logs
 Response(respons
@@ -1347,20 +1347,20 @@
 urn new 
-Http
+Logs
 Response
@@ -1551,32 +1551,33 @@
               %7D%0A
+%0A
             %7D;%0A 
@@ -1591,11 +1591,270 @@
 %7D%0A%0A    %7D
+%0A%0A    private abstract static class LogsResponse extends HttpResponse %7B%0A%0A        LogsResponse(int status) %7B%0A            super(status);%0A        %7D%0A%0A        @Override%0A        public String getContentType() %7B%0A            return %22application/json%22;%0A        %7D%0A    %7D
 %0A%7D%0A

Set content type for logs response (#6978)