Search in sources :

Example 51 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class RestApiHandler method handleGet.

private HttpResponse handleGet(HttpRequest request) {
    String path = request.getUri().getPath();
    if (path.endsWith("/info")) {
        return new SimpleObjectResponse(200, refresher.getDebugPage());
    }
    if (path.endsWith("/metrics")) {
        return new HttpResponse(200) {

            @Override
            public String getContentType() {
                return MediaType.APPLICATION_JSON;
            }

            @Override
            public void render(OutputStream outputStream) throws IOException {
                try (PrintStream printStream = new PrintStream(outputStream)) {
                    for (DimensionMetrics dimensionMetrics : metricReceiverWrapper.getAllMetrics()) {
                        String secretAgentJsonReport = dimensionMetrics.toSecretAgentReport() + "\n";
                        printStream.write(secretAgentJsonReport.getBytes(StandardCharsets.UTF_8.name()));
                    }
                }
            }
        };
    }
    return new SimpleResponse(400, "unknown path " + path);
}
Also used : DimensionMetrics(com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics) PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 52 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionCreateHandlerTest method require_that_post_request_must_contain_data.

@Test
public void require_that_post_request_must_contain_data() throws IOException {
    HttpResponse response = createHandler().handle(post());
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Request contains no data");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) CompressedApplicationInputStreamTest(com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest)

Example 53 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionCreateHandlerTest method require_that_handler_does_not_support_get.

@Test
public void require_that_handler_does_not_support_get() throws IOException {
    HttpResponse response = createHandler().handle(HttpRequest.createTestRequest(pathPrefix, GET));
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, METHOD_NOT_ALLOWED, HttpErrorResponse.errorCodes.METHOD_NOT_ALLOWED, "Method 'GET' is not supported");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) CompressedApplicationInputStreamTest(com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest)

Example 54 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionCreateHandlerTest method assertFromParameter.

private void assertFromParameter(String expected, String from) throws IOException {
    HttpRequest request = post(Collections.singletonMap("from", from));
    MockSessionFactory factory = new MockSessionFactory();
    factory.applicationPackage = testApp;
    HttpResponse response = createHandler(factory).handle(request);
    assertNotNull(response);
    assertThat(response.getStatus(), is(OK));
    assertTrue(factory.createFromCalled);
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"log\":[]" + tenantMessage + ",\"session-id\":\"" + expected + "\",\"prepared\":\"http://" + hostname + ":" + port + pathPrefix + expected + "/prepared\",\"content\":\"http://" + hostname + ":" + port + pathPrefix + expected + "/content/\",\"message\":\"Session " + expected + createdMessage + "}"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 55 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionCreateHandlerTest method require_that_from_parameter_cannot_be_set_if_data_in_request.

@Ignore
@Test
public void require_that_from_parameter_cannot_be_set_if_data_in_request() throws IOException {
    HttpRequest request = post(Collections.singletonMap("from", "active"));
    HttpResponse response = createHandler().handle(request);
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Parameter 'from' is illegal for POST");
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Ignore(org.junit.Ignore) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) CompressedApplicationInputStreamTest(com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest)

Aggregations

HttpResponse (com.yahoo.container.jdisc.HttpResponse)103 Test (org.junit.Test)75 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)33 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)24 HttpRequest (com.yahoo.container.jdisc.HttpRequest)16 CompressedApplicationInputStreamTest (com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest)6 SessionTest (com.yahoo.vespa.config.server.session.SessionTest)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)5 InnerCNode (com.yahoo.config.codegen.InnerCNode)5 Slime (com.yahoo.slime.Slime)5 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)5 OutputStream (java.io.OutputStream)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ApplicationId (com.yahoo.config.provision.ApplicationId)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3