Search in sources :

Example 56 with HttpResponse

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");
}
Also used : HashMap(java.util.HashMap) HttpResponse(com.yahoo.container.jdisc.HttpResponse) File(java.io.File) 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 57 with HttpResponse

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 + "}"));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) File(java.io.File) 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 58 with HttpResponse

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");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) File(java.io.File) 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 59 with HttpResponse

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);
}
Also used : Response(com.yahoo.processing.Response) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Execution(com.yahoo.processing.execution.Execution) Request(com.yahoo.processing.Request) HttpRequest(com.yahoo.container.jdisc.HttpRequest) Request(com.yahoo.processing.Request)

Example 60 with HttpResponse

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");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

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