From 22f8d25aa0e1edc6940738bb6e2d8bd50d0d2da7 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Wed, 13 Mar 2019 10:08:56 +0800 Subject: [PATCH] bugfix: test parameter type conversion. resolve #328 (#332) * bugfix: test parameter type conversion. resolve #328 * remove unused import * add kryo dependency * add license --- dubbo-admin-distribution/src/LICENSE | 2 + .../src/licenses/LICENSE-lodash | 49 +++++++++++++++++++ dubbo-admin-server/pom.xml | 5 ++ .../service/impl/GenericServiceImpl.java | 10 ++-- dubbo-admin-ui/package.json | 1 + .../src/components/test/TestMethod.vue | 12 +++-- dubbo-admin-ui/src/util/index.js | 29 ++++++++++- pom.xml | 6 +++ 8 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 dubbo-admin-distribution/src/licenses/LICENSE-lodash diff --git a/dubbo-admin-distribution/src/LICENSE b/dubbo-admin-distribution/src/LICENSE index 18c5d21..46bfdf8 100644 --- a/dubbo-admin-distribution/src/LICENSE +++ b/dubbo-admin-distribution/src/LICENSE @@ -276,6 +276,7 @@ The text of each license is the standard Apache 2.0 license. * Apache: dubbo 2.7.0 https://raw.githubusercontent.com/apache/incubator-dubbo/dubbo-2.7.0/LICENSE Apache 2.0 - dubbo-2.7.0.jar + - dubbo-serialization-kryo-2.7.0.jar * Google: gson 2.8.4 https://raw.githubusercontent.com/google/gson/gson-parent-2.8.4/LICENSE Apache 2.0 - gson-2.8.4.jar @@ -412,6 +413,7 @@ The text of each license is also included at licenses/LICENSE-[project]. * vuejs: vue-router 3.0.1 https://raw.githubusercontent.com/vuejs/vue-router/v3.0.1/LICENSE MIT * vuetifyjs: vuetify 1.2.2 https://raw.githubusercontent.com/vuetifyjs/vuetify/v1.2.2/LICENSE MIT * vuejs: vuex 3.0.1 https://raw.githubusercontent.com/vuejs/vuex/v3.0.1/LICENSE MIT + * lodash: lodash 4.17.11 https://raw.githubusercontent.com/lodash/lodash/4.17.11/LICENSE MIT ======================================================================== diff --git a/dubbo-admin-distribution/src/licenses/LICENSE-lodash b/dubbo-admin-distribution/src/licenses/LICENSE-lodash new file mode 100644 index 0000000..8a5ea5e --- /dev/null +++ b/dubbo-admin-distribution/src/licenses/LICENSE-lodash @@ -0,0 +1,49 @@ +The MIT License + +Copyright JS Foundation and other contributors + +Based on Underscore.js, copyright Jeremy Ashkenas, +DocumentCloud and Investigative Reporters & Editors + +This software consists of voluntary contributions made by many +individuals. For exact contribution history, see the revision history +available at https://github.com/lodash/lodash + +The following license applies to all parts of this software except as +documented below: + +==== + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +==== + +Copyright and related rights for sample code are waived via CC0. Sample +code is defined as all source code displayed within the prose of the +documentation. + +CC0: http://creativecommons.org/publicdomain/zero/1.0/ + +==== + +Files located in the node_modules and vendor directories are externally +maintained libraries used by this software which have their own +licenses; we recommend you read them, as their terms may differ from the +terms above. diff --git a/dubbo-admin-server/pom.xml b/dubbo-admin-server/pom.xml index f7e1125..d968143 100644 --- a/dubbo-admin-server/pom.xml +++ b/dubbo-admin-server/pom.xml @@ -129,6 +129,11 @@ netty-all + + org.apache.dubbo + dubbo-serialization-kryo + + org.mockito mockito-core diff --git a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/service/impl/GenericServiceImpl.java b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/service/impl/GenericServiceImpl.java index 0e0a0db..508e90e 100644 --- a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/service/impl/GenericServiceImpl.java +++ b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/service/impl/GenericServiceImpl.java @@ -23,7 +23,6 @@ import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.rpc.service.GenericService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -31,8 +30,11 @@ import javax.annotation.PostConstruct; @Component public class GenericServiceImpl { private ApplicationConfig applicationConfig; - @Autowired - private Registry registry; + private final Registry registry; + + public GenericServiceImpl(Registry registry) { + this.registry = registry; + } @PostConstruct public void init() { @@ -42,7 +44,6 @@ public class GenericServiceImpl { applicationConfig = new ApplicationConfig(); applicationConfig.setName("dubbo-admin"); applicationConfig.setRegistry(registryConfig); - } public Object invoke(String service, String method, String[] parameterTypes, Object[] params) { @@ -57,6 +58,7 @@ public class GenericServiceImpl { reference.setVersion(version); reference.setGroup(group); GenericService genericService = reference.get(); + return genericService.$invoke(method, parameterTypes, params); } } diff --git a/dubbo-admin-ui/package.json b/dubbo-admin-ui/package.json index 7604a58..ed9a87b 100644 --- a/dubbo-admin-ui/package.json +++ b/dubbo-admin-ui/package.json @@ -16,6 +16,7 @@ "http-status": "^1.2.0", "js-yaml": "^3.12.0", "jsoneditor": "^5.26.2", + "lodash": "^4.17.11", "vue": "^2.5.2", "vue-clipboard2": "^0.2.1", "vue-i18n": "^8.6.0", diff --git a/dubbo-admin-ui/src/components/test/TestMethod.vue b/dubbo-admin-ui/src/components/test/TestMethod.vue index 32aa0e7..116d807 100644 --- a/dubbo-admin-ui/src/components/test/TestMethod.vue +++ b/dubbo-admin-ui/src/components/test/TestMethod.vue @@ -52,6 +52,8 @@ import JsonEditor from '@/components/public/JsonEditor' import Breadcrumb from '@/components/public/Breadcrumb' import axios from 'axios' + import set from 'lodash/set' + import util from '@/util' export default { name: 'TestMethod', @@ -110,11 +112,13 @@ }, convertType (params, types) { - for (let i = 0; i < params.length; i++) { - if (typeof types[i] === 'string' && typeof params[i] !== 'string') { - params[i] = String(params[i]) + const p = util.flattenObject(params) + const t = util.flattenObject(types) + Object.keys(p).forEach(key => { + if (typeof t[key] === 'string' && typeof p[key] !== 'string') { + set(params, key, String(p[key])) } - } + }) } }, mounted () { diff --git a/dubbo-admin-ui/src/util/index.js b/dubbo-admin-ui/src/util/index.js index 5cdd02b..03a9a3c 100644 --- a/dubbo-admin-ui/src/util/index.js +++ b/dubbo-admin-ui/src/util/index.js @@ -36,8 +36,35 @@ const toggleFullScreen = () => { } } +// Flatten all nested keys of an object to one level with values, whose keys can be parameter of lodash.set +// e.g.: [{username: 'a', age: 3}, {username: 'b', age: 4}] => {'0.username': 'a', '0.age': 3, '1.username': 'b', '1.age': 4} +const flattenObject = obj => { + const toReturn = {} + + for (let i in obj) { + if (!obj.hasOwnProperty(i)) { + continue + } + + if ((typeof obj[i]) === 'object' && obj[i] !== null) { + const flatObject = flattenObject(obj[i]) + for (let x in flatObject) { + if (!flatObject.hasOwnProperty(x)) { + continue + } + + toReturn[i + '.' + x] = flatObject[x] + } + } else { + toReturn[i] = obj[i] + } + } + return toReturn +} + export default { randomElement, toggleFullScreen, - kebab + kebab, + flattenObject } diff --git a/pom.xml b/pom.xml index dfb727c..e153dc7 100644 --- a/pom.xml +++ b/pom.xml @@ -113,6 +113,12 @@ ${dubbo-version} + + org.apache.dubbo + dubbo-serialization-kryo + ${dubbo-version} + + org.apache.curator curator-framework -- GitLab