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);
}
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");
}
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");
}
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 + "}"));
}
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");
}
Aggregations