From c34f3cf4c7d6bc58044af631d04b5eae2b97ff0b Mon Sep 17 00:00:00 2001 From: Turcy Date: Wed, 13 Nov 2019 18:45:50 +0530 Subject: [PATCH 1/2] Correct error message reference --- .../app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js index d5bd168f87d..90b40836a93 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js @@ -236,7 +236,7 @@ $(document).ready(function () { deviceType, function (data, textStatus, jqXHR) { if (jqXHR.status == 200) { - $(errorMsgIdentifier).addClass(" hidden"); + $(errorMsgWrapper).addClass(" hidden"); $("#modalDevice").modal('show'); } }, From 5483a06aa739b33877e184bcf9e273451b9dd822 Mon Sep 17 00:00:00 2001 From: Turcy Date: Wed, 13 Nov 2019 18:52:58 +0530 Subject: [PATCH 2/2] Add Content-length to artifact file response --- .../impl/ArtifactDownloadAPIImpl.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ArtifactDownloadAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ArtifactDownloadAPIImpl.java index d442de1b968..0d796a0c820 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ArtifactDownloadAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ArtifactDownloadAPIImpl.java @@ -17,6 +17,7 @@ package org.wso2.carbon.device.application.mgt.api.services.impl; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.api.services.ArtifactDownloadAPI; @@ -27,13 +28,15 @@ import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.io.InputStream; /** * Implementation of ApplicationDTO Management related APIs. @@ -54,13 +57,20 @@ public class ArtifactDownloadAPIImpl implements ArtifactDownloadAPI { @PathParam("folderName") String folderName, @PathParam("fileName") String fileName) { AppmDataHandler dataHandler = APIUtil.getDataHandler(); - try { - InputStream fileInputStream = dataHandler.getArtifactStream(tenantId, uuid, folderName, fileName); - Response.ResponseBuilder response = Response - .ok(fileInputStream, MediaType.APPLICATION_OCTET_STREAM); - response.status(Response.Status.OK); - response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\""); - return response.build(); + try (InputStream fileInputStream = dataHandler.getArtifactStream(tenantId, uuid, folderName, fileName)) { + byte[] content = IOUtils.toByteArray(fileInputStream); + try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { + Response.ResponseBuilder response = Response + .ok(binaryDuplicate, MediaType.APPLICATION_OCTET_STREAM); + response.status(Response.Status.OK); + response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\""); + response.header("Content-Length", content.length); + return response.build(); + } catch (IOException e) { + String msg = "Error occurred while creating input stream from buffer array. "; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } } catch (NotFoundException e) { String msg = "Couldn't find an application release for UUID: " + uuid + " and file name: " + fileName; log.error(msg, e); @@ -74,6 +84,10 @@ public class ArtifactDownloadAPIImpl implements ArtifactDownloadAPI { String msg = "Error occurred while getting the application release artifact file. "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (IOException e) { + String msg = "Error occurred while getting the byte array of application release artifact file. "; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } }