diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java index 9c524570bac..722c79974a6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java @@ -651,7 +651,7 @@ public interface ApplicationManagementAPI { @GET @Path("/image-artifacts/{uuid}") - @Produces(MediaType.APPLICATION_OCTET_STREAM) + @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( consumes = MediaType.APPLICATION_JSON, 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/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java index 9cd5d0e9566..c73e2a8487c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java @@ -29,6 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.Filter; +import org.wso2.carbon.device.application.mgt.common.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; @@ -452,7 +453,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Override @GET @Path("/image-artifacts/{uuid}") - @Produces(MediaType.APPLICATION_OCTET_STREAM) + @Produces(MediaType.APPLICATION_JSON) public Response getApplicationImageArtifacts(@PathParam("uuid") String applicationUUID, @QueryParam("name") String name, @QueryParam("count") int count) { if (name == null || name.isEmpty()) { @@ -461,10 +462,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { - InputStream imageArtifact = applicationStorageManager.getImageArtifact(applicationUUID, name, count); - FileStreamingOutput fileStreamingOutput = new FileStreamingOutput(imageArtifact); - Response.ResponseBuilder response = Response.status(Response.Status.OK).entity(fileStreamingOutput); - response.header("Content-Disposition", "attachment; filename=\"" + name + "\""); + ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(applicationUUID, name, count); + Response.ResponseBuilder response = Response.status(Response.Status.OK).entity(imageArtifact); return response.build(); } catch (ApplicationStorageManagementException e) { log.error("Application Storage Management Exception while getting the image artifact " + name + " of " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ImageArtifact.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ImageArtifact.java new file mode 100644 index 00000000000..85626fab042 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ImageArtifact.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.application.mgt.common; + +/** + * This represents a image artifact of a application. Icon, Screen-shot or Banner. + * It consists of a name, type and base64 encoded string format of the image. + */ +public class ImageArtifact { + private String name; + private String type; + private String encodedImage; + + public String getType() { + return type; + } + + public String getEncodedImage() { + return encodedImage; + } + + public String getName() { + + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void setType(String type) { + this.type = type; + } + + public void setEncodedImage(String encodedImage) { + this.encodedImage = encodedImage; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java index 860812244ac..4f2b675dd67 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.application.mgt.common.services; +import org.wso2.carbon.device.application.mgt.common.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import java.io.InputStream; @@ -93,6 +94,6 @@ public interface ApplicationStorageManager { * @return the relevant image artifact. * @throws ApplicationStorageManagementException Application Storage Management Exception. */ - public InputStream getImageArtifact(String applicationUUID, String name, int count) throws + public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws ApplicationStorageManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index 495bc9c9731..9bcc817bef6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -75,7 +75,9 @@ org.wso2.carbon.user.core.*, org.wso2.carbon.user.api.*, org.wso2.carbon.ndatasource.core, - org.wso2.carbon + org.wso2.carbon, + org.apache.commons.io, + org.apache.commons.codec.binary;version="[1.4.0, 2.0.0)" !org.wso2.carbon.device.application.mgt.core.internal.*, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java index 287cd5370ba..97d0af23528 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java @@ -19,11 +19,14 @@ package org.wso2.carbon.device.application.mgt.core.impl; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; +import org.wso2.carbon.device.application.mgt.common.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; @@ -42,6 +45,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Files; import java.util.Arrays; import java.util.List; @@ -207,7 +211,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager } @Override - public InputStream getImageArtifact(String applicationUUID, String name, int count) throws + public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws ApplicationStorageManagementException { Application application = validateApplication(applicationUUID); validateImageArtifactNames(name); @@ -222,11 +226,19 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager "Image artifact " + name + " does not exist for the " + "application with UUID " + applicationUUID); } else { try { - return new FileInputStream(imageArtifactPath); + ImageArtifact imageArtifact = new ImageArtifact(); + imageArtifact.setName(imageFile.getName()); + imageArtifact.setType(Files.probeContentType(imageFile.toPath())); + byte[] imageBytes = IOUtils.toByteArray(new FileInputStream(imageArtifactPath)); + imageArtifact.setEncodedImage(Base64.encodeBase64URLSafeString(imageBytes)); + return imageArtifact; } catch (FileNotFoundException e) { throw new ApplicationStorageManagementException( "File not found exception while trying to get the image artifact " + name + " for the " + "application " + applicationUUID, e); + } catch (IOException e) { + throw new ApplicationStorageManagementException("IO Exception while trying to detect the image " + + "artifact " + name + " for the application " + applicationUUID, e); } } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml index 962be6a3df2..00548da9879 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml @@ -28,7 +28,7 @@ 4.0.0 org.wso2.carbon.device.application.mgt.publisher.ui 3.0.46-SNAPSHOT - war + pom WSO2 Carbon - Application Management Publisher UI WSO2 Carbon - Application Management Publisher UI React Application http://wso2.org diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/App.scss b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/App.css similarity index 100% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/App.scss rename to components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/App.css