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;
}
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);
}
Aggregations