Skip to content

Commit e34d109

Browse files
committed
Fix: Solve complex type parameter null pass value
1 parent c54da54 commit e34d109

File tree

4 files changed

+7
-59
lines changed

4 files changed

+7
-59
lines changed
Binary file not shown.

dist/jmeter-plugins-dubbo-1.3.6.jar

-39 Bytes
Binary file not shown.

src/main/java/io/github/ningyu/jmeter/plugin/dubbo/sample/DubboSample.java

+5-57
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ private Object callDubbo(SampleResult res) {
359359
ApplicationConfig application = new ApplicationConfig();
360360
application.setName("DubboSample");
361361

362-
// 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
362+
// This instance is heavy, encapsulating the connection to the registry and the connection to the provider,
363+
// so please cache yourself, otherwise memory and connection leaks may occur.
363364
ReferenceConfig reference = new ReferenceConfig();
364365
// set application
365366
reference.setApplication(application);
@@ -403,7 +404,7 @@ private Object callDubbo(SampleResult res) {
403404
reference.setProtocol(rpcProtocol);
404405
break;
405406
default:
406-
// 直连方式
407+
// direct invoke provider
407408
StringBuffer sb = new StringBuffer();
408409
sb.append(getRpcProtocol()).append(getAddress()).append("/").append(getInterface());
409410
log.debug("rpc invoker url : " + sb.toString());
@@ -498,7 +499,8 @@ private Object callDubbo(SampleResult res) {
498499
res.setSuccessful(false);
499500
return ErrorCode.MISS_METHOD.getMessage();
500501
}
501-
// 不同的注册中心地址使用不同的cache对象
502+
503+
// The registry's address is to generate the ReferenceConfigCache key
502504
ReferenceConfigCache cache = ReferenceConfigCache.getCache(getAddress(), new KeyGenerator() {
503505
public String generateKey(ReferenceConfig<?> referenceConfig) {
504506
return referenceConfig.toString();
@@ -517,7 +519,6 @@ public String generateKey(ReferenceConfig<?> referenceConfig) {
517519
for(MethodArgument arg : args) {
518520
ClassUtils.parseParameter(paramterTypeList, parameterValuesList, arg);
519521
}
520-
//发起调用
521522
parameterTypes = paramterTypeList.toArray(new String[paramterTypeList.size()]);
522523
parameterValues = parameterValuesList.toArray(new Object[parameterValuesList.size()]);
523524
Object result = null;
@@ -545,57 +546,4 @@ public String generateKey(ReferenceConfig<?> referenceConfig) {
545546
// reference.destroy();
546547
}
547548
}
548-
549-
public static void main(String[] args) throws Exception {
550-
// ApplicationConfig application = new ApplicationConfig();
551-
// application.setName("DubboSample");
552-
//
553-
// // 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
554-
// ReferenceConfig reference = new ReferenceConfig();
555-
// // 引用远程服务
556-
// reference.setApplication(application);
557-
// RegistryConfig registry = null;
558-
//
559-
// StringBuffer sb = new StringBuffer();
560-
// sb.append("dubbo").append("://").append("192.168.6.47:20835").append("/").append("com.jiuyescm.tenant.api.IMenuResourceService");
561-
// log.debug("rpc invoker url : " + sb.toString());
562-
// reference.setUrl(sb.toString());
563-
// Class clazz = Class.forName("com.jiuyescm.tenant.api.IMenuResourceService");
564-
// reference.setInterface(clazz);
565-
// reference.setRetries(Integer.valueOf("0"));
566-
// reference.setCluster("failfast");
567-
// reference.setVersion("1.0.0");
568-
// reference.setTimeout(Integer.valueOf("1200000"));
569-
// Object target = reference.get();
570-
// Method method = null;
571-
// Object[] parameterValues = null;
572-
// Method[] methods = target.getClass().getMethods();
573-
// String methodName = "createMenuResourceMapping";
574-
// List<MethodArgument> list = new ArrayList<MethodArgument>();
575-
// list.add(new MethodArgument("java.util.List", "[{\"menuId\":30002,\"appId\":8,\"resourceId\":40052},{\"menuId\":30003,\"appId\":8,\"resourceId\":40052}]"));
576-
// Class clazz = Class.forName("com.jiuyescm.tenant.api.IResourceService");
577-
// String methodName = "query";
578-
// List<MethodArgument> list = new ArrayList<MethodArgument>();
579-
// list.add(new MethodArgument("com.jiuyescm.tenant.vo.ResourceVo", "{\"menuId\":30002,\"appId\":8,\"resourceId\":40052}"));
580-
// list.add(new MethodArgument("java.lang.Integer", "1"));
581-
// list.add(new MethodArgument("java.lang.Integer", "10"));
582-
// List<Object> parameterValuesList = null;
583-
// Class clazz = Class.forName("com.jiuyescm.tenant.api.IResourceService");
584-
// String methodName = "testMethod";
585-
// List<MethodArgument> list = new ArrayList<MethodArgument>();
586-
// list.add(new MethodArgument("java.util.Map", "{\"name\":\"name\",\"value\":{\"service\":\"test1\",\"url\":\"test\",\"action\":\"GET\",\"enabled\":true,\"isPublic\":false,\"appId\":8,\"menuId\":30001}}"));
587-
// list.add(new MethodArgument("java.util.List", "[{\"name\":1,\"value\":{\"service\":\"test1\",\"url\":\"test\",\"action\":\"GET\",\"enabled\":true,\"isPublic\":false,\"appId\":8,\"menuId\":30001}},{\"name\":2,\"value\":{\"service\":\"test1\",\"url\":\"test\",\"action\":\"GET\",\"enabled\":true,\"isPublic\":false,\"appId\":8,\"menuId\":30001}}]"));
588-
// Method[] methods = clazz.getMethods();
589-
// parameterValuesList = new ArrayList<Object>();
590-
// for (Method m : methods) {
591-
// if (m.getName().equals(methodName)) {
592-
// Type[] paramTypes = m.getGenericParameterTypes();
593-
// for (int j = 0; j < paramTypes.length; j++) {
594-
// ClassUtils.parseParameter(paramTypes[j], parameterValuesList, list.get(j));
595-
// }
596-
// }
597-
// }
598-
// System.out.println(int.class.getName());
599-
}
600-
601549
}

src/main/java/io/github/ningyu/jmeter/plugin/util/ClassUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ public static void parseParameter(List<String> paramterTypeList,
214214
} catch (ClassNotFoundException e) {
215215
//不是jdk或者lib下的类,使用通用map格式反序列化值
216216
paramterTypeList.add(arg.getParamType());
217-
parameterValuesList.add(JsonUtils.formJson(arg.getParamValue(), new TypeToken<HashMap<String,Object>>() {}.getType()));
217+
parameterValuesList.add(isBlank(arg.getParamValue()) ? null : JsonUtils.formJson(arg.getParamValue(), new TypeToken<HashMap<String,Object>>() {}.getType()));
218218
}
219219
}
220220
}
221221
} catch (Exception e) {
222-
throw new IllegalArgumentException("无效参数 => [ParamType="+arg.getParamType()+",ParamValue="+arg.getParamValue()+"]", e);
222+
throw new IllegalArgumentException("Invalid parameter => [ParamType="+arg.getParamType()+",ParamValue="+arg.getParamValue()+"]", e);
223223
}
224224
}
225225
}

0 commit comments

Comments
 (0)