From eb5a36ef4234400f037424ff3172bb312ab9be9f Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Sep 2016 15:52:52 +0530 Subject: [PATCH 1/2] 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 2/2] 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();