This commit is contained in:
René Pfeuffer
2018-08-14 13:09:43 +02:00
parent fdaff02e01
commit dcdab9a00e
2 changed files with 5 additions and 14 deletions

View File

@@ -27,17 +27,17 @@ public class ContentResource {
private static final Logger LOG = LoggerFactory.getLogger(ContentResource.class); private static final Logger LOG = LoggerFactory.getLogger(ContentResource.class);
private final RepositoryServiceFactory servicefactory; private final RepositoryServiceFactory serviceFactory;
@Inject @Inject
public ContentResource(RepositoryServiceFactory servicefactory) { public ContentResource(RepositoryServiceFactory serviceFactory) {
this.servicefactory = servicefactory; this.serviceFactory = serviceFactory;
} }
@GET @GET
@Path("{revision}/{path: .*}") @Path("{revision}/{path: .*}")
public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision, @PathParam("path") String 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))) { try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
try { try {
StreamingOutput stream = os -> { StreamingOutput stream = os -> {
@@ -72,7 +72,7 @@ public class ContentResource {
@HEAD @HEAD
@Path("{revision}/{path: .*}") @Path("{revision}/{path: .*}")
public Response metadata(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision, @PathParam("path") String path) { public Response metadata(@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))) { try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
try { try {
Response.ResponseBuilder responseBuilder = Response.ok(); Response.ResponseBuilder responseBuilder = Response.ok();

View File

@@ -115,15 +115,6 @@ public class ContentResourceTest {
assertEquals("application/octet-stream", response.getHeaderString("Content-Type")); assertEquals("application/octet-stream", response.getHeaderString("Content-Type"));
} }
@Test
public void shouldHandleExceptionsInStreamProcessing() throws Exception {
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "MissingFile");
ByteArrayOutputStream baos = readOutputStream(response);
assertEquals(404, response.getStatus());
}
private void mockContentFromResource(String fileName) throws Exception { private void mockContentFromResource(String fileName) throws Exception {
URL url = Resources.getResource(fileName); URL url = Resources.getResource(fileName);
mockContent(fileName, Resources.toByteArray(url)); mockContent(fileName, Resources.toByteArray(url));