mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge pull request #623 from sameeragunarathne/master
fix android apk install operation issue by checking resource access s…
This commit is contained in:
commit
6c6cde7df0
@ -72,6 +72,7 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
@ -1018,22 +1019,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasValidAPKContentType(String contentType){
|
|
||||||
if (contentType != null){
|
|
||||||
switch (contentType) {
|
|
||||||
case MediaType.APPLICATION_OCTET_STREAM:
|
|
||||||
case "application/android":
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void validateApplicationUrl(String apkUrl) {
|
private static void validateApplicationUrl(String apkUrl) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(apkUrl);
|
URL url = new URL(apkUrl);
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
if (!hasValidAPKContentType(conn.getContentType())) {
|
if(((HttpURLConnection) conn).getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||||
String errorMessage = "URL is not pointed to a downloadable file.";
|
String errorMessage = "URL is not pointed to a downloadable file.";
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user