Add artifact download API

This commit is contained in:
lasanthaDLPDS 2019-04-24 10:45:16 +05:30
parent c9f928915e
commit f1672ee961
3 changed files with 13 additions and 5 deletions

View File

@ -52,7 +52,12 @@ public class ArtifactDownloadAPIImpl implements ArtifactDownloadAPI {
AppmDataHandler dataHandler = APIUtil.getDataHandler();
try {
InputStream fileInputStream = dataHandler.getArtifactStream(uuid, fileName);
return Response.status(Response.Status.OK).entity(fileInputStream).build();
Response.ResponseBuilder response = Response
.ok(fileInputStream, MediaType.APPLICATION_OCTET_STREAM);
response.status(Response.Status.OK);
// response.type("application/html");
response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
return response.build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid + " and file name: " + fileName;
log.error(msg, e);

View File

@ -130,9 +130,8 @@ public class StorageManagementUtil {
if (!sourceFile.exists()){
return null;
}
try (InputStream inputStream = new FileInputStream(sourceFile)){
return inputStream;
try {
return new FileInputStream(sourceFile);
} catch (FileNotFoundException e) {
String msg = "Couldn't file the file in file path: " + filePath;
log.error(msg);

View File

@ -207,7 +207,11 @@ public class HandlerUtil {
resp.setCharacterEncoding("UTF-8");
proxyResponse.setExecutorResponse(null);
try (PrintWriter writer = resp.getWriter()) {
writer.write(gson.toJson(proxyResponse));
if (proxyResponse.getCode() == HttpStatus.SC_OK){
writer.write(gson.toJson(proxyResponse.getData()));
} else{
writer.write(proxyResponse.getData());
}
}
}