Search in sources :

Example 21 with HttpRequest

use of com.yahoo.container.jdisc.HttpRequest 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 22 with HttpRequest

use of com.yahoo.container.jdisc.HttpRequest 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)

Example 23 with HttpRequest

use of com.yahoo.container.jdisc.HttpRequest 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 24 with HttpRequest

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

the class HttpGetConfigHandlerTest method require_that_nocache_property_works.

@Test
public void require_that_nocache_property_works() throws IOException {
    long generation = 1L;
    ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    InnerCNode targetDef = getInnerCNode();
    mockRequestHandler.responses.put(new ApplicationId.Builder().tenant(tenant).applicationName("myapplication").build(), SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5"));
    final HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Collections.singletonMap("nocache", "true"));
    HttpResponse response = handler.handle(request);
    assertThat(SessionHandlerTest.getRenderedString(response), is(EXPECTED_RENDERED_STRING));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) 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)

Example 25 with HttpRequest

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

the class HttpGetConfigHandlerTest method require_that_request_gets_correct_fields_with_short_appid.

@Test
public void require_that_request_gets_correct_fields_with_short_appid() {
    String uriShortAppId = "http://yahoo.com:8080/config/v2/tenant/jason/application/alcide/foo.bar/myid";
    HttpRequest r = HttpRequest.createTestRequest(uriShortAppId, GET);
    HttpConfigRequest req = HttpConfigRequest.createFromRequestV2(r);
    assertThat(req.getApplicationId().tenant().value(), is("jason"));
    assertThat(req.getApplicationId().application().value(), is("alcide"));
    assertThat(req.getApplicationId().instance().value(), is("default"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) HttpConfigRequest(com.yahoo.vespa.config.server.http.HttpConfigRequest) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest)

Aggregations

HttpRequest (com.yahoo.container.jdisc.HttpRequest)37 Test (org.junit.Test)23 HttpResponse (com.yahoo.container.jdisc.HttpResponse)18 InputStream (java.io.InputStream)9 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)7 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Query (com.yahoo.search.Query)4 Joiner (com.google.common.base.Joiner)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Inject (com.google.inject.Inject)3 Version (com.yahoo.component.Version)3 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3 ApplicationName (com.yahoo.config.provision.ApplicationName)3 Environment (com.yahoo.config.provision.Environment)3 RegionName (com.yahoo.config.provision.RegionName)3 TenantName (com.yahoo.config.provision.TenantName)3 LoggingRequestHandler (com.yahoo.container.jdisc.LoggingRequestHandler)3 IOUtils (com.yahoo.io.IOUtils)3