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\":[]}"));
}
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();
}
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");
}
}
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;
}
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));
}
Aggregations