alibaba / higress

Cloud Native API Gateway | 云原生API网关
https://higress.io
Apache License 2.0
2.5k stars 407 forks source link

http2dubbo 入参支持Integer类型 #1062

Open xgj2440620200 opened 4 days ago

xgj2440620200 commented 4 days ago

If you are reporting any crash or any potential security issue, do not open an issue in this repo. Please report the issue via ASRC(Alibaba Security Response Center) where the issue will be triaged appropriately.

Ⅰ. Issue Description

http2dubbo验证接口多参数、多类型,java dubbo 服务的接口参数声明为 string 和 integer 时,会报错 given param not match the type .

Ⅱ. Describe what happened

java dubbo 服务的接口参数分别string 和 string 不会报错,string 和 Long 不会报错, string 和 integer 是会报错 can not transcode the request because the given param not match the type

If there is an exception, please attach the exception trace: image

[Envoy (Epoch 0)] [2024-06-26 14:45:41.801][49][warning][filter] Failed to resolve headers, error is INVALID_ARGUMENT: can not transcode the request because the given param not match the type
{"authority":"localhost","bytes_received":"0","bytes_sent":"90","downstream_local_address":"172.23.0.7:80","downstream_remote_address":"172.23.0.1:59090","duration":"0","istio_policy_status":"-","method":"GET","path":"/dubbo/test?name=abcdddc&age=2","protocol":"HTTP/1.1","request_id":"381cf076-6c78-42d0-8159-d67c77fea2dc","requested_server_name":"-","response_code":"400","response_flags":"-","route_name":"-","start_time":"2024-06-26T14:45:41.801Z","trace_id":"-","upstream_cluster":"outbound|20880||providers:com.example.demo.dubbo.api.DemoService::.DEFAULT-GROUP.public.nacos","upstream_host":"-","upstream_local_address":"-","upstream_service_time":"-","upstream_transport_failure_reason":"-","user_agent":"curl/7.29.0","x_forwarded_for":"172.23.0.1"}

Ⅲ. Describe what you expected to happen

期望返回 {"result":"Hello abcdddc#2"}

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. 申明dubbo接口
    
    package com.example.demo.dubbo.api;

public interface DemoService {

String sayName(String name, Long age);

String sayHello(String name);

}

3. 实现 dubbo 接口

package com.example.demo.dubbo.service;

import com.example.demo.dubbo.api.DemoService;

import org.apache.dubbo.config.annotation.DubboService;

@DubboService public class DemoServiceImpl implements DemoService {

@Override
public String sayName(String name, Integer age ) {
    return "Hello " + name + "#" + age;
}

@Override
public String sayHello(String name) {
    return "Hello " + name;
}

}

5. 部署 dubbo 服务到nacos, 并参考 [http2dubbo](https://higress.cn/zh-cn/docs/user/dubbo),配好 http2dubbo 的路由和协议转换,其中CRD配置如下:

apiVersion: networking.higress.io/v1 kind: Http2Rpc metadata: name: httproute-http2rpc-demo namespace: higress-system spec: dubbo: service: com.example.demo.dubbo.api.DemoService version: group: methods:

7. curl 命令验证

单个参数

curl "localhost/dubbo/hello?name=abcdddc"

期待返回

{"result":"Hello abcdddc"}

多个参数,不同类型

curl "localhost/dubbo/test?name=abcdddc&age=2"

期待返回

{"result":"Hello abcdddc#2"}



### Ⅴ. Anything else we need to know?
拉了 higress 主分支的源码,搜到如下信息:
![image](https://github.com/alibaba/higress/assets/20533911/64bf50e2-f676-4697-ad1a-b4f51c00aac7)
![image](https://github.com/alibaba/higress/assets/20533911/2fb6c051-4786-461a-b1e8-72e99a1a052e)

### Ⅵ. Environment:

- Higress version:  1.4.0
- OS : centos7
- Others: java、dubbo3服务使用dubbo协议
johnlanni commented 4 days ago

cc @sjtuzbk

sjtuzbk commented 4 days ago

目前只支持Long,不支持Integer

johnlanni commented 4 days ago

@xgj2440620200 json 里的数字类型只能映射为一种固定的 java 类型,目前是 long

xgj2440620200 commented 3 days ago

@johnlanni dubbo 接口是旧服务, 里面是有些 Integer 类型的参数, 有没办法兼容呢

johnlanni commented 3 days ago

@sjtuzbk 帮忙修改下issue描述,方便社区同学认领开发