bugfix: test parameter type conversion. resolve #328 (#332)
* bugfix: test parameter type conversion. resolve #328
* remove unused import
* add kryo dependency
* add license
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 @@
* 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 @@
* 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 <https://js.foundation/>
+
+Based on Underscore.js, copyright Jeremy Ashkenas,
+DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
+
+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
@@ -130,6 +130,11 @@
</dependency>
<dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-serialization-kryo</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-version}</version>
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.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 @@
@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 @@
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 @@
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 @@
}
}
+// 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
@@ -114,6 +114,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-serialization-kryo</artifactId>
+ <version>${dubbo-version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator-version}</version>