use of com.yahoo.jdisc.handler.ResponseDispatch 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.handler.ResponseDispatch in project vespa by vespa-engine.
the class ApplicationStatusHandler method handleRequest.
@Override
public ContentChannel handleRequest(com.yahoo.jdisc.Request request, ResponseHandler handler) {
JSONObject json = new StatusResponse(applicationJson, clientsJson, serversJson, requestFiltersJson, responseFiltersJson, bindingsConfig).render();
FastContentWriter writer = new FastContentWriter(new ResponseDispatch() {
@Override
protected com.yahoo.jdisc.Response newResponse() {
com.yahoo.jdisc.Response response = new com.yahoo.jdisc.Response(com.yahoo.jdisc.Response.Status.OK);
response.headers().add("Content-Type", Arrays.asList(new String[] { "application/json" }));
return response;
}
}.connect(handler));
writer.write(json.toString());
writer.close();
return new IgnoredContent();
}
Aggregations