Search in sources :

Example 6 with RemoteSession

use of org.apache.jackrabbit.oak.remote.RemoteSession in project jackrabbit-oak by apache.

the class GetBinaryHandler method handle.

@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    RemoteSession session = (RemoteSession) request.getAttribute("session");
    if (session == null) {
        sendInternalServerError(response, "session not found");
        return;
    }
    String providedBinaryId = readBinaryId(request);
    if (providedBinaryId == null) {
        sendBadRequest(response, "unable to read the provided binary ID");
        return;
    }
    RemoteBinaryId binaryId = session.readBinaryId(providedBinaryId);
    if (binaryId == null) {
        sendNotFound(response, "binary ID not found");
        return;
    }
    List<RemoteBinaryFilters> contentRanges = parseRequestRanges(request, session, binaryId);
    if (contentRanges == null) {
        handleFile(response, session, binaryId);
    } else if (contentRanges.size() == 1) {
        handleSingleRange(response, session, binaryId, contentRanges.get(0));
    } else {
        handleMultipleRanges(response, session, binaryId, contentRanges);
    }
}
Also used : RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) RemoteBinaryFilters(org.apache.jackrabbit.oak.remote.RemoteBinaryFilters) RemoteBinaryId(org.apache.jackrabbit.oak.remote.RemoteBinaryId)

Example 7 with RemoteSession

use of org.apache.jackrabbit.oak.remote.RemoteSession 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();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision)

Example 8 with RemoteSession

use of org.apache.jackrabbit.oak.remote.RemoteSession 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");
}
Also used : RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) RemoteTreeFilters(org.apache.jackrabbit.oak.remote.RemoteTreeFilters) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision)

Example 9 with RemoteSession

use of org.apache.jackrabbit.oak.remote.RemoteSession 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();
}
Also used : RemoteOperation(org.apache.jackrabbit.oak.remote.RemoteOperation) ServletOutputStream(javax.servlet.ServletOutputStream) RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) IOException(java.io.IOException)

Aggregations

RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)9 JsonFactory (com.fasterxml.jackson.core.JsonFactory)5 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)5 ServletOutputStream (javax.servlet.ServletOutputStream)5 RemoteRevision (org.apache.jackrabbit.oak.remote.RemoteRevision)5 RemoteBinaryId (org.apache.jackrabbit.oak.remote.RemoteBinaryId)3 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 RemoteBinaryFilters (org.apache.jackrabbit.oak.remote.RemoteBinaryFilters)1 RemoteCommitException (org.apache.jackrabbit.oak.remote.RemoteCommitException)1 RemoteCredentials (org.apache.jackrabbit.oak.remote.RemoteCredentials)1 RemoteLoginException (org.apache.jackrabbit.oak.remote.RemoteLoginException)1 RemoteOperation (org.apache.jackrabbit.oak.remote.RemoteOperation)1 RemoteQueryParseException (org.apache.jackrabbit.oak.remote.RemoteQueryParseException)1 RemoteRepository (org.apache.jackrabbit.oak.remote.RemoteRepository)1 RemoteResults (org.apache.jackrabbit.oak.remote.RemoteResults)1 RemoteTreeFilters (org.apache.jackrabbit.oak.remote.RemoteTreeFilters)1