Search in sources :

Example 26 with HttpRequest

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

the class HttpListConfigsHandlerTest method require_that_named_handler_can_be_created.

@Test
public void require_that_named_handler_can_be_created() throws IOException {
    HttpRequest req = HttpRequest.createTestRequest("http://foo.com:8080/config/v1/foo.bar/conf/id/", GET);
    req.getJDiscRequest().parameters().put("http.path", Arrays.asList("foo.bar"));
    HttpResponse response = namedHandler.handle(req);
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"children\":[],\"configs\":[]}"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 27 with HttpRequest

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

the class Templating method getNextResultURL.

/**
 * An URL that may be used to obtain the next result page.
 */
public String getNextResultURL() {
    HttpRequest request = result.getQuery().getHttpRequest();
    StringBuilder nextURL = new StringBuilder();
    nextURL.append(getPath(request)).append("?");
    parametersExceptOffset(request, nextURL);
    int offset = getLastHitNo();
    nextURL.append("&").append("offset=").append(Integer.toString(offset));
    return nextURL.toString();
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest)

Example 28 with HttpRequest

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

the class ConnectionControlSearcher method setCloseIfLifetimeExceeded.

private void setCloseIfLifetimeExceeded(Query query, Result result, int maxLifetimeSeconds) {
    final HttpRequest httpRequest = query.getHttpRequest();
    if (httpRequest == null) {
        query.trace(false, 5, simpleName, " got max lifetime = ", maxLifetimeSeconds, ", but got no JDisc request. Setting no header.");
        return;
    }
    final long connectedAtMillis = httpRequest.getJDiscRequest().getConnectedAt(TimeUnit.MILLISECONDS);
    final long maxLifeTimeMillis = maxLifetimeSeconds * 1000L;
    if (connectedAtMillis + maxLifeTimeMillis < clock.getAsLong()) {
        result.getHeaders(true).put(HTTP_CONNECTION_HEADER_NAME, HTTP_CONNECTION_CLOSE_ARGUMENT);
        query.trace(false, 5, simpleName, ": Max HTTP connection lifetime (", maxLifetimeSeconds, ") exceeded; adding \"", HTTP_CONNECTION_HEADER_NAME, ": ", HTTP_CONNECTION_CLOSE_ARGUMENT, "\" header");
    }
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest)

Example 29 with HttpRequest

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

the class FeedTesterV3 method createRequest.

HttpRequest createRequest(int numberOfDocs) {
    String clientId = "client123";
    StringBuilder wireData = new StringBuilder();
    for (int x = 0; x < numberOfDocs; x++) {
        String docData = "[{\"put\": \"id:testdocument:testdocument::c\", \"fields\": { \"title\": \"fooKey\", \"body\": \"value\"}}]";
        String operationId = "123" + x;
        wireData.append(operationId + " " + Integer.toHexString(docData.length()) + "\n" + docData);
    }
    InputStream inputStream = new ByteArrayInputStream(wireData.toString().getBytes());
    HttpRequest request = HttpRequest.createTestRequest("http://dummyhostname:19020/reserved-for-internal-use/feedapi", com.yahoo.jdisc.http.HttpRequest.Method.POST, inputStream);
    request.getJDiscRequest().headers().add(Headers.VERSION, "3");
    request.getJDiscRequest().headers().add(Headers.DATA_FORMAT, FeedParams.DataFormat.JSON_UTF8.name());
    request.getJDiscRequest().headers().add(Headers.TIMEOUT, "1000000000");
    request.getJDiscRequest().headers().add(Headers.CLIENT_ID, clientId);
    request.getJDiscRequest().headers().add(Headers.PRIORITY, "LOWEST");
    request.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "4");
    request.getJDiscRequest().headers().add(Headers.DRAIN, "true");
    return request;
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 30 with HttpRequest

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

the class FeedHandlerCompressionTest method testUnzipFails.

/**
 * Test by setting encoding, but not compressing data.
 * @throws Exception
 */
@Test
public void testUnzipFails() throws Exception {
    final String testData = "foo bar";
    InputStream inputStream = new ByteArrayInputStream(testData.getBytes());
    HttpRequest httpRequest = mock(HttpRequest.class);
    when(httpRequest.getHeader("Content-Encoding")).thenReturn("gzip");
    InputStream decompressedStream = FeedHandler.unzipStreamIfNeeded(inputStream, httpRequest);
    final StringBuilder processedInput = new StringBuilder();
    while (true) {
        int readValue = decompressedStream.read();
        if (readValue < 0) {
            break;
        }
        processedInput.append((char) readValue);
    }
    assertThat(processedInput.toString(), is(testData));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

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