use of org.apache.jackrabbit.oak.remote.RemoteRevision in project jackrabbit-oak by apache.
the class GetLastRevisionHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
RemoteSession session = (RemoteSession) request.getAttribute("session");
if (session == null) {
sendInternalServerError(response, "session not found");
return;
}
RemoteRevision revision = session.readLastRevision();
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/json");
ServletOutputStream stream = response.getOutputStream();
JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
generator.writeStartObject();
generator.writeStringField("revision", revision.asString());
generator.writeEndObject();
generator.flush();
stream.close();
}
use of org.apache.jackrabbit.oak.remote.RemoteRevision in project jackrabbit-oak by apache.
the class SearchRevisionHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RemoteSession session = (RemoteSession) request.getAttribute("session");
if (session == null) {
sendInternalServerError(response, "session not found");
return;
}
RemoteRevision revision = readRevision(request, session);
if (revision == null) {
sendGone(response, "unable to read the revision");
return;
}
String query = readQuery(request);
if (query == null) {
sendBadRequest(response, "query not specified");
return;
}
String language = readLanguage(request);
if (language == null) {
sendBadRequest(response, "language not specified");
return;
}
Long offset = readOffset(request);
if (offset == null) {
sendBadRequest(response, "offset not specified");
return;
}
Long limit = readLimit(request);
if (limit == null) {
sendBadRequest(response, "limit not specified");
return;
}
RemoteResults results;
try {
results = session.search(revision, query, language, offset, limit);
} catch (RemoteQueryParseException e) {
sendBadRequest(response, "malformed query");
return;
}
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("Oak-Revision", revision.asString());
response.setContentType("application/json");
ServletOutputStream stream = response.getOutputStream();
JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
renderResponse(generator, results);
generator.flush();
stream.close();
}
use of org.apache.jackrabbit.oak.remote.RemoteRevision in project jackrabbit-oak by apache.
the class GetTreeHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
RemoteSession session = (RemoteSession) request.getAttribute("session");
if (session == null) {
sendInternalServerError(response, "session not found");
return;
}
RemoteRevision revision = readRevision(request, session);
if (revision == null) {
sendGone(response, "unable to read the revision");
return;
}
RemoteTree tree = session.readTree(revision, readPath(request), readFilters(request));
if (tree == null) {
sendNotFound(response, singletonMap("Oak-Revision", revision.asString()), "tree not found");
return;
}
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("Oak-Revision", revision.asString());
response.setContentType("application/json");
ServletOutputStream stream = response.getOutputStream();
JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
renderResponse(generator, tree);
generator.flush();
stream.close();
}
use of org.apache.jackrabbit.oak.remote.RemoteRevision in project jackrabbit-oak by apache.
the class HeadTreeHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
RemoteSession session = (RemoteSession) request.getAttribute("session");
if (session == null) {
sendInternalServerError(response, "session not found");
return;
}
RemoteRevision revision = readRevision(request, session);
if (revision == null) {
sendGone(response, "revision not found");
return;
}
RemoteTree tree = session.readTree(revision, readPath(request), new RemoteTreeFilters());
if (tree == null) {
sendNotFound(response, singletonMap("Oak-Revision", revision.asString()), "tree not found");
return;
}
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("Oak-Revision", revision.asString());
response.setContentType("application/json");
}
use of org.apache.jackrabbit.oak.remote.RemoteRevision in project jackrabbit-oak by apache.
the class PatchRevisionHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
RemoteSession session = (RemoteSession) request.getAttribute("session");
if (session == null) {
sendInternalServerError(response, "session not found");
return;
}
RemoteRevision base = readRevision(request, session);
if (base == null) {
sendGone(response, "revision not found");
return;
}
RemoteOperation operation;
try {
operation = parseOperations(session, new ObjectMapper().readTree(request.getInputStream()));
} catch (Exception e) {
operation = null;
}
if (operation == null) {
sendBadRequest(response, "unable to parse the list of operations");
return;
}
RemoteRevision revision;
try {
revision = session.commit(base, operation);
} catch (RemoteCommitException e) {
logger.warn("unable to perform the commit", e);
sendBadRequest(response, "commit failed");
return;
}
response.setStatus(HttpServletResponse.SC_CREATED);
response.setContentType("application/json");
ServletOutputStream stream = response.getOutputStream();
JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
renderResponse(generator, revision);
generator.flush();
stream.close();
}
Aggregations