private Message handleRequestWithIfMatch(Request request) throws IOException { final Path path = Path.fromString(request.uri().getPath()); final Resource resource = resolveResource(path); final String ifMatch = getOnlyElement(request.headers().get(Header.IF_MATCH)); if (ifMatch.equals("*") || !ifMatch.equals(resource.etag())) { return handleRequestWithoutIfMatch(request); } else { return Response.clientErrorPreconditionFailed(); } }
private Message handleRequestWithIfModifiedSince(final Request request) throws IOException { final Path path = Path.fromUri(request.uri()); final Resource resource = resolveResource(path); try { String date = getOnlyElement(request.headers().get(IF_MODIFIED_SINCE)); Date ifModifiedSince = new SimpleDateFormat().parse(date); if (!ifModifiedSince.after(new Date()) && !(resource.lastModified().after(new Date()))) { return redirectionNotModified(); } else { return handleRequestWithoutIfModifiedSince(request); } } catch (ParseException e) { return handleRequestWithoutIfModifiedSince(request); } }
private Message handleRequestWithoutAcceptCharset(final Request request) { if (request.containsHeader(Header.RANGE)) { return handleRequestWithRange(request); } else { return handleRequestWithoutRange(request); } }
private Message handleRequestWithoutAcceptLanguage(final Request request) { if (request.containsHeader(Header.ACCEPT_CHARSET)) { return handleRequestWithAcceptCharset(request); } else { return handleRequestWithoutAcceptCharset(request); } }
private Message handleRequestWithoutAccept(final Request request) { if (request.containsHeader(Header.ACCEPT_LANGUAGE)) { return handleRequestWithAcceptLanguage(request); } else { return handleRequestWithoutAcceptLanguage(request); } }
private Message handleRequestWithoutIfNoneMatch(Request request) throws IOException { if (request.containsHeader(Header.IF_MODIFIED_SINCE)) { return handleRequestWithIfModifiedSince(request); } else { return handleRequestWithoutIfModifiedSince(request); } }
private Message handleRequestWithoutIfUnmodifiedSince(Request request) throws IOException { if (request.containsHeader(Header.IF_NONE_MATCH)) { return handleRequestWithIfNoneMatch(); } else { return handleRequestWithoutIfNoneMatch(request); } }
@PROPPATCH public Message proppatch(@PathTranslated Path path, @Context Request request, Depth depth) throws IOException { final Resource resource = resolveResource(path); final Iterable<QName> properties = getProperties(request.buffer()); final List<RESPONSE> responses = propfind(properties, resource, depth); return successMultiStatus(multistatus(responses)); }
private Message handleRequestWithoutIfModifiedSince(final Request request) throws IOException { switch (request.method()) { case POST: case PUT: // case DELETE: // return delete(request); case GET: case HEAD: if (request.headers().containsKey(Header.ACCEPT)) { return handleRequestWithAccept(request); } else { return handleRequestWithoutAccept(request); } default: return clientErrorMethodNotAllowed(); } }
private Message handleRequestWithoutRange(Request request) { final Path path = Path.fromUri(request.uri()); final Resource resource = resolveResource(path); try { return Response.build(SUCCESS_OK) .header(CONTENT_TYPE) .set(APPLICATION_OCTET_STREAM.toString()) .setBody(resource.channel()); } catch (IOException e) { return serverErrorInternal(); } }
@PUT public Message put(@PathTranslated Path path, @Context Request request) throws IOException { final Resource resource = resolveResource(path); if (!resource.parent().exists()) { return clientErrorConflict(); } if (resource.exists() && resource.isCollection()) { return clientErrorMethodNotAllowed(); } ByteBuffer entity = request.buffer(); resource.put(entity); return successCreated(); }
@MKCOL public Message mkcol(@PathTranslated Path path, @Context Request request) { final Resource resource = resolveResource(path); if (request.hasBody()) { return clientErrorUnsupportedMediaType(); } else { if (resource.exists()) { return clientErrorMethodNotAllowed(); } else { if (resource.parent().exists()) { return (resource.mkcol() ? successCreated() : serverErrorInternal()); } else { return clientErrorConflict(); } } } }
@PROPFIND public Message propfind(@PathTranslated Path path, Depth depth, @Context Request request) throws IOException { return propfind(path, depth, request.buffer()); }
private final Message getResource(final Request request) throws IOException { return request.containsHeader(Header.IF_MATCH) ? handleRequestWithIfMatch(request) : handleRequestWithoutIfMatch(request); }