Search in sources :

Example 1 with RemoteSession

use of org.apache.jackrabbit.oak.remote.RemoteSession 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();
}
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) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision)

Example 2 with RemoteSession

use of org.apache.jackrabbit.oak.remote.RemoteSession 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 3 with RemoteSession

use of org.apache.jackrabbit.oak.remote.RemoteSession 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 4 with RemoteSession

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

the class AuthenticationWrapperHandler method handle.

@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    RemoteSession session = (RemoteSession) request.getAttribute("session");
    if (session != null) {
        authenticated.handle(request, response);
        return;
    }
    RemoteRepository repository = (RemoteRepository) request.getAttribute("repository");
    if (repository == null) {
        sendInternalServerError(response, "repository not found");
        return;
    }
    RemoteCredentials credentials = extractCredentials(request, repository);
    if (credentials == null) {
        notAuthenticated.handle(request, response);
        return;
    }
    try {
        session = repository.login(credentials);
    } catch (RemoteLoginException e) {
        logger.warn("unable to authenticate to the repository", e);
        notAuthenticated.handle(request, response);
        return;
    }
    request.setAttribute("session", session);
    authenticated.handle(request, response);
}
Also used : RemoteLoginException(org.apache.jackrabbit.oak.remote.RemoteLoginException) RemoteCredentials(org.apache.jackrabbit.oak.remote.RemoteCredentials) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) RemoteRepository(org.apache.jackrabbit.oak.remote.RemoteRepository)

Example 5 with RemoteSession

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

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