Search in sources :

Example 6 with Request

use of org.restlet.data.Request in project GeoGig by boundlessgeo.

the class CommandResource method getRepresentation.

@Override
public Representation getRepresentation(Variant variant) {
    Request request = getRequest();
    Representation representation = runCommand(variant, request);
    return representation;
}
Also used : Request(org.restlet.data.Request) Representation(org.restlet.resource.Representation) WriterRepresentation(org.locationtech.geogig.rest.WriterRepresentation)

Example 7 with Request

use of org.restlet.data.Request 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

Request (org.restlet.data.Request)7 Representation (org.restlet.resource.Representation)4 MediaType (org.restlet.data.MediaType)3 Optional (com.google.common.base.Optional)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Context (org.locationtech.geogig.api.Context)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 AsyncContext (org.locationtech.geogig.rest.AsyncContext)2 Form (org.restlet.data.Form)2 Stopwatch (com.google.common.base.Stopwatch)1 CountingInputStream (com.google.common.io.CountingInputStream)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 Decoder (com.noelios.restlet.application.Decoder)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 Mapping (org.locationtech.geogig.osm.internal.Mapping)1