use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class BindingsOverviewHandler method handleRequest.
@Override
public ContentChannel handleRequest(com.yahoo.jdisc.Request request, ResponseHandler handler) {
JSONObject json;
int statusToReturn;
if (request instanceof HttpRequest && ((HttpRequest) request).getMethod() != Method.GET) {
json = errorMessageInJson();
statusToReturn = com.yahoo.jdisc.Response.Status.METHOD_NOT_ALLOWED;
} else {
json = new StatusResponse(bindingsConfig).render();
statusToReturn = com.yahoo.jdisc.Response.Status.OK;
}
FastContentWriter writer = new FastContentWriter(new ResponseDispatch() {
@Override
protected com.yahoo.jdisc.Response newResponse() {
com.yahoo.jdisc.Response response = new com.yahoo.jdisc.Response(statusToReturn);
response.headers().add("Content-Type", Arrays.asList(new String[] { "application/json" }));
return response;
}
}.connect(handler));
try {
writer.write(json.toString());
} finally {
writer.close();
}
return new IgnoredContent();
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class VipStatusHandlerTestCase method testFileFound.
@Test
public final void testFileFound() throws IOException {
final File statusFile = File.createTempFile("VipStatusHandlerTestCase", null);
try {
final FileWriter writer = new FileWriter(statusFile);
final String OK = "OK\n";
writer.write(OK);
writer.close();
final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true).statusfile(statusFile.getAbsolutePath()).noSearchBackendsImpliesOutOfService(false));
final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric);
final MockResponseHandler responseHandler = new MockResponseHandler();
final HttpRequest request = createRequest();
final BufferedContentChannel requestContent = createChannel();
handler.handleRequest(request, requestContent, responseHandler);
final ByteBuffer b = responseHandler.channel.read();
final byte[] asBytes = new byte[b.remaining()];
b.get(asBytes);
assertEquals(OK, Utf8.toString(asBytes));
} finally {
statusFile.delete();
}
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class VipStatusHandlerTestCase method testProgrammaticallyRemovedFromRotation.
@Test
public final void testProgrammaticallyRemovedFromRotation() throws IOException {
VipStatus vipStatus = new VipStatus();
final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false).noSearchBackendsImpliesOutOfService(true));
final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric, vipStatus);
vipStatus.removeFromRotation(this);
{
final MockResponseHandler responseHandler = new MockResponseHandler();
final HttpRequest request = createRequest();
final BufferedContentChannel requestContent = createChannel();
handler.handleRequest(request, requestContent, responseHandler);
final ByteBuffer b = responseHandler.channel.read();
final byte[] asBytes = new byte[b.remaining()];
b.get(asBytes);
assertEquals(VipStatusHandler.StatusResponse.NO_SEARCH_BACKENDS, Utf8.toString(asBytes));
}
vipStatus.addToRotation(this);
{
final MockResponseHandler responseHandler = new MockResponseHandler();
final HttpRequest request = createRequest();
final BufferedContentChannel requestContent = createChannel();
handler.handleRequest(request, requestContent, responseHandler);
final ByteBuffer b = responseHandler.channel.read();
final byte[] asBytes = new byte[b.remaining()];
b.get(asBytes);
assertEquals(VipStatusHandler.OK_MESSAGE, Utf8.toString(asBytes));
}
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterResponseTest method testAddCookie.
@Test
public void testAddCookie() {
URI uri = URI.create("http://example.com/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
HttpResponse httpResp = newResponse(httpReq, 200);
DiscFilterResponse response = new JdiscFilterResponse(httpResp);
response.addCookie(JDiscCookieWrapper.wrap(new Cookie("name", "value")));
List<Cookie> cookies = response.getCookies();
Assert.assertEquals(cookies.size(), 1);
Assert.assertEquals(cookies.get(0).getName(), "name");
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterResponseTest method testSetCookie.
@Test
public void testSetCookie() {
URI uri = URI.create("http://example.com/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
HttpResponse httpResp = newResponse(httpReq, 200);
DiscFilterResponse response = new JdiscFilterResponse(httpResp);
response.setCookie("name", "value");
List<Cookie> cookies = response.getCookies();
Assert.assertEquals(cookies.size(), 1);
Assert.assertEquals(cookies.get(0).getName(), "name");
}
Aggregations