- public void handle(HttpExchange exchange) throws IOException {
- String method = exchange.getRequestMethod();
- if (DavMethod.PROPFIND.name().equals(method)) {
- handlePROPFIND(exchange);
- } else if (HttpMethod.GET.name().equals(method)) {
- handleGET(exchange);
- } else {
- throw new IllegalArgumentException("Unsupported method " + method);
+ protected void handleGET(HttpExchange exchange, String path) throws IOException {
+ ContentSession session = RemoteAuthUtils.doAs(() -> contentRepository.get(),
+ new RemoteAuthHttpExchange(exchange));
+ if (!session.exists(path)) // not found
+ throw new ContentNotFoundException(session, path);
+ Content content = session.get(path);
+ Optional<Long> size = content.get(DName.getcontentlength, Long.class);
+ try (InputStream in = content.open(InputStream.class)) {
+ exchange.sendResponseHeaders(HttpResponseStatus.OK.getCode(), size.orElse(0l));
+ StreamUtils.copy(in, exchange.getResponseBody());
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot process " + path, e);