Changing the image return to be a base6 format

feature/appm-store/pbac
megala21 7 years ago
parent b4b9fffad5
commit 48023c5d8b

@ -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,

@ -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 "

@ -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;
}
}

@ -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;
}

@ -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)"
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.application.mgt.core.internal.*,

@ -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);
}
}
}

@ -28,7 +28,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.publisher.ui</artifactId>
<version>3.0.46-SNAPSHOT</version>
<packaging>war</packaging>
<packaging>pom</packaging>
<name>WSO2 Carbon - Application Management Publisher UI</name>
<description>WSO2 Carbon - Application Management Publisher UI React Application</description>
<url>http://wso2.org</url>

Loading…
Cancel
Save