Search in sources :

Example 1 with RemoteBinaryId

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

the class HeadBinaryHandler 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;
    }
    response.setStatus(HttpServletResponse.SC_OK);
    response.setHeader("Accept-Ranges", "bytes");
}
Also used : RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) RemoteBinaryId(org.apache.jackrabbit.oak.remote.RemoteBinaryId)

Example 2 with RemoteBinaryId

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

the class PostBinaryHandler 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;
    }
    RemoteBinaryId binaryId = session.writeBinary(request.getInputStream());
    response.setStatus(HttpServletResponse.SC_CREATED);
    response.setContentType("application/json");
    ServletOutputStream stream = response.getOutputStream();
    JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
    generator.writeStartObject();
    generator.writeStringField("binaryId", binaryId.asString());
    generator.writeEndObject();
    generator.flush();
    stream.close();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RemoteBinaryId(org.apache.jackrabbit.oak.remote.RemoteBinaryId)

Example 3 with RemoteBinaryId

use of org.apache.jackrabbit.oak.remote.RemoteBinaryId 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)

Aggregations

RemoteBinaryId (org.apache.jackrabbit.oak.remote.RemoteBinaryId)3 RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)3 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 RemoteBinaryFilters (org.apache.jackrabbit.oak.remote.RemoteBinaryFilters)1