[BUG] <not support dubbo primitive type >
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
Interface
Student findById(long id)
Invoke Failure
Expected Behavior
No response
Steps To Reproduce
No response
Environment
ShenYu version(s): 2.4.2-SNAPSHOT
Debug logs
No response
Anything else?
No response
need more info
2021-11-30 10:30:52 [New I/O client worker #1-1] ERROR org.apache.shenyu.plugin.alibaba.dubbo.AlibabaDubboPlugin - dubbo failed using async genericInvoker() metaData=MetaData{id='1461601432558649344', appName='dubbo-sample-webapp', contextPath='/dubbo-sample-webapp', path='/dubbo-sample-webapp/student/findById', rpcType='dubbo', serviceName='com.meip.gateway.inf.StudentInterface', methodName='findById', parameterTypes='long', rpcExt='{"loadbalance":"random","retries":2,"timeout":3000,"sent":false}', enabled=true} param={"id":"10"}
java.lang.RuntimeException: java.lang.RuntimeException: Illegal constructor: long
java.lang.RuntimeException: Illegal constructor: long
at org.apache.dubbo.common.utils.PojoUtils.newInstance(PojoUtils.java:580)
at org.apache.dubbo.common.utils.PojoUtils.realize0(PojoUtils.java:472)
at org.apache.dubbo.common.utils.PojoUtils.realize(PojoUtils.java:212)
at org.apache.dubbo.common.utils.PojoUtils.realize(PojoUtils.java:99)
at org.apache.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:104)
at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$FilterChainNode.invoke(FilterChainBuilder.java:82)
at org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$FilterChainNode.invoke(FilterChainBuilder.java:82)
at org.apache.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:41)
at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$FilterChainNode.invoke(FilterChainBuilder.java:82)
at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:145)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:100)
at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:175)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)
at java.lang.Thread.run(Thread.java:748)
Interface
`public interface StudentInterface {
Student findById(long id);
List<Student> findByArrays(Long[] ids);
}`
impl
`@DubboService public class StudentInterfaceImpl implements StudentInterface {
@Override
@ShenyuDubboClient(path = "/student/findById")
public Student findById(long id) {
return Student.builder().id(id).age(20).height(170).name("测试").sex(Sex.MALE).build();
}
@Override
@ShenyuDubboClient(path = "/student/findByArrays")
public List<Student> findByArrays(Long[] ids) {
return Arrays.stream(ids).map(x -> Student.builder().id(x).age(20).height(170).name("测试").sex(Sex.MALE).build()).collect(Collectors.toList());
}
}`
this have error?
List
findByArrays(Long[] ids);
hi ,The error log contains' Illegal constructor: long ' , Your pojo object constructor has no parameters?
primitive type : long
public Student findById(long id) {
return Student.builder().id(id).age(20).height(170).name("测试").sex(Sex.MALE).build();
}
If is Long Then true
public Student findById(Long id)
Can see the Student ?
Request is error not Response
` @Data @Builder public class Student implements Serializable {
private long id;
private String name;
private int age;
private Sex sex;
private int height;
}
`
GenericService 这个接口只有一个方法,名为 $invoke,它接受三个参数,分别为方法名、方法参数类型数组和参数值数组;
对于方法参数类型数组
- 如果是基本类型,如 int 或 long,可以使用 int.class.getName()获取其类型;
- 如果是基本类型数组,如 int[],则可以使用 int[].class.getName();
- 如果是 POJO,则直接使用全类名,如 com.alibaba.dubbo.samples.generic.api.Params。
You can add @ NoArgsConstructor to Student
Or it could be a Dubbo BUG
ApacheDubboProxyService
Line : 84
` return Mono.fromFuture(invokeAsync(genericService, metaData.getMethodName(), pair.getLeft(), pair.getRight()).thenApply(ret -> { if (Objects.isNull(ret)) { ret = Constants.DUBBO_RPC_RESULT_EMPTY; } exchange.getAttributes().put(Constants.RPC_RESULT, ret); exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE, ResultEnum.SUCCESS.getName()); return ret; })).onErrorMap(exception -> exception instanceof GenericException ? new ShenyuException(((GenericException) exception).getExceptionMessage()) : new ShenyuException(exception));
`
pair.getRight() is wrong
BodyParamUtils.buildSingleParameter
can you fix it in BodyParamUtils.buildSingleParameter? @meiping05
I try it
Have Other Contact Information ?