diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/FileDownloaderServiceProvider.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/FileDownloaderServiceProvider.java index f8fe6f2f94..230869366e 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/FileDownloaderServiceProvider.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/FileDownloaderServiceProvider.java @@ -143,24 +143,35 @@ public class FileDownloaderServiceProvider { } return null; } - - String []urlSegments = url.toString().split("/"); - if (urlSegments.length < 1) { - if (log.isDebugEnabled()) { - log.debug("Cannot determine the file name for the remote file"); + String fullQualifiedName = null; + String query = url.getQuery(); + if (query != null && query.startsWith("fileName=")) { + String[] queryParts = query.split("=", 2); + if (queryParts.length > 1 && !queryParts[1].isEmpty()) { + fullQualifiedName = queryParts[1]; } - return null; } - - String fullQualifiedName = urlSegments[urlSegments.length - 1]; - String []fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)"); - if (fileNameSegments.length != 2) { + if (fullQualifiedName == null) { + String[] urlSegments = url.getPath().split("/"); + if (urlSegments.length > 0) { + fullQualifiedName = urlSegments[urlSegments.length - 1]; + } + } + if (fullQualifiedName != null) { + String[] fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)"); + if (fileNameSegments.length == 2) { + return fileNameSegments; + } else { + if (log.isDebugEnabled()) { + log.debug("Error encountered when constructing file name"); + } + } + } else { if (log.isDebugEnabled()) { - log.debug("Error encountered when constructing file name"); + log.debug("Cannot determine the file name for the remote file"); } - return null; } - return fileNameSegments; + return null; } /** diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/FileTransferServiceHelperUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/FileTransferServiceHelperUtil.java index 856faf4944..0542aba5a6 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/FileTransferServiceHelperUtil.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/FileTransferServiceHelperUtil.java @@ -183,6 +183,15 @@ public class FileTransferServiceHelperUtil { return fileDescriptorResolvedFromRelease; } + String file = urlPathSegments[urlPathSegments.length - 1]; + String query = downloadUrl.getQuery(); + if (query != null && query.startsWith("fileName=")) { + String[] queryParts = query.split("=", 2); + if (queryParts.length > 1 && !queryParts[1].isEmpty()) { + file = queryParts[1]; + } + } + if (urlPathSegments.length < 2) { if (log.isDebugEnabled()) { log.debug("URL patch segments contain less than 2 segments"); @@ -190,7 +199,6 @@ public class FileTransferServiceHelperUtil { return null; } - String file = urlPathSegments[urlPathSegments.length - 1]; String artifactHolder = urlPathSegments[urlPathSegments.length - 2]; try { FileDescriptor fileDescriptor = new FileDescriptor();