Search in sources :

Example 1 with ResponseDispatch

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();
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) ResponseDispatch(com.yahoo.jdisc.handler.ResponseDispatch) JSONObject(org.json.JSONObject) FastContentWriter(com.yahoo.jdisc.handler.FastContentWriter)

Example 2 with ResponseDispatch

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();
}
Also used : ResponseDispatch(com.yahoo.jdisc.handler.ResponseDispatch) JSONObject(org.json.JSONObject) FastContentWriter(com.yahoo.jdisc.handler.FastContentWriter)

Aggregations

FastContentWriter (com.yahoo.jdisc.handler.FastContentWriter)2 ResponseDispatch (com.yahoo.jdisc.handler.ResponseDispatch)2 JSONObject (org.json.JSONObject)2 HttpRequest (com.yahoo.jdisc.http.HttpRequest)1