Add filesystem artifact repository implementation (#336)

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2016-11-14 11:23:50 +01:00
committed by Kai Zimmermann
parent 9b42c8cf57
commit 8be49a1184
48 changed files with 682 additions and 425 deletions

View File

@@ -180,9 +180,9 @@ public final class RestResourceConversionHelper {
response.setHeader(CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal());
response.setHeader(CONTENT_LENGTH, String.valueOf(r.getLength()));
try {
copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId,
r.getStart(), r.getLength());
try (InputStream inputStream = file.getFileInputStream()) {
copyStreams(inputStream, response.getOutputStream(), controllerManagement, statusId, r.getStart(),
r.getLength());
} catch (final IOException e) {
LOG.error("fullfileRequest of file ({}) failed!", artifact.getFilename(), e);
throw new FileSteamingFailedException(artifact.getFilename());
@@ -246,8 +246,9 @@ public final class RestResourceConversionHelper {
response.setContentType("multipart/byteranges; boundary=" + MULTIPART_BOUNDARY);
response.setStatus(SC_PARTIAL_CONTENT);
try {
for (final ByteRange r : ranges) {
for (final ByteRange r : ranges) {
try (InputStream inputStream = file.getFileInputStream()) {
// Add multipart boundary and header fields for every range.
response.getOutputStream().println();
response.getOutputStream().println("--" + MULTIPART_BOUNDARY);
@@ -255,19 +256,26 @@ public final class RestResourceConversionHelper {
.println("Content-Range: bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal());
// Copy single part range of multi part range.
copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId,
r.getStart(), r.getLength());
copyStreams(inputStream, response.getOutputStream(), controllerManagement, statusId, r.getStart(),
r.getLength());
} catch (final IOException e) {
throwFileStreamingFailedException(artifact, e);
}
}
try {
// End with final multipart boundary.
response.getOutputStream().println();
response.getOutputStream().print("--" + MULTIPART_BOUNDARY + "--");
} catch (final IOException e) {
LOG.error("multipartRangeRequest of file ({}) failed!", artifact.getFilename(), e);
throw new FileSteamingFailedException(artifact.getFilename());
throwFileStreamingFailedException(artifact, e);
}
}
private static void throwFileStreamingFailedException(final Artifact artifact, final IOException e) {
LOG.error("multipartRangeRequest of file ({}) failed!", artifact.getFilename(), e);
throw new FileSteamingFailedException(artifact.getFilename());
}
private static void handleStandardRangeRequest(final Artifact artifact, final HttpServletResponse response,
final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId,
final List<ByteRange> ranges) {
@@ -276,9 +284,9 @@ public final class RestResourceConversionHelper {
response.setHeader(CONTENT_LENGTH, String.valueOf(r.getLength()));
response.setStatus(SC_PARTIAL_CONTENT);
try {
copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId,
r.getStart(), r.getLength());
try (InputStream inputStream = file.getFileInputStream()) {
copyStreams(inputStream, response.getOutputStream(), controllerManagement, statusId, r.getStart(),
r.getLength());
} catch (final IOException e) {
LOG.error("standardRangeRequest of file ({}) failed!", artifact.getFilename(), e);
throw new FileSteamingFailedException(artifact.getFilename());

View File

@@ -1,33 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.rest;
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
import org.eclipse.hawkbit.rest.configuration.RestConfiguration;
import org.eclipse.hawkbit.rest.util.FilterHttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
/**
* Abstract Test for Rest tests.
*/
@SpringApplicationConfiguration(classes = { RestConfiguration.class,
org.eclipse.hawkbit.RepositoryApplicationConfiguration.class })
public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractIntegrationTest {
@Autowired
private FilterHttpResponse filterHttpResponse;
@Override
protected DefaultMockMvcBuilder createMvcWebAppContext() {
final DefaultMockMvcBuilder createMvcWebAppContext = super.createMvcWebAppContext();
return createMvcWebAppContext.addFilter(filterHttpResponse);
}
}