diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ContentResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ContentResource.java index 59aa720955..014b9b90ef 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ContentResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ContentResource.java @@ -38,19 +38,7 @@ public class ContentResource { @Path("{revision}/{path: .*}") public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision, @PathParam("path") String path) { try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) { - StreamingOutput stream = os -> { - try { - repositoryService.getCatCommand().setRevision(revision).retriveContent(os, path); - } catch (PathNotFoundException e) { - LOG.debug("path '{}' not found in repository {}/{}", path, namespace, name, e); - throw new WebApplicationException(Status.NOT_FOUND); - } catch (RepositoryException e) { - LOG.info("error reading repository resource {} from {}/{}", path, namespace, name, e); - throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); - } - os.close(); - }; - + StreamingOutput stream = createStreamingOutput(namespace, name, revision, path, repositoryService); Response.ResponseBuilder responseBuilder = Response.ok(stream); return createContentHeader(namespace, name, revision, path, repositoryService, responseBuilder); } catch (RepositoryNotFoundException e) { @@ -59,6 +47,21 @@ public class ContentResource { } } + private StreamingOutput createStreamingOutput(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision, @PathParam("path") String path, RepositoryService repositoryService) { + return os -> { + try { + repositoryService.getCatCommand().setRevision(revision).retriveContent(os, path); + os.close(); + } catch (PathNotFoundException e) { + LOG.debug("path '{}' not found in repository {}/{}", path, namespace, name, e); + throw new WebApplicationException(Status.NOT_FOUND); + } catch (RepositoryException e) { + LOG.info("error reading repository resource {} from {}/{}", path, namespace, name, e); + throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); + } + }; + } + @HEAD @Path("{revision}/{path: .*}") public Response metadata(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision, @PathParam("path") String path) {