From 1d3f5f39a7c38b2c741c679db8a0bdbb1ad8a239 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Sep 2016 14:33:53 +0530 Subject: [PATCH 1/6] Adding custom headers support to invoker util --- .../oauth/token-protected-service-invokers.js | 77 ++++++++++++------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 6520a819b5..a743acaae1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -66,11 +66,15 @@ var invokers = function () { * @param endpoint Backend REST API url. * @param responseCallback a function to be called with response retrieved. * @param count a counter which hold the number of recursive execution + * @param headers a list of name value pairs for additional http headers */ - privateMethods["execute"] = function (httpMethod, requestPayload, endpoint, responseCallback, count) { + privateMethods["execute"] = function (httpMethod, requestPayload, endpoint, responseCallback, count, headers) { var xmlHttpRequest = new XMLHttpRequest(); xmlHttpRequest.open(httpMethod, endpoint); + for(var i in headers){ + xmlHttpRequest.setRequestHeader(headers[i].name, headers[i].value); + } xmlHttpRequest.setRequestHeader(constants["CONTENT_TYPE_IDENTIFIER"], constants["APPLICATION_JSON"]); xmlHttpRequest.setRequestHeader(constants["ACCEPT_IDENTIFIER"], constants["APPLICATION_JSON"]); @@ -82,7 +86,7 @@ var invokers = function () { }); } else { xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"], - constants["BEARER_PREFIX"] + accessToken); + constants["BEARER_PREFIX"] + accessToken); } } @@ -98,9 +102,9 @@ var invokers = function () { log.debug("Response payload if any : " + xmlHttpRequest.responseText); if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || - xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { + xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { tokenUtil.refreshTokenPair(); - return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count); + return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers); } else { return responseCallback(xmlHttpRequest); } @@ -113,8 +117,8 @@ var invokers = function () { * @param endpoint Backend REST API url. * @param responseCallback a function to be called with response retrieved. */ - privateMethods["initiateXMLHTTPRequest"] = function (httpMethod, requestPayload, endpoint, responseCallback) { - return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0); + privateMethods["initiateXMLHTTPRequest"] = function (httpMethod, requestPayload, endpoint, responseCallback, headers) { + return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0, headers); }; /** @@ -122,9 +126,9 @@ var invokers = function () { * @param endpoint Backend REST API url. * @param responseCallback a function to be called with response retrieved. */ - publicXMLHTTPInvokers["get"] = function (endpoint, responseCallback) { + publicXMLHTTPInvokers["get"] = function (endpoint, responseCallback, headers) { var requestPayload = null; - return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback); + return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback, headers); }; /** @@ -133,8 +137,8 @@ var invokers = function () { * @param requestPayload payload/data if exists which is needed to be send. * @param responseCallback a function to be called with response retrieved. */ - publicXMLHTTPInvokers["post"] = function (endpoint, requestPayload, responseCallback) { - return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback); + publicXMLHTTPInvokers["post"] = function (endpoint, requestPayload, responseCallback, headers) { + return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback, headers); }; /** @@ -143,8 +147,8 @@ var invokers = function () { * @param requestPayload payload/data if exists which is needed to be send. * @param responseCallback a function to be called with response retrieved. */ - publicXMLHTTPInvokers["put"] = function (endpoint, requestPayload, responseCallback) { - return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback); + publicXMLHTTPInvokers["put"] = function (endpoint, requestPayload, responseCallback, headers) { + return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback, headers); }; /** @@ -152,9 +156,9 @@ var invokers = function () { * @param endpoint Backend REST API url. * @param responseCallback a function to be called with response retrieved. */ - publicXMLHTTPInvokers["delete"] = function (endpoint, responseCallback) { + publicXMLHTTPInvokers["delete"] = function (endpoint, responseCallback, headers) { var requestPayload = null; - return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint, responseCallback); + return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint, responseCallback, headers); }; /** @@ -239,8 +243,9 @@ var invokers = function () { * @param payload payload/data which need to be send. * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. + * @param headers a list of name value pairs for additional http headers. */ - privateMethods["initiateHTTPClientRequest"] = function (method, url, successCallback, errorCallback, payload) { + privateMethods["initiateHTTPClientRequest"] = function (method, url, successCallback, errorCallback, payload, headers) { //noinspection JSUnresolvedVariable var HttpClient = Packages.org.apache.commons.httpclient.HttpClient; var httpMethodObject; @@ -269,6 +274,14 @@ var invokers = function () { //noinspection JSUnresolvedFunction throw new IllegalArgumentException("Invalid HTTP request method: " + method); } + + for(var i in headers){ + var header = new Header(); + header.setName(headers[i].name); + header.setValue(headers[i].value); + httpMethodObject.addRequestHeader(header); + } + //noinspection JSUnresolvedVariable var Header = Packages.org.apache.commons.httpclient.Header; var header = new Header(); @@ -295,15 +308,19 @@ var invokers = function () { } } //noinspection JSUnresolvedFunction - var stringRequestEntity = new StringRequestEntity(stringify(payload)); - //noinspection JSUnresolvedFunction - httpMethodObject.setRequestEntity(stringRequestEntity); + if (payload != null) { + var StringRequestEntity = Packages.org.apache.commons.httpclient.methods.StringRequestEntity; + var stringRequestEntity = new StringRequestEntity(stringify(payload)); + //noinspection JSUnresolvedFunction + httpMethodObject.setRequestEntity(stringRequestEntity); + } var client = new HttpClient(); try { //noinspection JSUnresolvedFunction client.executeMethod(httpMethodObject); //noinspection JSUnresolvedFunction var status = httpMethodObject.getStatusCode(); + new Log().error(status); if (status == 200) { //noinspection JSUnresolvedFunction return successCallback(httpMethodObject.getResponseBody()); @@ -315,7 +332,9 @@ var invokers = function () { return errorCallback(response); } finally { //noinspection JSUnresolvedFunction - method.releaseConnection(); + if (method != constants["HTTP_GET"]) { + method.releaseConnection(); + } } }; @@ -324,11 +343,12 @@ var invokers = function () { * @param url target url. * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. + * @param headers a list of name value pairs for additional http headers. */ - publicHTTPClientInvokers["get"] = function (url, successCallback, errorCallback) { + publicHTTPClientInvokers["get"] = function (url, successCallback, errorCallback, headers) { var requestPayload = null; return privateMethods. - initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback, requestPayload); + initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback, requestPayload, headers); }; /** @@ -337,10 +357,11 @@ var invokers = function () { * @param payload payload/data which need to be send. * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. + * @param headers a list of name value pairs for additional http headers. */ - publicHTTPClientInvokers["post"] = function (url, payload, successCallback, errorCallback) { + publicHTTPClientInvokers["post"] = function (url, payload, successCallback, errorCallback, headers) { return privateMethods. - initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback, payload); + initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback, payload, headers); }; /** @@ -349,10 +370,11 @@ var invokers = function () { * @param payload payload/data which need to be send. * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. + * @param headers a list of name value pairs for additional http headers. */ - publicHTTPClientInvokers["put"] = function (url, payload, successCallback, errorCallback) { + publicHTTPClientInvokers["put"] = function (url, payload, successCallback, errorCallback, headers) { return privateMethods. - initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback, payload); + initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback, payload, headers); }; /** @@ -360,11 +382,12 @@ var invokers = function () { * @param url target url. * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. + * @param headers a list of name value pairs for additional http headers. */ - publicHTTPClientInvokers["delete"] = function (url, successCallback, errorCallback) { + publicHTTPClientInvokers["delete"] = function (url, successCallback, errorCallback, headers) { var requestPayload = null; return privateMethods. - initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback, requestPayload); + initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback, requestPayload, headers); }; var publicMethods = {}; From c6c555abc6a270a1ba812981a430f37c894ad97e Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Sep 2016 14:34:25 +0530 Subject: [PATCH 2/6] Fixing null pointer issue on mqtt notification strategy implementation --- .../provider/mqtt/MQTTNotificationStrategy.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java index ee4105922d..24d43a6ac3 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java @@ -20,6 +20,8 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; @@ -32,6 +34,7 @@ import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterExc import java.util.HashMap; import java.util.Map; +import java.util.Properties; public class MQTTNotificationStrategy implements NotificationStrategy { @@ -75,7 +78,16 @@ public class MQTTNotificationStrategy implements NotificationStrategy { @Override public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { Map dynamicProperties = new HashMap<>(); - dynamicProperties.put("topic", (String) ctx.getOperation().getProperties().get(MQTT_ADAPTER_TOPIC)); + Properties properties = ctx.getOperation().getProperties(); + if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) { + dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC)); + } else { + Operation operation = ctx.getOperation(); + String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" + + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType(); + dynamicProperties.put("topic", topic); + } + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, ctx.getOperation().getPayLoad()); } From 4691bedbc525d5e60609f38474e99a2dfb762a3f Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Sep 2016 14:35:17 +0530 Subject: [PATCH 3/6] Fixes to devices listing --- .../app/pages/cdmf.page.devices/devices.js | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js index d7a19da36b..ae506f4b07 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js @@ -24,22 +24,22 @@ function onRequest(context) { var groupName = request.getParameter("groupName"); var groupOwner = request.getParameter("groupOwner"); - var page = {}; + var viewModel = {}; var title = "Devices"; if (groupName) { title = groupName + " " + title; - page.groupName = groupName; + viewModel.groupName = groupName; } - page.title = title; + viewModel.title = title; var currentUser = session.get(constants.USER_SESSION_KEY); if (currentUser) { - page.permissions = {}; + viewModel.permissions = {}; var uiPermissions = userModule.getUIPermissions(); - page.permissions.list = stringify(uiPermissions); + viewModel.permissions.list = stringify(uiPermissions); if (uiPermissions.ADD_DEVICE) { - page.permissions.enroll = true; + viewModel.permissions.enroll = true; } - page.currentUser = currentUser; + viewModel.currentUser = currentUser; var deviceCount = 0; if (groupName && groupOwner) { var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; @@ -48,30 +48,30 @@ function onRequest(context) { deviceCount = deviceModule.getDevicesCount(); } if (deviceCount > 0) { - page.deviceCount = deviceCount; + viewModel.deviceCount = deviceCount; var utility = require("/app/modules/utility.js").utility; var typesListResponse = deviceModule.getDeviceTypes(); var deviceTypes = []; if (typesListResponse["status"] == "success") { - var data = typesListResponse["content"]; + var data = typesListResponse.content.deviceTypes; if (data) { for (var i = 0; i < data.length; i++) { - var config = utility.getDeviceTypeConfig(data[i].name); + var config = utility.getDeviceTypeConfig(data[i]); if (!config) { continue; } var deviceType = config.deviceType; deviceTypes.push({ - "type": data[i].name, - "category": deviceType.category, - "label": deviceType.label, - "thumb": utility.getDeviceThumb(data[i].name) - }); + "type": data[i], + "category": deviceType.category, + "label": deviceType.label, + "thumb": utility.getDeviceThumb(data[i]) + }); } } } - page.deviceTypes = stringify(deviceTypes); + viewModel.deviceTypes = stringify(deviceTypes); } } - return page; + return viewModel; } From 728307defda4856abd8219b0e04c84ee5bd4b368 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Sep 2016 14:57:00 +0530 Subject: [PATCH 4/6] Adding bundle import --- .../pom.xml | 1 + .../notification/provider/mqtt/MQTTNotificationStrategy.java | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index 54f056436e..4402eacd05 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -139,6 +139,7 @@ org.wso2.carbon.context, org.wso2.carbon.device.mgt.common.operation.mgt, org.wso2.carbon.device.mgt.common.push.notification, + org.wso2.carbon.device.mgt.common, org.wso2.carbon.device.mgt.core.service, org.wso2.carbon.event.output.adapter.core, org.wso2.carbon.event.output.adapter.core.exception, diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java index 24d43a6ac3..29d623b349 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java @@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; @@ -82,9 +81,8 @@ public class MQTTNotificationStrategy implements NotificationStrategy { if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) { dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC)); } else { - Operation operation = ctx.getOperation(); String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" - + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType(); + + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + ctx.getOperation().getType(); dynamicProperties.put("topic", topic); } From eb5a36ef4234400f037424ff3172bb312ab9be9f Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Sep 2016 15:52:52 +0530 Subject: [PATCH 5/6] Supporting stream download on service invoker --- .../oauth/token-protected-service-invokers.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index a743acaae1..d4fdbc3e89 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -275,6 +275,8 @@ var invokers = function () { throw new IllegalArgumentException("Invalid HTTP request method: " + method); } + //noinspection JSUnresolvedVariable + var Header = Packages.org.apache.commons.httpclient.Header; for(var i in headers){ var header = new Header(); header.setName(headers[i].name); @@ -282,8 +284,6 @@ var invokers = function () { httpMethodObject.addRequestHeader(header); } - //noinspection JSUnresolvedVariable - var Header = Packages.org.apache.commons.httpclient.Header; var header = new Header(); header.setName(constants["CONTENT_TYPE_IDENTIFIER"]); header.setValue(constants["APPLICATION_JSON"]); @@ -320,12 +320,14 @@ var invokers = function () { client.executeMethod(httpMethodObject); //noinspection JSUnresolvedFunction var status = httpMethodObject.getStatusCode(); - new Log().error(status); if (status == 200) { - //noinspection JSUnresolvedFunction - return successCallback(httpMethodObject.getResponseBody()); + var responseContentDispositionHeader = httpMethodObject.getResponseHeader(constants["CONTENT_DISPOSITION_IDENTIFIER"]); + if (responseContentDispositionHeader) { + return successCallback(httpMethodObject.getResponseBodyAsStream(), httpMethodObject.getResponseHeaders()); + } else { + return successCallback(httpMethodObject.getResponseBody()); + } } else { - //noinspection JSUnresolvedFunction return errorCallback(httpMethodObject.getResponseBody()); } } catch (e) { From 98ab29fe94f480de1af72ad7e78bd3d156e5b31c Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Sep 2016 15:53:16 +0530 Subject: [PATCH 6/6] Fixing virtual firealarm device agent download --- .../jaggeryapps/devicemgt/api/device-api.jag | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag index d0fc9c4f70..3e4c75a337 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag @@ -48,27 +48,28 @@ if (!user) { var deviceType = request.getParameter("deviceType"); // need a better solution here deviceTypeConfig = utility.getDeviceTypeConfig(deviceType); if (deviceTypeConfig && deviceTypeConfig.deviceType.downloadAgentUri) { + hearders = [{"name": constants["ACCEPT_IDENTIFIER"], "value": constants["APPLICATION_ZIP"]}]; sketchDownloadEndPoint = devicemgtProps["httpsURL"] + "/" + deviceTypeConfig.deviceType.downloadAgentUri; serviceInvokers.HttpClient.get(sketchDownloadEndPoint + queryString, function (responsePayload, responseHeaders) { - if (responseHeaders) { - for (var i = 0; i < responseHeaders.length; i++) { - var header = responseHeaders[i] - var headerName = String(header.getName()); - var headerValue = String(header.getValue()); - response.addHeader(headerName, headerValue); - } - var streamObject = new Stream(responsePayload); - print(streamObject); - } else { - return responsePayload; - } - }, function (responsePayload) { - log.error(responsePayload) - var response = {}; - response["status"] = "error"; - return response; - } - ); + if (responseHeaders) { + for (var i = 0; i < responseHeaders.length; i++) { + var header = responseHeaders[i]; + var headerName = String(header.getName()); + var headerValue = String(header.getValue()); + response.addHeader(headerName, headerValue); + } + var streamObject = new Stream(responsePayload); + print(streamObject); + } else { + return responsePayload; + } + }, function (responsePayload) { + log.error(responsePayload); + var response = {}; + response["status"] = "error"; + return response; + } + , hearders); } else { result = 400; } @@ -143,14 +144,14 @@ if (!user) { } serviceInvokers.XMLHttp.get( - targetURL, function (responsePayload) { - response.status = 200; - result = responsePayload; - }, - function (responsePayload) { - response.status = responsePayload.status; - result = responsePayload.responseText; - }); + targetURL, function (responsePayload) { + response.status = 200; + result = responsePayload; + }, + function (responsePayload) { + response.status = responsePayload.status; + result = responsePayload.responseText; + }); } else if (uriMatcher.match("/{context}/api/devices/")) { if (userModule.isAuthorized("/permission/admin/device-mgt/devices/list")) { result = deviceModule.listDevices();