use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class SessionCreateHandlerTest method require_that_post_request_must_have_correct_content_type.
@Test
public void require_that_post_request_must_have_correct_content_type() throws IOException {
// no Content-Type header
HashMap<String, String> headers = new HashMap<>();
File outFile = CompressedApplicationInputStreamTest.createTarFile();
HttpResponse response = createHandler().handle(post(outFile, headers, null));
HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Request contains no Content-Type header");
}
use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class SessionCreateHandlerTest method require_that_prepare_url_is_returned_on_success.
@Test
public void require_that_prepare_url_is_returned_on_success() throws IOException {
File outFile = CompressedApplicationInputStreamTest.createTarFile();
Map<String, String> parameters = Collections.singletonMap("name", "foo");
HttpResponse response = createHandler().handle(post(outFile, postHeaders, parameters));
assertNotNull(response);
assertThat(response.getStatus(), is(OK));
assertThat(SessionHandlerTest.getRenderedString(response), is("{\"log\":[]" + tenantMessage + ",\"session-id\":\"0\",\"prepared\":\"http://" + hostname + ":" + port + pathPrefix + "0/prepared\",\"content\":\"http://" + hostname + ":" + port + pathPrefix + "0/content/\",\"message\":\"Session 0" + createdMessage + "}"));
}
use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class SessionCreateHandlerTest method require_internal_error_when_exception.
@Test
public void require_internal_error_when_exception() throws IOException {
MockSessionFactory factory = new MockSessionFactory();
factory.doThrow = true;
File outFile = CompressedApplicationInputStreamTest.createTarFile();
HttpResponse response = createHandler(factory).handle(post(outFile));
HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, INTERNAL_SERVER_ERROR, HttpErrorResponse.errorCodes.INTERNAL_SERVER_ERROR, "foo");
}
use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class AbstractProcessingHandler method handle.
@Override
@SuppressWarnings("unchecked")
public HttpResponse handle(HttpRequest request, ContentChannel channel) {
com.yahoo.processing.Request processingRequest = new com.yahoo.processing.Request();
populate("", request.propertyMap(), processingRequest.properties());
populate("context", request.getJDiscRequest().context(), processingRequest.properties());
processingRequest.properties().set(Request.JDISC_REQUEST, request);
FreezeListener freezeListener = new FreezeListener(processingRequest, renderers, defaultRenderer, channel, renderingExecutor);
processingRequest.properties().set(freezeListenerKey, freezeListener);
Chain<COMPONENT> chain = chainRegistry.getComponent(resolveChainId(processingRequest.properties()));
if (chain == null)
throw new IllegalArgumentException("Chain '" + processingRequest.properties().get("chain") + "' not found");
Execution execution = createExecution(chain, processingRequest);
freezeListener.setExecution(execution);
Response processingResponse = execution.process(processingRequest);
return freezeListener.getHttpResponse(processingResponse);
}
use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.
the class MockServiceTest method testHandlerTextFormat.
@Test
public void testHandlerTextFormat() throws InterruptedException, IOException {
HttpResponse response = runHandler(com.yahoo.jdisc.http.HttpRequest.Method.GET, "/foo/bar");
assertResponse(response, 200, "Hello\nThere!");
response = runHandler(com.yahoo.jdisc.http.HttpRequest.Method.GET, "http://my.host:8080/foo/bar?key1=foo&key2=bar");
assertResponse(response, 200, "With params!");
response = runHandler(com.yahoo.jdisc.http.HttpRequest.Method.PUT, "/bar");
assertResponse(response, 301, "My data is on a single line");
}
Aggregations