HTTP协议转Dubbo2协议

插件信息

名称字段属性
http协议转dubbo2http-to-dubbo2协议转换

功能描述

将客户端 HTTP请求 转换成 Dubbo2请求 转发给上游服务,并将上游服务的 Dubbo2响应 转换成 HTTP响应 转发给客户端。该插件仅当路由驱动为http时生效。

注意事项

目前只支持读取http请求中body中的内容,且为json格式

Open Api

配置参数说明

参数名值类型是否必填值可能性默认值说明
servicestringapi.Server服务名
methodstringgetUser方法名
paramsarray_object对转发的body内容进行匹配,匹配成功后读取并解析成dubbo2协议所需要数据
params -> class_namestringcn.apinto.model.UserInfo对应java中的className 获取方法(user.getClass().getName())
params -> field_namestring否 (仅params长度为0时可不填)从body中提取的字段名,不填默认读取整个body

配置示例

dubbo2服务端接口配置
package cn.apinto.model;

public class User {
    String name;
    int id;
    Integer age;
}
package cn.apinto.api.UserService;

import cn.apinto.model.User;
import java.util.List;
import java.util.Map;

public interface UserService {
    User getUserByUser(User user);
    User getUserByName(String name);
    User getUserByNameByUser(String name,User user);
    Map<String,User> getUserMap(Map<String,User> users);
    List<User> getUserList(List<User> users);
}

测试用例1

插件配置
{
  "service": "cn.apinto.api.UserService",
  "method": "getUserByUser",
  "params": [
    {
      "class_name": "cn.apinto.model.User"
    }
  ]
}
http请求的body内容
{
  "name": "apinto",
  "id": 10,
  "age": 30
}

测试用例2

插件配置
{
  "service": "cn.apinto.api.UserService",
  "method": "getUserByName",
  "params": [
    {
      "class_name": "java.lang.String",
      "filed_name": "name"
    }
  ]
}
http请求的body内容
{
  "name": "apinto"
}

测试用例3

插件配置
{
  "service": "cn.apinto.api.UserService",
  "method": "getUserByNameByUser",
  "params": [
    {
      "class_name": "java.lang.String",
      "filed_name": "name"
    },
    {
      "class_name": "cn.apinto.model.User",
      "filed_name": "user"
    }
  ]
}
http请求的body内容
{
  "name": "apinto",
  "user": {
    "name": "apinto",
    "id": 10,
    "age": 30
  }
}

测试用例4

插件配置
{
  "service": "cn.apinto.api.UserService",
  "method": "getUserMap",
  "params": [
    {
      "class_name": "java.util.Map"
    }
  ]
}
http请求的body内容
{
  "user1": {
    "name": "apinto",
    "id": 1,
    "age": 10
  },
  "user2": {
    "name": "apinto",
    "id": 2,
    "age": 20
  },
  "user3": {
    "name": "apinto",
    "id": 3,
    "age": 30
  }
}

测试用例5

插件配置
{
  "service": "cn.apinto.api.UserService",
  "method": "getUserList",
  "params": [
    {
      "class_name": "java.util.List"
    }
  ]
}
http请求的body内容
[
  {
    "name": "apinto",
    "id": 1,
    "age": 10
  },
  {
    "name": "apinto",
    "id": 2,
    "age": 20
  },
  {
    "name": "apinto",
    "id": 3,
    "age": 30
  }
]