From bb33b4ea12a66c1c81acdb9551b30a1ac5c8f4ce Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 20 Apr 2016 13:37:42 +0530 Subject: [PATCH 1/5] Parameterizing Content-Type and Accept headers. --- .../jaggeryapps/devicemgt/api/invoker-api.jag | 47 ++++++++++------ .../app/modules/backend-service-invoker.js | 54 ++++++++++--------- .../public/js/invoker-lib.js | 30 ++++++----- 3 files changed, 80 insertions(+), 51 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/invoker-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/invoker-api.jag index 45b91271436..ac587def72e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/invoker-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/invoker-api.jag @@ -30,11 +30,13 @@ var result; if (uriMatcher.match("/{context}/api/invoker/execute/")) { var method = request.getContent().actionMethod; - var targetURL = devicemgtProps.httpsURL + request.getContent().actionUrl; + var targetURL = getTargetUrl(devicemgtProps.httpsURL, request.getContent().actionUrl); var payload = request.getContent().actionPayload; + var contentType = request.getHeader(constants.CONTENT_TYPE_IDENTIFIER); + var acceptType = request.getHeader(constants.ACCEPT_IDENTIFIER); if (method == undefined && payload == undefined) { method = parse(request.getContent()).actionMethod; - targetURL = devicemgtProps.httpsURL + parse(request.getContent()).actionUrl; + targetURL = getTargetUrl(devicemgtProps.httpsURL, parse(request.getContent()).actionUrl); payload = parse(request.getContent()).actionPayload; } try { @@ -48,7 +50,9 @@ if (uriMatcher.match("/{context}/api/invoker/execute/")) { function (responsePayload) { response.status = responsePayload.status; response.content = responsePayload.responseText; - }); + }, + contentType, + acceptType); break; case constants.HTTP_POST: var responseData = serviceInvokers.XMLHttp.post( @@ -59,7 +63,9 @@ if (uriMatcher.match("/{context}/api/invoker/execute/")) { function (responsePayload) { response.status = responsePayload.status; response.content = responsePayload.responseText; - }); + }, + contentType, + acceptType); break; case constants.HTTP_PUT: var responseData = serviceInvokers.XMLHttp.put( @@ -70,19 +76,22 @@ if (uriMatcher.match("/{context}/api/invoker/execute/")) { function (responsePayload) { response.status = responsePayload.status; response.content = responsePayload.responseText; - }); + }, + contentType, + acceptType); break; case constants.HTTP_DELETE: - var responseData = - serviceInvokers.XMLHttp.delete( - targetURL, function (responsePayload) { - response.status = 200; - response.content = responsePayload; - }, - function (responsePayload) { - response.status = responsePayload.status; - response.content = responsePayload.responseText; - }); + var responseData = serviceInvokers.XMLHttp.delete( + targetURL, function (responsePayload) { + response.status = 200; + response.content = responsePayload; + }, + function (responsePayload) { + response.status = responsePayload.status; + response.content = responsePayload.responseText; + }, + contentType, + acceptType); break; } } catch (e) { @@ -90,4 +99,12 @@ if (uriMatcher.match("/{context}/api/invoker/execute/")) { } } +function getTargetUrl(serverUrl, actionUrl){ + if(actionUrl == undefined || actionUrl.lastIndexOf("http", 0) === 0){ + return actionUrl; + } else { + return serverUrl + actionUrl; + } +} + %> diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js index 9aeb2e84de4..6e7540b3f00 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js @@ -54,11 +54,17 @@ var backendServiceInvoker = function () { * @param errorCallback a function to be called if en error is reserved. * @param count a counter which hold the number of recursive execution */ - privateMethods.execute = function (method, url, successCallback, errorCallback, payload, count) { + privateMethods.execute = function (method, url, successCallback, errorCallback, payload, count, contentType, acceptType) { var xmlHttpRequest = new XMLHttpRequest(); xmlHttpRequest.open(method, url); - xmlHttpRequest.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, constants.APPLICATION_JSON); - xmlHttpRequest.setRequestHeader(constants.ACCEPT_IDENTIFIER, constants.APPLICATION_JSON); + if(!contentType){ + contentType = constants.APPLICATION_JSON; + } + if(!acceptType){ + acceptType = constants.APPLICATION_JSON; + } + xmlHttpRequest.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, contentType); + xmlHttpRequest.setRequestHeader(constants.ACCEPT_IDENTIFIER, acceptType); if (IS_OAUTH_ENABLED) { var accessToken = privateMethods.getAccessToken(); if (!accessToken) { @@ -98,9 +104,9 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - privateMethods.initiateXMLHTTPRequest = function (method, url, successCallback, errorCallback, payload) { + privateMethods.initiateXMLHTTPRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) { if (privateMethods.getAccessToken()) { - return privateMethods.execute(method, url, successCallback, errorCallback, payload, 0); + return privateMethods.execute(method, url, successCallback, errorCallback, payload, 0, contentType, acceptType); } }; @@ -112,7 +118,7 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload) { + privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) { var HttpClient = Packages.org.apache.commons.httpclient.HttpClient; var httpMethodObject; switch (method) { @@ -138,11 +144,11 @@ var backendServiceInvoker = function () { var Header = Packages.org.apache.commons.httpclient.Header; var header = new Header(); header.setName(constants.CONTENT_TYPE_IDENTIFIER); - header.setValue(constants.APPLICATION_JSON); + header.setValue(contentType); httpMethodObject.addRequestHeader(header); header = new Header(); header.setName(constants.ACCEPT_IDENTIFIER); - header.setValue(constants.APPLICATION_JSON); + header.setValue(acceptType); httpMethodObject.addRequestHeader(header); if (IS_OAUTH_ENABLED) { var accessToken = privateMethods.getAccessToken(); @@ -226,8 +232,8 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicXMLHTTPInvokers.get = function (url, successCallback, errorCallback) { - return privateMethods.initiateXMLHTTPRequest(constants.HTTP_GET, url, successCallback, errorCallback); + publicXMLHTTPInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) { + return privateMethods.initiateXMLHTTPRequest(constants.HTTP_GET, url, successCallback, errorCallback, contentType, acceptType); }; /** @@ -237,8 +243,8 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicXMLHTTPInvokers.post = function (url, payload, successCallback, errorCallback) { - return privateMethods.initiateXMLHTTPRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload); + publicXMLHTTPInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) { + return privateMethods.initiateXMLHTTPRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType); }; /** @@ -248,8 +254,8 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicXMLHTTPInvokers.put = function (url, payload, successCallback, errorCallback) { - return privateMethods.initiateXMLHTTPRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload); + publicXMLHTTPInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) { + return privateMethods.initiateXMLHTTPRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType); }; /** @@ -258,8 +264,8 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicXMLHTTPInvokers.delete = function (url, successCallback, errorCallback) { - return privateMethods.initiateXMLHTTPRequest(constants.HTTP_DELETE, url, successCallback, errorCallback); + publicXMLHTTPInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) { + return privateMethods.initiateXMLHTTPRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType); }; /** @@ -281,8 +287,8 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicHTTPClientInvokers.get = function (url, successCallback, errorCallback) { - return privateMethods.initiateHTTPClientRequest(constants.HTTP_GET, url, successCallback, errorCallback); + publicHTTPClientInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) { + return privateMethods.initiateHTTPClientRequest(constants.HTTP_GET, url, successCallback, errorCallback, contentType, acceptType); }; /** @@ -292,9 +298,9 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback) { + publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) { return privateMethods. - initiateHTTPClientRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload); + initiateHTTPClientRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType); }; /** @@ -304,8 +310,8 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback) { - return privateMethods.initiateHTTPClientRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload); + publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) { + return privateMethods.initiateHTTPClientRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType); }; /** @@ -314,8 +320,8 @@ var backendServiceInvoker = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback) { - return privateMethods.initiateHTTPClientRequest(constants.HTTP_DELETE, url, successCallback, errorCallback); + publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) { + return privateMethods.initiateHTTPClientRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType); }; var publicInvokers = {}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js index 00aa67e7d58..c94345469fd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js @@ -22,33 +22,39 @@ var invokerUtil = function () { var END_POINT = window.location.origin+"/devicemgt/api/invoker/execute/"; - module.get = function (url, successCallback, errorCallback) { + module.get = function (url, successCallback, errorCallback, contentType, acceptType) { var payload = null; - execute("GET", url, payload, successCallback, errorCallback); + execute("GET", url, payload, successCallback, errorCallback, contentType, acceptType); }; - module.post = function (url, payload, successCallback, errorCallback) { - execute("POST", url, payload, successCallback, errorCallback); + module.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) { + execute("POST", url, payload, successCallback, errorCallback, contentType, acceptType); }; - module.put = function (url, payload, successCallback, errorCallback) { - execute("PUT", url, payload, successCallback, errorCallback); + module.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) { + execute("PUT", url, payload, successCallback, errorCallback, contentType, acceptType); }; - module.delete = function (url, successCallback, errorCallback) { + module.delete = function (url, successCallback, errorCallback, contentType, acceptType) { var payload = null; - execute("DELETE", url, payload, successCallback, errorCallback); + execute("DELETE", url, payload, successCallback, errorCallback, contentType, acceptType); }; - function execute (methoad, url, payload, successCallback, errorCallback) { + function execute (methoad, url, payload, successCallback, errorCallback, contentType, acceptType) { + if(contentType == undefined){ + contentType = "application/json"; + } + if(acceptType == undefined){ + acceptType = "application/json"; + } var data = { url: END_POINT, type: "POST", - contentType: "application/json", - accept: "application/json", + contentType: contentType, + accept: acceptType, success: successCallback }; console.log(data); var paramValue = {}; paramValue.actionMethod = methoad; paramValue.actionUrl = url; - paramValue.actionPayload = JSON.stringify(payload); + paramValue.actionPayload = payload; data.data = JSON.stringify(paramValue); $.ajax(data).fail(function (jqXHR) { if (jqXHR.status == "401") { From 2d44ec234b76cefc0365c4decfe24f6ce4c58832 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 20 Apr 2016 13:38:36 +0530 Subject: [PATCH 2/5] Now operations are auto generated and supports query params, path params and form params. --- .../feature/mgt/util/AnnotationUtil.java | 178 +++++++++++------- 1 file changed, 111 insertions(+), 67 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java index 621de443721..8941ad03125 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java @@ -35,6 +35,9 @@ import javax.ws.rs.HttpMethod; import javax.ws.rs.OPTIONS; import javax.ws.rs.POST; import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationHandler; @@ -61,7 +64,8 @@ public class AnnotationUtil { private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework"; public static final String STRING_ARR = "string_arr"; public static final String STRING = "string"; - private Class featureClazz; + private Class + featureAnnotationClazz; private ClassLoader classLoader; private ServletContext servletContext; @@ -108,7 +112,7 @@ public class AnnotationUtil { if (deviceTypeAnno != null) { Method[] deviceTypeMethod = deviceTypeClazz.getMethods(); String deviceType = invokeMethod(deviceTypeMethod[0], deviceTypeAnno, STRING); - featureClazz = + featureAnnotationClazz = (Class) classLoader.loadClass( org.wso2.carbon.device.mgt.extensions.feature.mgt @@ -130,80 +134,120 @@ public class AnnotationUtil { return features; } - private List getFeatures(Method[] annotatedMethods) throws Throwable { + private List getFeatures(Method[] methodsList) throws Throwable { List featureList = new ArrayList<>(); - for (Method method : annotatedMethods) { - Annotation methodAnnotation = method.getAnnotation(featureClazz); - if (methodAnnotation != null) { - Annotation[] annotations = method.getDeclaredAnnotations(); + for (Method currentMethod : methodsList) { + Annotation featureAnnotation = currentMethod.getAnnotation(featureAnnotationClazz); + if (featureAnnotation != null) { + Feature feature = new Feature(); + feature = processFeatureAnnotation(feature, currentMethod); + Annotation[] annotations = currentMethod.getDeclaredAnnotations(); + Feature.MetadataEntry metadataEntry = new Feature.MetadataEntry(); + metadataEntry.setId(-1); + Map apiParams = new HashMap<>(); for (int i = 0; i < annotations.length; i++) { - if (annotations[i].annotationType().getName().equals( - org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature.class.getName())) { - Feature feature = new Feature(); - Method[] featureAnnoMethods = featureClazz.getMethods(); - Annotation featureAnno = method.getAnnotation(featureClazz); - - for (int k = 0; k < featureAnnoMethods.length; k++) { - switch (featureAnnoMethods[k].getName()) { - case "name": - feature.setName(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - case "code": - feature.setCode(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - case "description": - feature.setDescription(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - case "type": - feature.setType(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - } - } - //Extracting method with which feature is exposed - if (annotations[i].annotationType().getName().equals(GET.class.getName())) { - feature.setMethod(HttpMethod.GET); - } - if (annotations[i].annotationType().getName().equals(POST.class.getName())) { - feature.setMethod(HttpMethod.POST); - } - if (annotations[i].annotationType().getName().equals(OPTIONS.class.getName())) { - feature.setMethod(HttpMethod.OPTIONS); - } - if (annotations[i].annotationType().getName().equals(DELETE.class.getName())) { - feature.setMethod(HttpMethod.DELETE); - } - if (annotations[i].annotationType().getName().equals(PUT.class.getName())) { - feature.setMethod(HttpMethod.PUT); - } - try { - Class formParamClazz = (Class) classLoader.loadClass( - FormParam.class.getName()); - Method[] formMethods = formParamClazz.getMethods(); - //Extract method parameter information and store same as feature meta info - List metaInfoList = new ArrayList<>(); - Annotation[][] paramAnnotations = method.getParameterAnnotations(); - for (int j = 0; j < paramAnnotations.length; j++) { - for (Annotation anno : paramAnnotations[j]) { - if (anno.annotationType().getName().equals(FormParam.class.getName())) { - Feature.MetadataEntry metadataEntry = new Feature.MetadataEntry(); - metadataEntry.setId(j); - metadataEntry.setValue(invokeMethod(formMethods[0], anno, STRING)); - metaInfoList.add(metadataEntry); - } - } - } - feature.setMetadataEntries(metaInfoList); - } catch (ClassNotFoundException e) { - log.debug("No Form Param found for class " + featureClazz.getName()); - } - featureList.add(feature); + Annotation currentAnnotation = annotations[i]; + feature = processHttpMethodAnnotation(feature, currentAnnotation); + if (currentAnnotation.annotationType().getName().equals(Path.class.getName())) { + String uri = getPathAnnotationValue(currentMethod); + apiParams.put("uri", uri); } + apiParams = processParamAnnotations(apiParams, currentMethod); } + metadataEntry.setValue(apiParams); + List metaInfoList = new ArrayList<>(); + metaInfoList.add(metadataEntry); + feature.setMetadataEntries(metaInfoList); + featureList.add(feature); } } return featureList; } + private Map processParamAnnotations(Map apiParams, Method currentMethod) throws Throwable{ + try { + apiParams.put("pathParams", processParamAnnotations(currentMethod, PathParam.class)); + apiParams.put("queryParams", processParamAnnotations(currentMethod, QueryParam.class)); + apiParams.put("formParams", processParamAnnotations(currentMethod, FormParam.class)); + } catch (ClassNotFoundException e) { + log.debug("No Form Param found for class " + featureAnnotationClazz.getName()); + } + return apiParams; + } + + private List processParamAnnotations(Method currentMethod, Class clazz) throws Throwable{ + List params = new ArrayList<>(); + try { + Class paramClazz = (Class) classLoader.loadClass(clazz.getName()); + Method[] formMethods = paramClazz.getMethods(); + //Extract method parameter information and store same as feature meta info + Annotation[][] paramAnnotations = currentMethod.getParameterAnnotations(); + Method valueMethod = formMethods[0]; + for (int j = 0; j < paramAnnotations.length; j++) { + for (Annotation anno : paramAnnotations[j]) { + if (anno.annotationType().getName().equals(clazz.getName())) { + params.add(invokeMethod(valueMethod, anno, STRING)); + } + } + } + } catch (ClassNotFoundException e) { + log.debug("No "+ clazz.getName() +" Param found for class " + featureAnnotationClazz.getName()); + } + return params; + } + + private Feature processHttpMethodAnnotation(Feature feature, Annotation currentAnnotation) { + //Extracting method with which feature is exposed + if (currentAnnotation.annotationType().getName().equals(GET.class.getName())) { + feature.setMethod(HttpMethod.GET); + } else if (currentAnnotation.annotationType().getName().equals(POST.class.getName())) { + feature.setMethod(HttpMethod.POST); + } else if (currentAnnotation.annotationType().getName().equals(OPTIONS.class.getName())) { + feature.setMethod(HttpMethod.OPTIONS); + } else if (currentAnnotation.annotationType().getName().equals(DELETE.class.getName())) { + feature.setMethod(HttpMethod.DELETE); + } else if (currentAnnotation.annotationType().getName().equals(PUT.class.getName())) { + feature.setMethod(HttpMethod.PUT); + } + return feature; + } + + private Feature processFeatureAnnotation(Feature feature, Method currentMethod) throws Throwable{ + Method[] featureAnnoMethods = featureAnnotationClazz.getMethods(); + Annotation featureAnno = currentMethod.getAnnotation(featureAnnotationClazz); + for (int k = 0; k < featureAnnoMethods.length; k++) { + switch (featureAnnoMethods[k].getName()) { + case "name": + feature.setName(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; + case "code": + feature.setCode(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; + case "description": + feature.setDescription(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; + case "type": + feature.setType(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; + } + } + return feature; + } + + public String getPathAnnotationValue(Method currentMethod) throws Throwable{ + String uri = ""; + try { + Class pathClazz = (Class) classLoader.loadClass(Path.class.getName()); + Annotation pathAnnno = currentMethod.getAnnotation(pathClazz); + Method[] pathMethods = pathClazz.getMethods(); + Method valueMethod = pathMethods[0]; + uri = invokeMethod(valueMethod, pathAnnno, STRING); + } catch (ClassNotFoundException e) { + log.debug("No Path Param found for class " + featureAnnotationClazz.getName()); + } + return uri; + } + /** * When an annotation and method is passed, this method invokes that executes said method against the annotation */ From 6ec5b7a85a21ae0d489e313b196639d3b8b48e3c Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 20 Apr 2016 13:42:25 +0530 Subject: [PATCH 3/5] Reading Http Method from Features --- .../resources/jaggeryapps/devicemgt/app/modules/operation.js | 1 + 1 file changed, 1 insertion(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js index 75c9abe9e7e..c6219757082 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js @@ -60,6 +60,7 @@ var operationModule = function () { } feature["operation"] = features[i].code; feature["name"] = features[i].name; + feature["method"] = features[i].method; feature["description"] = features[i].description; feature["deviceType"] = deviceType; feature["params"] = []; From 69e38b3c9840b6cf017ec322838c01a7e143231a Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 20 Apr 2016 22:02:31 +0530 Subject: [PATCH 4/5] adding JSON strigify on payload if contentType is json --- .../public/js/invoker-lib.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js index c94345469fd..1a7c52198ba 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js @@ -55,6 +55,9 @@ var invokerUtil = function () { paramValue.actionMethod = methoad; paramValue.actionUrl = url; paramValue.actionPayload = payload; + if(acceptType == "application/json"){ + paramValue.actionPayload = JSON.stringify(payload); + } data.data = JSON.stringify(paramValue); $.ajax(data).fail(function (jqXHR) { if (jqXHR.status == "401") { From 8e7052e012a30915e80e0ebbb3e41179137f864b Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 20 Apr 2016 22:03:01 +0530 Subject: [PATCH 5/5] adding JSON strigify on payload if contentType is json --- .../public/js/invoker-lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js index 1a7c52198ba..15679db0630 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js @@ -55,7 +55,7 @@ var invokerUtil = function () { paramValue.actionMethod = methoad; paramValue.actionUrl = url; paramValue.actionPayload = payload; - if(acceptType == "application/json"){ + if(contentType == "application/json"){ paramValue.actionPayload = JSON.stringify(payload); } data.data = JSON.stringify(paramValue);