Search in sources :

Example 1 with InputRepresentation

use of org.restlet.resource.InputRepresentation in project GeoGig by boundlessgeo.

the class ConsoleResourceResource method handlePost.

/**
     * Handles JSON RPC 2.0 (http://json-rpc.org/wiki/specification) calls to the
     * <code>/console/run-command end point</code>.
     */
@Override
public void handlePost() {
    final Request request = getRequest();
    final String resource = RESTUtils.getStringAttribute(getRequest(), "resource");
    checkArgument("run-command".equals(resource), "Invalid entry point. Expected: run-command.");
    JsonParser parser = new JsonParser();
    InputRepresentation entityAsObject = (InputRepresentation) request.getEntity();
    JsonObject json;
    try {
        InputStream stream = entityAsObject.getStream();
        InputStreamReader reader = new InputStreamReader(stream);
        json = (JsonObject) parser.parse(reader);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    Preconditions.checkArgument("2.0".equals(json.get("jsonrpc").getAsString()));
    Optional<GeoGIG> providedGeogig = RESTUtils.getGeogig(request);
    checkArgument(providedGeogig.isPresent());
    final GeoGIG geogig = providedGeogig.get();
    JsonObject response;
    if (!checkConsoleEnabled(geogig.getContext())) {
        response = serviceDisabled(json);
    } else {
        response = processRequest(json, geogig);
    }
    getResponse().setEntity(response.toString(), MediaType.APPLICATION_JSON);
}
Also used : InputRepresentation(org.restlet.resource.InputRepresentation) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(org.restlet.data.Request) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) GeoGIG(org.locationtech.geogig.api.GeoGIG) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 Request (org.restlet.data.Request)1 InputRepresentation (org.restlet.resource.InputRepresentation)1