Skip to content

Commit

Permalink
Merge pull request #12475 from piyumaldk/thumbnail-import
Browse files Browse the repository at this point in the history
Fix API import failing if it has an icon
  • Loading branch information
piyumaldk authored Jul 2, 2024
2 parents 3dbc29b + 78398f7 commit 28d654f
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.axiom.om.util.AXIOMUtil;
import org.apache.axis2.Constants;
import org.apache.axis2.util.JavaUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -5611,19 +5612,17 @@ public Map<String, Object> searchPaginatedContent(String searchQuery, String org
@Override
public void setThumbnailToAPI(String apiId, ResourceFile resource, String organization) throws APIManagementException {

InputStream thumbnailImageContent = null;
try {
org.wso2.carbon.apimgt.persistence.dto.ResourceFile iconResourceFile = new org.wso2.carbon.apimgt.persistence.dto.ResourceFile(
resource.getContent(), resource.getContentType());
InputStream content = iconResourceFile.getContent();
content.mark(1);
if (content.read() == -1) {
thumbnailImageContent = iconResourceFile.getContent();
if (thumbnailImageContent.available() > 0) {
apiPersistenceInstance.saveThumbnail(new Organization(organization), apiId, iconResourceFile);
} else {
// Thumbnail deletion from publisher originally handled through the same PUT call
// It was decided after discussion to fix the deletion (U2 update) through the same originally used PUT
apiPersistenceInstance.deleteThumbnail(new Organization(organization), apiId);
} else {
// Content will be reset to re-read the stream from the beginning
content.reset();
apiPersistenceInstance.saveThumbnail(new Organization(organization), apiId, iconResourceFile);
}
} catch (ThumbnailPersistenceException e) {
if (e.getErrorHandler() == ExceptionCodes.API_NOT_FOUND) {
Expand All @@ -5633,6 +5632,8 @@ public void setThumbnailToAPI(String apiId, ResourceFile resource, String organi
}
} catch (IOException e) {
throw new APIManagementException("Error while reading input stream ", e);
} finally {
IOUtils.closeQuietly(thumbnailImageContent);
}
}

Expand Down

0 comments on commit 28d654f

Please sign in to comment.