From ae3a219a78c937d40f3fb4a7e3bd77b2783fae29 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Mon, 25 Dec 2023 10:22:02 +0800 Subject: [PATCH 01/31] add http-dubbo plugin --- apisix/plugins/http-dubbo.lua | 225 ++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 apisix/plugins/http-dubbo.lua diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua new file mode 100644 index 000000000000..90c7fac5abc6 --- /dev/null +++ b/apisix/plugins/http-dubbo.lua @@ -0,0 +1,225 @@ +local require = require +local core = require("apisix.core") +local pairs = pairs +local str_format = string.format +local rshift = bit.rshift +local band = bit.band +local char = string.char +local tostring = tostring +local ngx = ngx +local type = type +local plugin_name = "http-dubbo" + +local schema = { + type = "object", + properties = { + service_name = { + type = "string", + minLength = 1, + }, + service_version = { + type = "string", + pattern = [[^\d+\.\d+\.\d+]], + }, + method = { + type = "string", + minLength = 1, + }, + params_type_desc = { + type = "string", + minLength = 1, + }, + serialization_header_key = { + type = "string" + }, + serialized = { + type = "boolean", + default = false + } + }, + required = { "service_name", "method", "params_type_desc" }, +} + +local _M = { + version = 0.1, + priority = 0, + name = plugin_name, + schema = schema, +} + +function _M.check_schema(conf) + return core.schema.check(schema, conf) +end + +local function str_int32(int) + return char(band(rshift(int, 24), 0xff), + band(rshift(int, 16), 0xff), + band(rshift(int, 8), 0xff), + band(int, 0xff)) +end + +local function parse_dubbo_header(header) + for i = 1, 16 do + local currentByte = header:byte(i) + if not currentByte then + return nil + end + end + + local magic_number = str_format("%04x", header:byte(1) * 256 + header:byte(2)) + local message_flag = header:byte(3) + local status = header:byte(4) + local request_id = 0 + for i = 5, 12 do + request_id = request_id * 256 + header:byte(i) + end + + local byte13Val = header:byte(13) * 256 * 256 * 256 + local byte14Val = header:byte(14) * 256 * 256 + local data_length = byte13Val + byte14Val + header:byte(15) * 256 + header:byte(16) + + local is_request = bit.band(bit.rshift(message_flag, 7), 0x01) == 1 and 1 or 0 + local is_two_way = bit.band(bit.rshift(message_flag, 6), 0x01) == 1 and 1 or 0 + local is_event = bit.band(bit.rshift(message_flag, 5), 0x01) == 1 and 1 or 0 + + return { + magic_number = magic_number, + message_flag = message_flag, + is_request = is_request, + is_two_way = is_two_way, + is_event = is_event, + status = status, + request_id = request_id, + data_length = data_length + } +end + +local function string_to_json_string(str) + local result = "\"" + for i = 1, #str do + local byte = core.string.sub(str, i, i) + if byte == "\\" then + result = result .. "\\\\" + elseif byte == "\n" then + result = result .. "\\n" + elseif byte == "\t" then + result = result .. "\\t" + elseif byte == "\r" then + result = result .. "\\r" + elseif byte == "\b" then + result = result .. "\\b" + elseif byte == "\f" then + result = result .. "\\f" + elseif byte == "\"" then + result = result .. "\\\"" + else + result = result .. byte + end + end + return result .. "\"" +end + +local function get_dubbo_request(conf, ctx) + -- use dubbo and fastjson + local first_byte4 = "\xda\xbb\xc6\x00" + + local requestId = "\x00\x00\x00\x00\x00\x00\x00\x01" + local version = "\"2.0.2\"\n" + local service = "\"" .. conf.service_name .. "\"" .. "\n" + + local service_version + if not conf.service_version then + service_version = "0.0.0" + else + service_version = conf.service_version + end + service_version = "\"" .. service_version .. "\"" .. "\n" + local method_name = "\"" .. conf.method .. "\"" .. "\n" + + local params_desc = "\"" .. conf.params_type_desc .. "\"" .. "\n" + local params = "" + local serialized = conf.serialized + if conf.serialization_header_key then + local serialization_header = core.request.header(ctx, conf.serialization_header_key) + serialized = serialization_header == "true" + end + if serialized then + params = core.request.get_body() .. "\n" + local end_of_params = core.string.sub(params, -1) + if not end_of_params == "\n" then + params = params .. "\n" + end + else + local body_data = core.request.get_body() + if body_data then + local lua_object = core.json.decode(body_data); + for k, v in pairs(lua_object) do + local pt = type(v) + if pt == "nil" then + params = params .. "null" .. "\n" + elseif pt == "string" then + params = params .. string_to_json_string(v) .. "\n" + elseif pt == "number" then + params = params .. tostring(v) .. "\n" + else + params = params .. core.json.encode(v) .. "\n" + end + end + else + ngx.say("Failed to get request body data.") + return + end + end + local attachments = "{}\n" + + local payload = #version + #service + #service_version + #method_name + #params_desc + #params + #attachments + return { + first_byte4, + requestId, + str_int32(payload), + version, + service, + service_version, + method_name, + params_desc, + params, + attachments + } +end + +function _M.before_proxy(conf, ctx) + local sock = ngx.socket.tcp() + sock:settimeouts(6000, 6000, 6000) -- one second timeout + local ok, err = sock:connect(ctx.picked_server.host, ctx.picked_server.port) + if not ok then + ngx.say("failed to connect to upstream ", err) + return + end + local request = get_dubbo_request(conf, ctx) + local bytes, err = sock:send(request) + if bytes > 0 then + local header, err = sock:receiveany(16); + if header then + local header_info = parse_dubbo_header(header) + if header_info and header_info.status == 20 then + local readline = sock:receiveuntil("\n") + local body_status, err, partial = readline() + + if body_status then + local response_status = core.string.sub(body_status, 1, 1) + if response_status == "2" or response_status == "5" then + return 200 + elseif response_status == "1" or response_status == "4" then + local body, err, partial = readline() + return 200, body + end + end + end + end + end + sock:close() + return 500 + +end + +return _M From 1445d09be1d2f84389417ee1d6fa3c84349384a5 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Mon, 25 Dec 2023 11:00:42 +0800 Subject: [PATCH 02/31] fix params append --- apisix/plugins/http-dubbo.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index 90c7fac5abc6..b3addcd85c85 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -144,7 +144,7 @@ local function get_dubbo_request(conf, ctx) serialized = serialization_header == "true" end if serialized then - params = core.request.get_body() .. "\n" + params = core.request.get_body() local end_of_params = core.string.sub(params, -1) if not end_of_params == "\n" then params = params .. "\n" From d129cf31a24304e019362da997182f093f1eb500 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Mon, 25 Dec 2023 11:06:44 +0800 Subject: [PATCH 03/31] add License --- apisix/plugins/http-dubbo.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index b3addcd85c85..4481c47085be 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -1,3 +1,20 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + local require = require local core = require("apisix.core") local pairs = pairs From 202a523812e6b0ec406d2b670063d2b644e6a6f8 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 10 Jan 2024 14:56:20 +0800 Subject: [PATCH 04/31] add http-dubbo test cases and fix cr --- .github/workflows/gm-cron.yaml | 5 + apisix/plugins/http-dubbo.lua | 46 +++--- conf/config-default.yaml | 1 + .../pom.xml | 46 ++++++ .../DubboSerializationTestService.java | 109 ++++++++++++++ .../java/org/apache/dubbo/backend/PoJo.java | 135 ++++++++++++++++++ .../pom.xml | 97 +++++++++++++ .../DubboSerializationTestServiceImpl.java | 58 ++++++++ .../dubbo/backend/provider/Provider.java | 50 +++++++ .../META-INF/spring/dubbo-demo-provider.xml | 38 +++++ .../src/main/resources/dubbo.properties | 17 +++ .../src/main/resources/log4j.properties | 23 +++ .../META-INF/spring/dubbo-demo-provider.xml | 38 +++++ .../target/classes/dubbo.properties | 17 +++ .../target/classes/log4j.properties | 23 +++ t/lib/dubbo-serialization-backend/pom.xml | 97 +++++++++++++ t/plugin/http-dubbo.t | 76 ++++++++++ 17 files changed, 860 insertions(+), 16 deletions(-) create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/pom.xml create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/pom.xml create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/dubbo.properties create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/log4j.properties create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/META-INF/spring/dubbo-demo-provider.xml create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/dubbo.properties create mode 100644 t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/log4j.properties create mode 100644 t/lib/dubbo-serialization-backend/pom.xml create mode 100644 t/plugin/http-dubbo.t diff --git a/.github/workflows/gm-cron.yaml b/.github/workflows/gm-cron.yaml index b90abaf14b8c..61a3594234d8 100644 --- a/.github/workflows/gm-cron.yaml +++ b/.github/workflows/gm-cron.yaml @@ -124,11 +124,16 @@ jobs: - name: Start Dubbo Backend if: steps.test_env.outputs.type == 'plugin' run: | + cur_dir=$(pwd) sudo apt install -y maven cd t/lib/dubbo-backend mvn package cd dubbo-backend-provider/target java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log & + cd $cur_dir/t/lib/dubbo-serialization-backend + mvn package + cd dubbo-serialization-backend-provider + java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java2.log & - name: Build xDS library if: steps.test_env.outputs.type == 'last' diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index 4481c47085be..2335d7c5a124 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -37,6 +37,7 @@ local schema = { service_version = { type = "string", pattern = [[^\d+\.\d+\.\d+]], + default ="0.0.0" }, method = { type = "string", @@ -52,6 +53,18 @@ local schema = { serialized = { type = "boolean", default = false + }, + connect_timeout={ + type = "number", + default = 6000 + }, + read_timeout={ + type = "number", + default = 6000 + }, + send_timeout={ + type = "number", + default = 6000 } }, required = { "service_name", "method", "params_type_desc" }, @@ -59,7 +72,7 @@ local schema = { local _M = { version = 0.1, - priority = 0, + priority = 504, name = plugin_name, schema = schema, } @@ -144,13 +157,7 @@ local function get_dubbo_request(conf, ctx) local version = "\"2.0.2\"\n" local service = "\"" .. conf.service_name .. "\"" .. "\n" - local service_version - if not conf.service_version then - service_version = "0.0.0" - else - service_version = conf.service_version - end - service_version = "\"" .. service_version .. "\"" .. "\n" + local service_version = "\"" .. conf.service_version .. "\"" .. "\n" local method_name = "\"" .. conf.method .. "\"" .. "\n" local params_desc = "\"" .. conf.params_type_desc .. "\"" .. "\n" @@ -162,8 +169,12 @@ local function get_dubbo_request(conf, ctx) end if serialized then params = core.request.get_body() - local end_of_params = core.string.sub(params, -1) - if not end_of_params == "\n" then + if params then + local end_of_params = core.string.sub(params, -1) + if not (end_of_params == "\n") then + params = params .. "\n" + end + else params = params .. "\n" end else @@ -183,9 +194,9 @@ local function get_dubbo_request(conf, ctx) end end else - ngx.say("Failed to get request body data.") - return + params = params .. "\n" end + end local attachments = "{}\n" @@ -206,11 +217,13 @@ end function _M.before_proxy(conf, ctx) local sock = ngx.socket.tcp() - sock:settimeouts(6000, 6000, 6000) -- one second timeout + + sock:settimeouts(conf.connect_timeout, conf.send_timeout, conf.read_timeout) -- one second timeout local ok, err = sock:connect(ctx.picked_server.host, ctx.picked_server.port) if not ok then - ngx.say("failed to connect to upstream ", err) - return + sock:close() + core.log.error("failed to connect to upstream ", err) + return 502 end local request = get_dubbo_request(conf, ctx) local bytes, err = sock:send(request) @@ -221,13 +234,14 @@ function _M.before_proxy(conf, ctx) if header_info and header_info.status == 20 then local readline = sock:receiveuntil("\n") local body_status, err, partial = readline() - if body_status then local response_status = core.string.sub(body_status, 1, 1) if response_status == "2" or response_status == "5" then + sock:close() return 200 elseif response_status == "1" or response_status == "4" then local body, err, partial = readline() + sock:close() return 200, body end end diff --git a/conf/config-default.yaml b/conf/config-default.yaml index 6ab8db8aa608..a6479ac4486b 100755 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -499,6 +499,7 @@ plugins: # plugin list (sorted by priority) #- dubbo-proxy # priority: 507 - grpc-transcode # priority: 506 - grpc-web # priority: 505 + - http-dubbo # priority: 504 - public-api # priority: 501 - prometheus # priority: 500 - datadog # priority: 495 diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/pom.xml b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/pom.xml new file mode 100644 index 000000000000..883ff366aa1e --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + org.apache.dubbo.backend + dubbo-serialization-backend + 1.0.0-SNAPSHOT + ../pom.xml + + org.apache.dubbo.backend + dubbo-serialization-backend-interface + 1.0.0-SNAPSHOT + jar + ${project.artifactId} + + + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java new file mode 100644 index 000000000000..5c973281eaf1 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.backend; + +import java.util.List; +import java.util.Map; + +public interface DubboSerializationTestService { + + + + + AllDataTypesPOJO testPoJo(AllDataTypesPOJO input); + + AllDataTypesPOJO[] testPoJos(AllDataTypesPOJO[] input); + + + + // 方法测试 void 返回类型 + void testVoid(); + + // 方法测试失败 + void testFailure(); + + // 方法测试超时 + void testTimeout(); + + // 测试POJO包括所有数据类型 + class AllDataTypesPOJO { + private int intValue; + private long longValue; + private float floatValue; + private double doubleValue; + private char charValue; + private boolean booleanValue; + private byte byteValue; + + public int getIntValue() { + return intValue; + } + + public void setIntValue(int intValue) { + this.intValue = intValue; + } + + public long getLongValue() { + return longValue; + } + + public void setLongValue(long longValue) { + this.longValue = longValue; + } + + public float getFloatValue() { + return floatValue; + } + + public void setFloatValue(float floatValue) { + this.floatValue = floatValue; + } + + public double getDoubleValue() { + return doubleValue; + } + + public void setDoubleValue(double doubleValue) { + this.doubleValue = doubleValue; + } + + public char getCharValue() { + return charValue; + } + + public void setCharValue(char charValue) { + this.charValue = charValue; + } + + public boolean isBooleanValue() { + return booleanValue; + } + + public void setBooleanValue(boolean booleanValue) { + this.booleanValue = booleanValue; + } + + public byte getByteValue() { + return byteValue; + } + + public void setByteValue(byte byteValue) { + this.byteValue = byteValue; + } + } + +} diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java new file mode 100644 index 000000000000..780e8f14ae84 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java @@ -0,0 +1,135 @@ +package org.apache.dubbo.backend; + +import java.util.HashMap; +import java.util.Map; + +public class PoJo { + private String aString; + + private Boolean aBoolean; + private Byte aByte; + private Character acharacter; + private Integer aInt; + + private Float aFloat; + private Double aDouble; + private Long aLong; + private Short aShort; + + private String[] strings; + + private Map poJoMap; + + public String getaString() { + return aString; + } + + public void setaString(String aString) { + this.aString = aString; + } + + public Boolean getaBoolean() { + return aBoolean; + } + + public void setaBoolean(Boolean aBoolean) { + this.aBoolean = aBoolean; + } + + public Byte getaByte() { + return aByte; + } + + public void setaByte(Byte aByte) { + this.aByte = aByte; + } + + public Character getAcharacter() { + return acharacter; + } + + public void setAcharacter(Character acharacter) { + this.acharacter = acharacter; + } + + public Integer getaInt() { + return aInt; + } + + public void setaInt(Integer aInt) { + this.aInt = aInt; + } + + public Float getaFloat() { + return aFloat; + } + + public void setaFloat(Float aFloat) { + this.aFloat = aFloat; + } + + public Double getaDouble() { + return aDouble; + } + + public void setaDouble(Double aDouble) { + this.aDouble = aDouble; + } + + public Long getaLong() { + return aLong; + } + + public void setaLong(Long aLong) { + this.aLong = aLong; + } + + public Short getaShort() { + return aShort; + } + + public void setaShort(Short aShort) { + this.aShort = aShort; + } + + + + public Map getPoJoMap() { + return poJoMap; + } + + public void setPoJoMap(Map poJoMap) { + this.poJoMap = poJoMap; + } + + public String[] getStrings() { + return strings; + } + + public void setStrings(String[] strings) { + this.strings = strings; + } + + public static PoJo getTestInstance(){ + PoJo poJo = new PoJo(); + poJo.aBoolean =true; + poJo.aByte =1; + poJo.acharacter ='a'; + poJo.aInt =2; + poJo.aDouble = 1.1; + poJo.aFloat =1.2f; + poJo.aLong = 3L; + poJo.aShort = 4; + poJo.aString ="aa"; + HashMap poJoMap = new HashMap<>(); + poJoMap.put("key","value"); + poJo.poJoMap = poJoMap; + poJo.strings = new String[]{"aa","bb"}; + return poJo; + } + + public static void main(String[] args) { + + } + +} diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/pom.xml b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/pom.xml new file mode 100644 index 000000000000..b5b762f92f52 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + + org.apache.dubbo.backend + dubbo-serialization-backend + 1.0.0-SNAPSHOT + ../pom.xml + + org.apache.dubbo.backend + dubbo-serialization-backend-provider + 1.0.0-SNAPSHOT + jar + ${project.artifactId} + + + true + 1.7.25 + 2.12.0 + 2.7.21 + + + + + org.apache.dubbo.backend + dubbo-serialization-backend-interface + 1.0.0-SNAPSHOT + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + + + dubbo-demo-provider + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.apache.dubbo.backend.provider.Provider + + + + + + com.jolira + onejar-maven-plugin + 1.4.4 + + + + one-jar + + + + + + + diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java new file mode 100644 index 000000000000..5e0bfb81eda6 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.backend.provider; + +import org.apache.dubbo.backend.DubboSerializationTestService; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.lang.InterruptedException; + +public class DubboSerializationTestServiceImpl implements DubboSerializationTestService { + + @Override + public AllDataTypesPOJO testPoJo(AllDataTypesPOJO input) { + return input; + } + + @Override + public AllDataTypesPOJO[] testPoJos(AllDataTypesPOJO[] input) { + return input; + } + + @Override + public void testVoid() { + + + } + + @Override + public void testFailure() { + throw new RuntimeException("testFailure"); + } + + @Override + public void testTimeout() { + try { + TimeUnit.MINUTES.sleep(1); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java new file mode 100644 index 000000000000..c70f171732a3 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.backend.provider; + +import com.alibaba.fastjson.JSONObject; +import org.apache.dubbo.backend.DubboSerializationTestService; +import org.apache.dubbo.backend.PoJo; +import org.apache.dubbo.common.utils.ReflectUtils; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.lang.reflect.Method; +import java.util.concurrent.TimeUnit; +import java.lang.InterruptedException; + +public class Provider { + + /** + * To get ipv6 address to work, add + * System.setProperty("java.net.preferIPv6Addresses", "true"); + * before running your application. + */ + public static void main(String[] args) throws Exception { + + JSONObject.toJSONString(PoJo.getTestInstance()); + Method[] declaredMethods = DubboSerializationTestService.class.getDeclaredMethods(); + ReflectUtils.getDesc(declaredMethods[1].getParameterTypes()); + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-provider.xml"}); + + context.start(); + while (true) { + try { + TimeUnit.MINUTES.sleep(1); + } catch (InterruptedException ex) {} + } + } +} diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml new file mode 100644 index 000000000000..8dae775e4e49 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/dubbo.properties b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/dubbo.properties new file mode 100644 index 000000000000..258fd3bf2628 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/dubbo.properties @@ -0,0 +1,17 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +dubbo.application.qos.enable=false diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/log4j.properties b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/log4j.properties new file mode 100644 index 000000000000..2f4f4addf137 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/resources/log4j.properties @@ -0,0 +1,23 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +###set log levels### +log4j.rootLogger=info, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/META-INF/spring/dubbo-demo-provider.xml b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/META-INF/spring/dubbo-demo-provider.xml new file mode 100644 index 000000000000..8dae775e4e49 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/META-INF/spring/dubbo-demo-provider.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/dubbo.properties b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/dubbo.properties new file mode 100644 index 000000000000..258fd3bf2628 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/dubbo.properties @@ -0,0 +1,17 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +dubbo.application.qos.enable=false diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/log4j.properties b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/log4j.properties new file mode 100644 index 000000000000..2f4f4addf137 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/target/classes/log4j.properties @@ -0,0 +1,23 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +###set log levels### +log4j.rootLogger=info, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n diff --git a/t/lib/dubbo-serialization-backend/pom.xml b/t/lib/dubbo-serialization-backend/pom.xml new file mode 100644 index 000000000000..fe9f04229975 --- /dev/null +++ b/t/lib/dubbo-serialization-backend/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + org.apache.dubbo.backend + dubbo-serialization-backend + 1.0.0-SNAPSHOT + pom + ${project.artifactId} + A dubbo backend for test based on dubbo-samples-tengine + + true + 2.7.21 + + + dubbo-serialization-backend-interface + dubbo-serialization-backend-provider + + + + + + + org.springframework.boot + spring-boot-dependencies + 2.1.5.RELEASE + pom + import + + + org.apache.dubbo + dubbo-dependencies-bom + ${dubbo.version} + pom + import + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + org.springframework + spring + + + javax.servlet + servlet-api + + + log4j + log4j + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.1.5.RELEASE + + + org.apache.dubbo + dubbo-spring-boot-starter + 2.7.1 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t new file mode 100644 index 000000000000..98c00daf069b --- /dev/null +++ b/t/plugin/http-dubbo.t @@ -0,0 +1,76 @@ +use t::APISIX 'no_plan'; + +repeat_each(1); +no_long_string(); +no_shuffle(); +no_root_location(); +add_block_preprocessor(sub { + my ($block) = @_; + + + my $yaml_config = $block->yaml_config // <<_EOC_; +apisix: + node_listen: 1984 + enable_admin: false +deployment: + role: data_plane + role_data_plane: + config_provider: yaml +_EOC_ + + $block->set_value("yaml_config", $yaml_config); +}); +run_tests; +__DATA__ +=== TEST 1: test_pojo +--- apisix_yaml +upstreams: + - nodes: + - host: 127.0.0.1 + port: 30880 + weight: 1 + type: roundrobin + id: 1 +routes: + - + uri: /t + plugins: + http-dubbo: + service_name: org.apache.dubbo.backend.DubboSerializationTestService + params_type_desc: Lorg/apache/dubbo/backend/DubboSerializationTestService$AllDataTypesPOJO; + serialized: true + method: testPoJo + upstream_id: 1 +#END + +--- request +POST /t +{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]} +--- response_body +{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]} + +=== TEST 2: test_pojos +--- apisix_yaml +upstreams: + - nodes: + - host: 127.0.0.1 + port: 30880 + weight: 1 + type: roundrobin + id: 1 +routes: + - + uri: /t + plugins: + http-dubbo: + service_name: org.apache.dubbo.backend.DubboSerializationTestService + params_type_desc: [Lorg/apache/dubbo/backend/DubboSerializationTestService$AllDataTypesPOJO; + serialized: true + method: testPoJos + upstream_id: 1 +#END +--- request +POST /t +{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]} +--- response_body +[{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]}] From e694b7af943f25f0b16045a7e26cafcd9b0b7f55 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 10 Jan 2024 14:58:25 +0800 Subject: [PATCH 05/31] add License --- t/plugin/http-dubbo.t | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index 98c00daf069b..33c56837963c 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -1,3 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# use t::APISIX 'no_plan'; repeat_each(1); From 3d41ca54a9a71ff218060f77ca05cd75ad1df67e Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 10 Jan 2024 16:24:36 +0800 Subject: [PATCH 06/31] polish --- .gitignore | 5 +++-- apisix/plugins/http-dubbo.lua | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 49dbbfe5759e..94669c34502a 100644 --- a/.gitignore +++ b/.gitignore @@ -59,8 +59,7 @@ client_body_temp utils/lj-releng utils/reindex *.etcd/ -t/lib/dubbo-backend/dubbo-backend-interface/target/ -t/lib/dubbo-backend/dubbo-backend-provider/target/ +t/lib/dubbo*/**/target/ .idea/ *.iml \.* @@ -88,3 +87,5 @@ pack-v*-linux.tgz* # release tar package *.tgz release/* + + diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index 2335d7c5a124..b6cb9e078eac 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -218,7 +218,7 @@ end function _M.before_proxy(conf, ctx) local sock = ngx.socket.tcp() - sock:settimeouts(conf.connect_timeout, conf.send_timeout, conf.read_timeout) -- one second timeout + sock:settimeouts(conf.connect_timeout, conf.send_timeout, conf.read_timeout) local ok, err = sock:connect(ctx.picked_server.host, ctx.picked_server.port) if not ok then sock:close() From 31ae7270561e89af893bcddf31137772c4d3e6ce Mon Sep 17 00:00:00 2001 From: shenfeng Date: Thu, 11 Jan 2024 11:42:24 +0800 Subject: [PATCH 07/31] fix ci --- .github/workflows/build.yml | 5 +++++ .github/workflows/centos7-ci.yml | 6 ++++++ .github/workflows/redhat-ci.yaml | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2c1bbcc9cd71..7fac4a54bf3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -141,11 +141,16 @@ jobs: - name: Start Dubbo Backend if: matrix.os_name == 'linux_openresty' && (steps.test_env.outputs.type == 'plugin' || steps.test_env.outputs.type == 'last') run: | + cur_dir=$(pwd) sudo apt install -y maven cd t/lib/dubbo-backend mvn package cd dubbo-backend-provider/target java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log & + cd $cur_dir/t/lib/dubbo-serialization-backend + mvn package + cd dubbo-serialization-backend-provider + java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java2.log & - name: Build xDS library if: steps.test_env.outputs.type == 'last' diff --git a/.github/workflows/centos7-ci.yml b/.github/workflows/centos7-ci.yml index 9f98a363f5f3..3746a8beda7d 100644 --- a/.github/workflows/centos7-ci.yml +++ b/.github/workflows/centos7-ci.yml @@ -99,11 +99,17 @@ jobs: - name: Start Dubbo Backend run: | + cur_dir=$(pwd) sudo apt install -y maven cd t/lib/dubbo-backend mvn package cd dubbo-backend-provider/target java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log & + cd $cur_dir/t/lib/dubbo-serialization-backend + mvn package + cd dubbo-serialization-backend-provider + java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java2.log & + - name: Build xDS library if: steps.test_env.outputs.type == 'last' diff --git a/.github/workflows/redhat-ci.yaml b/.github/workflows/redhat-ci.yaml index 547bfb1f14dc..4184beba5535 100644 --- a/.github/workflows/redhat-ci.yaml +++ b/.github/workflows/redhat-ci.yaml @@ -95,11 +95,16 @@ jobs: - name: Start Dubbo Backend run: | + cur_dir=$(pwd) sudo apt install -y maven cd t/lib/dubbo-backend mvn package cd dubbo-backend-provider/target java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log & + cd $cur_dir/t/lib/dubbo-serialization-backend + mvn package + cd dubbo-serialization-backend-provider + java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java2.log & - name: Build xDS library if: steps.test_env.outputs.type == 'last' From e8ff79eb1418a32cd5ec41db418ccf71ebda62bc Mon Sep 17 00:00:00 2001 From: shenfeng Date: Thu, 11 Jan 2024 11:52:32 +0800 Subject: [PATCH 08/31] fix ci --- .github/workflows/build.yml | 2 +- .github/workflows/centos7-ci.yml | 2 +- .github/workflows/gm-cron.yaml | 2 +- .github/workflows/redhat-ci.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7fac4a54bf3c..d5a7f6e2c417 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -149,7 +149,7 @@ jobs: java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log & cd $cur_dir/t/lib/dubbo-serialization-backend mvn package - cd dubbo-serialization-backend-provider + cd dubbo-serialization-backend-provider/target java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java2.log & - name: Build xDS library diff --git a/.github/workflows/centos7-ci.yml b/.github/workflows/centos7-ci.yml index 3746a8beda7d..17d8f7dd0a81 100644 --- a/.github/workflows/centos7-ci.yml +++ b/.github/workflows/centos7-ci.yml @@ -107,7 +107,7 @@ jobs: java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log & cd $cur_dir/t/lib/dubbo-serialization-backend mvn package - cd dubbo-serialization-backend-provider + cd dubbo-serialization-backend-provider/target java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java2.log & diff --git a/.github/workflows/gm-cron.yaml b/.github/workflows/gm-cron.yaml index 61a3594234d8..b00de03e9c78 100644 --- a/.github/workflows/gm-cron.yaml +++ b/.github/workflows/gm-cron.yaml @@ -132,7 +132,7 @@ jobs: java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log & cd $cur_dir/t/lib/dubbo-serialization-backend mvn package - cd dubbo-serialization-backend-provider + cd dubbo-serialization-backend-provider/target java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java2.log & - name: Build xDS library diff --git a/.github/workflows/redhat-ci.yaml b/.github/workflows/redhat-ci.yaml index 4184beba5535..960187c9a625 100644 --- a/.github/workflows/redhat-ci.yaml +++ b/.github/workflows/redhat-ci.yaml @@ -103,7 +103,7 @@ jobs: java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log & cd $cur_dir/t/lib/dubbo-serialization-backend mvn package - cd dubbo-serialization-backend-provider + cd dubbo-serialization-backend-provider/target java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java2.log & - name: Build xDS library From 443495af867a7dbd422943d0ce01656634fbb921 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Mon, 15 Jan 2024 10:12:46 +0800 Subject: [PATCH 09/31] fix ci --- .../DubboSerializationTestService.java | 79 +------------------ .../java/org/apache/dubbo/backend/PoJo.java | 17 ++-- .../DubboSerializationTestServiceImpl.java | 10 +-- .../dubbo/backend/provider/Provider.java | 3 - t/plugin/http-dubbo.t | 10 +-- 5 files changed, 16 insertions(+), 103 deletions(-) diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java index 5c973281eaf1..16f6cb7c88a5 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java @@ -16,94 +16,19 @@ */ package org.apache.dubbo.backend; -import java.util.List; -import java.util.Map; - public interface DubboSerializationTestService { + PoJo testPoJo(PoJo input); + PoJo[] testPoJos(PoJo[] input); - - AllDataTypesPOJO testPoJo(AllDataTypesPOJO input); - - AllDataTypesPOJO[] testPoJos(AllDataTypesPOJO[] input); - - - - // 方法测试 void 返回类型 void testVoid(); - // 方法测试失败 void testFailure(); - // 方法测试超时 void testTimeout(); // 测试POJO包括所有数据类型 - class AllDataTypesPOJO { - private int intValue; - private long longValue; - private float floatValue; - private double doubleValue; - private char charValue; - private boolean booleanValue; - private byte byteValue; - - public int getIntValue() { - return intValue; - } - - public void setIntValue(int intValue) { - this.intValue = intValue; - } - - public long getLongValue() { - return longValue; - } - - public void setLongValue(long longValue) { - this.longValue = longValue; - } - - public float getFloatValue() { - return floatValue; - } - - public void setFloatValue(float floatValue) { - this.floatValue = floatValue; - } - - public double getDoubleValue() { - return doubleValue; - } - - public void setDoubleValue(double doubleValue) { - this.doubleValue = doubleValue; - } - - public char getCharValue() { - return charValue; - } - - public void setCharValue(char charValue) { - this.charValue = charValue; - } - - public boolean isBooleanValue() { - return booleanValue; - } - - public void setBooleanValue(boolean booleanValue) { - this.booleanValue = booleanValue; - } - - public byte getByteValue() { - return byteValue; - } - public void setByteValue(byte byteValue) { - this.byteValue = byteValue; - } - } } diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java index 780e8f14ae84..df69ba38a6ac 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java @@ -18,7 +18,7 @@ public class PoJo { private String[] strings; - private Map poJoMap; + private Map stringMap; public String getaString() { return aString; @@ -94,12 +94,12 @@ public void setaShort(Short aShort) { - public Map getPoJoMap() { - return poJoMap; + public Map getStringMap() { + return stringMap; } - public void setPoJoMap(Map poJoMap) { - this.poJoMap = poJoMap; + public void setStringMap(Map stringMap) { + this.stringMap = stringMap; } public String[] getStrings() { @@ -123,13 +123,8 @@ public static PoJo getTestInstance(){ poJo.aString ="aa"; HashMap poJoMap = new HashMap<>(); poJoMap.put("key","value"); - poJo.poJoMap = poJoMap; + poJo.stringMap = poJoMap; poJo.strings = new String[]{"aa","bb"}; return poJo; } - - public static void main(String[] args) { - - } - } diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java index 5e0bfb81eda6..872ac4a81d1f 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java @@ -17,28 +17,24 @@ package org.apache.dubbo.backend.provider; import org.apache.dubbo.backend.DubboSerializationTestService; +import org.apache.dubbo.backend.PoJo; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.TimeUnit; -import java.lang.InterruptedException; public class DubboSerializationTestServiceImpl implements DubboSerializationTestService { @Override - public AllDataTypesPOJO testPoJo(AllDataTypesPOJO input) { + public PoJo testPoJo(PoJo input) { return input; } @Override - public AllDataTypesPOJO[] testPoJos(AllDataTypesPOJO[] input) { + public PoJo[] testPoJos(PoJo[] input) { return input; } @Override public void testVoid() { - - } @Override diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java index c70f171732a3..031cf3a22737 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java @@ -35,9 +35,6 @@ public class Provider { */ public static void main(String[] args) throws Exception { - JSONObject.toJSONString(PoJo.getTestInstance()); - Method[] declaredMethods = DubboSerializationTestService.class.getDeclaredMethods(); - ReflectUtils.getDesc(declaredMethods[1].getParameterTypes()); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-provider.xml"}); context.start(); diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index 33c56837963c..cb5cd67d8f28 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -53,7 +53,7 @@ routes: plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService - params_type_desc: Lorg/apache/dubbo/backend/DubboSerializationTestService$AllDataTypesPOJO; + params_type_desc: Lorg/apache/dubbo/backend/PoJo; serialized: true method: testPoJo upstream_id: 1 @@ -61,9 +61,9 @@ routes: --- request POST /t -{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]} +{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]} --- response_body -{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]} +{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]} === TEST 2: test_pojos --- apisix_yaml @@ -80,13 +80,13 @@ routes: plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService - params_type_desc: [Lorg/apache/dubbo/backend/DubboSerializationTestService$AllDataTypesPOJO; + params_type_desc: [org/apache/dubbo/backend/PoJo; serialized: true method: testPoJos upstream_id: 1 #END --- request POST /t -{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]} +[{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]}] --- response_body [{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]}] From 34fdc5d4c1c4bcedf31aaf7de16d4e2f050c9116 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Mon, 15 Jan 2024 10:17:54 +0800 Subject: [PATCH 10/31] add License --- .../main/java/org/apache/dubbo/backend/PoJo.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java index df69ba38a6ac..16122faabe05 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.dubbo.backend; import java.util.HashMap; From 4aa4d031df86dcb1785341327e1df5ed061983ed Mon Sep 17 00:00:00 2001 From: ShenFeng312 <49786112+ShenFeng312@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:28:15 +0800 Subject: [PATCH 11/31] Update t/plugin/http-dubbo.t Co-authored-by: Liu Wei <375636559@qq.com> --- t/plugin/http-dubbo.t | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index cb5cd67d8f28..decf2f994073 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -36,8 +36,11 @@ _EOC_ $block->set_value("yaml_config", $yaml_config); }); + run_tests; + __DATA__ + === TEST 1: test_pojo --- apisix_yaml upstreams: From 37d8163688be564e30fc8f7663f279c1b527c3dc Mon Sep 17 00:00:00 2001 From: shenfeng Date: Fri, 19 Jan 2024 10:57:13 +0800 Subject: [PATCH 12/31] fix cr --- .../dubbo/backend/DubboSerializationTestService.java | 4 ---- t/plugin/http-dubbo.t | 10 ++++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java index 16f6cb7c88a5..fcc2a7143a13 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/DubboSerializationTestService.java @@ -27,8 +27,4 @@ public interface DubboSerializationTestService { void testFailure(); void testTimeout(); - - // 测试POJO包括所有数据类型 - - } diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index cb5cd67d8f28..6c1d10864171 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -22,8 +22,6 @@ no_shuffle(); no_root_location(); add_block_preprocessor(sub { my ($block) = @_; - - my $yaml_config = $block->yaml_config // <<_EOC_; apisix: node_listen: 1984 @@ -36,8 +34,11 @@ _EOC_ $block->set_value("yaml_config", $yaml_config); }); + run_tests; + __DATA__ + === TEST 1: test_pojo --- apisix_yaml upstreams: @@ -58,13 +59,14 @@ routes: method: testPoJo upstream_id: 1 #END - --- request POST /t {"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]} --- response_body {"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]} + + === TEST 2: test_pojos --- apisix_yaml upstreams: @@ -80,7 +82,7 @@ routes: plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService - params_type_desc: [org/apache/dubbo/backend/PoJo; + params_type_desc: "[org/apache/dubbo/backend/PoJo;" serialized: true method: testPoJos upstream_id: 1 From abd9593aa65d61605bb3fc6faaae474f97a86c9a Mon Sep 17 00:00:00 2001 From: shenfeng Date: Fri, 19 Jan 2024 11:11:06 +0800 Subject: [PATCH 13/31] fix cr --- apisix/plugins/http-dubbo.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index b6cb9e078eac..632270a9b33f 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -81,6 +81,7 @@ function _M.check_schema(conf) return core.schema.check(schema, conf) end + local function str_int32(int) return char(band(rshift(int, 24), 0xff), band(rshift(int, 16), 0xff), @@ -88,6 +89,7 @@ local function str_int32(int) band(int, 0xff)) end + local function parse_dubbo_header(header) for i = 1, 16 do local currentByte = header:byte(i) @@ -124,6 +126,7 @@ local function parse_dubbo_header(header) } end + local function string_to_json_string(str) local result = "\"" for i = 1, #str do @@ -149,6 +152,7 @@ local function string_to_json_string(str) return result .. "\"" end + local function get_dubbo_request(conf, ctx) -- use dubbo and fastjson local first_byte4 = "\xda\xbb\xc6\x00" @@ -215,6 +219,7 @@ local function get_dubbo_request(conf, ctx) } end + function _M.before_proxy(conf, ctx) local sock = ngx.socket.tcp() From 92596b07483e0cc9dbd090b31e67a87bcf6daa53 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Fri, 19 Jan 2024 11:12:20 +0800 Subject: [PATCH 14/31] fix cr --- .../src/main/java/org/apache/dubbo/backend/PoJo.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java index 16122faabe05..150d035a1f6e 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-interface/src/main/java/org/apache/dubbo/backend/PoJo.java @@ -21,19 +21,15 @@ public class PoJo { private String aString; - private Boolean aBoolean; private Byte aByte; private Character acharacter; private Integer aInt; - private Float aFloat; private Double aDouble; private Long aLong; private Short aShort; - private String[] strings; - private Map stringMap; public String getaString() { @@ -108,8 +104,6 @@ public void setaShort(Short aShort) { this.aShort = aShort; } - - public Map getStringMap() { return stringMap; } From 8451fd8cc47e63eb116c82becb26d053cdd734f6 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Fri, 19 Jan 2024 16:17:50 +0800 Subject: [PATCH 15/31] add service_version --- t/plugin/http-dubbo.t | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index 6c1d10864171..bc96d668beb7 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -57,6 +57,7 @@ routes: params_type_desc: Lorg/apache/dubbo/backend/PoJo; serialized: true method: testPoJo + service_version: 1.0.0 upstream_id: 1 #END --- request @@ -85,6 +86,7 @@ routes: params_type_desc: "[org/apache/dubbo/backend/PoJo;" serialized: true method: testPoJos + service_version: 1.0.0 upstream_id: 1 #END --- request From 6599c31098130310c0e2c5b8f8d04fbabaa2dd2f Mon Sep 17 00:00:00 2001 From: shenfeng Date: Tue, 23 Jan 2024 11:02:58 +0800 Subject: [PATCH 16/31] fix test --- apisix/plugins/http-dubbo.lua | 2 +- .../main/java/org/apache/dubbo/backend/provider/Provider.java | 3 ++- t/plugin/http-dubbo.t | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index 632270a9b33f..8194bd2c190f 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -175,7 +175,7 @@ local function get_dubbo_request(conf, ctx) params = core.request.get_body() if params then local end_of_params = core.string.sub(params, -1) - if not (end_of_params == "\n") then + if end_of_params ~= "\n" then params = params .. "\n" end else diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java index 031cf3a22737..dde4580d570a 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/Provider.java @@ -36,7 +36,8 @@ public class Provider { public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-provider.xml"}); - + String jsonString = JSONObject.toJSONString(PoJo.getTestInstance()); + System.out.println(jsonString); context.start(); while (true) { try { diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index bc96d668beb7..f33533c0188e 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -93,4 +93,4 @@ routes: POST /t [{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]}] --- response_body -[{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","poJoMap":{"key":"value"},"strings":["aa","bb"]}] +[{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]}] From 132777a514b5360bb067a65c983a0be5b92f54ee Mon Sep 17 00:00:00 2001 From: shenfeng Date: Tue, 23 Jan 2024 11:54:34 +0800 Subject: [PATCH 17/31] fix test --- t/plugin/http-dubbo.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index f33533c0188e..9b5739483f1e 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -83,7 +83,7 @@ routes: plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService - params_type_desc: "[org/apache/dubbo/backend/PoJo;" + params_type_desc: "[Lorg/apache/dubbo/backend/PoJo;" serialized: true method: testPoJos service_version: 1.0.0 From 81e9f00ecd1887df0d63d4ee11553457e8700a88 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Tue, 23 Jan 2024 11:57:00 +0800 Subject: [PATCH 18/31] fix test --- t/plugin/http-dubbo.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index 9b5739483f1e..e90e2f98752e 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -63,7 +63,7 @@ routes: --- request POST /t {"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]} ---- response_body +--- response_body chomp {"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]} @@ -92,5 +92,5 @@ routes: --- request POST /t [{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]}] ---- response_body +--- response_body chomp [{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]}] From 5f1664ccb7124dfce347c3178eefcb2adbc84ba5 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 11:33:40 +0800 Subject: [PATCH 19/31] add test --- apisix/plugins/http-dubbo.lua | 8 +- .../DubboSerializationTestServiceImpl.java | 5 +- t/plugin/http-dubbo.t | 132 ++++++++++++++++++ 3 files changed, 138 insertions(+), 7 deletions(-) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index 8194bd2c190f..5320b6b3f80c 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -45,7 +45,7 @@ local schema = { }, params_type_desc = { type = "string", - minLength = 1, + default = "" }, serialization_header_key = { type = "string" @@ -67,7 +67,7 @@ local schema = { default = 6000 } }, - required = { "service_name", "method", "params_type_desc" }, + required = { "service_name", "method" }, } local _M = { @@ -178,8 +178,6 @@ local function get_dubbo_request(conf, ctx) if end_of_params ~= "\n" then params = params .. "\n" end - else - params = params .. "\n" end else local body_data = core.request.get_body() @@ -197,8 +195,6 @@ local function get_dubbo_request(conf, ctx) params = params .. core.json.encode(v) .. "\n" end end - else - params = params .. "\n" end end diff --git a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java index 872ac4a81d1f..41e927391a36 100644 --- a/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java +++ b/t/lib/dubbo-serialization-backend/dubbo-serialization-backend-provider/src/main/java/org/apache/dubbo/backend/provider/DubboSerializationTestServiceImpl.java @@ -18,7 +18,10 @@ import org.apache.dubbo.backend.DubboSerializationTestService; import org.apache.dubbo.backend.PoJo; +import org.apache.dubbo.common.utils.ReflectUtils; +import java.lang.reflect.Method; +import java.util.Arrays; import java.util.concurrent.TimeUnit; public class DubboSerializationTestServiceImpl implements DubboSerializationTestService { @@ -45,7 +48,7 @@ public void testFailure() { @Override public void testTimeout() { try { - TimeUnit.MINUTES.sleep(1); + TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { throw new RuntimeException(e); } diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index e90e2f98752e..ba35c7188fb5 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -94,3 +94,135 @@ POST /t [{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]}] --- response_body chomp [{"aBoolean":true,"aByte":1,"aDouble":1.1,"aFloat":1.2,"aInt":2,"aLong":3,"aShort":4,"aString":"aa","acharacter":"a","stringMap":{"key":"value"},"strings":["aa","bb"]}] + + + +=== TEST 2: test_timeout +--- apisix_yaml +upstreams: + - nodes: + - host: 127.0.0.1 + port: 30881 + weight: 1 + type: roundrobin + id: 1 +routes: + - + uri: /t + plugins: + http-dubbo: + service_name: org.apache.dubbo.backend.DubboSerializationTestService + params_type_desc: "[Lorg/apache/dubbo/backend/PoJo;" + serialized: true + method: testPoJos + service_version: 1.0.0 + connect_timeout:100 + read_timeout: 100 + send_timeout: 100 + upstream_id: 1 +#END +--- config + location /t { + content_by_lua_block { + + local code, body = t('/t', + ngx.HTTP_GET + ) + if code == 502 then + ngx.say("passed") + else + ngx.say("fail") + end + + } + } +--- request +GET /t +--- response_body +passed + + + +=== TEST 2: test_void +--- apisix_yaml +upstreams: + - nodes: + - host: 127.0.0.1 + port: 30880 + weight: 1 + type: roundrobin + id: 1 +routes: + - + uri: /t + plugins: + http-dubbo: + service_name: org.apache.dubbo.backend.DubboSerializationTestService + params_type_desc: + serialized: true + method: testVoid + service_version: 1.0.0 + upstream_id: 1 +#END +--- config + location /t { + content_by_lua_block { + + local code, body = t('/t', + ngx.HTTP_GET + ) + if code == 200 then + ngx.say("passed") + else + ngx.say("fail") + end + + } + } +--- request +GET /t +--- response_body +passed + + + +=== TEST 2: test_fail +--- apisix_yaml +upstreams: + - nodes: + - host: 127.0.0.1 + port: 30880 + weight: 1 + type: roundrobin + id: 1 +routes: + - + uri: /t + plugins: + http-dubbo: + service_name: org.apache.dubbo.backend.DubboSerializationTestService + params_type_desc: + serialized: true + method: testFailure + service_version: 1.0.0 + upstream_id: 1 +#END +--- config + location /t { + content_by_lua_block { + + local code, body = t('/t', + ngx.HTTP_GET + ) + if code == 500 then + ngx.say("passed") + else + ngx.say("fail") + end + + } + } +--- request +GET /t +--- response_body +passed From 982380eb626b394c0c782ca0c6d0ac005ac0956b Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 11:43:00 +0800 Subject: [PATCH 20/31] fix test --- t/plugin/http-dubbo.t | 2 -- 1 file changed, 2 deletions(-) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index ba35c7188fb5..e2bcc524ff5a 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -158,7 +158,6 @@ routes: plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService - params_type_desc: serialized: true method: testVoid service_version: 1.0.0 @@ -201,7 +200,6 @@ routes: plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService - params_type_desc: serialized: true method: testFailure service_version: 1.0.0 From 5d68990a2b9fa4fa4c73781d7b3021ba7f372c9e Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 15:29:28 +0800 Subject: [PATCH 21/31] fix ci --- t/plugin/http-dubbo.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index e2bcc524ff5a..0993398a4bca 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -116,7 +116,7 @@ routes: serialized: true method: testPoJos service_version: 1.0.0 - connect_timeout:100 + connect_timeout: 100 read_timeout: 100 send_timeout: 100 upstream_id: 1 From 33a47ee0803aebc85099ff563a56110e6b88befa Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 16:08:09 +0800 Subject: [PATCH 22/31] fix ci --- t/admin/plugins.t | 1 + 1 file changed, 1 insertion(+) diff --git a/t/admin/plugins.t b/t/admin/plugins.t index c174d5f29b52..911205f48cb4 100644 --- a/t/admin/plugins.t +++ b/t/admin/plugins.t @@ -109,6 +109,7 @@ degraphql kafka-proxy grpc-transcode grpc-web +http-dubbo public-api prometheus datadog From 56a159f5115b3f1653229f19b53db0a9a1142ecc Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 16:36:13 +0800 Subject: [PATCH 23/31] fix ci --- t/plugin/http-dubbo.t | 70 +++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index 0993398a4bca..e9c82389a839 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -108,7 +108,7 @@ upstreams: id: 1 routes: - - uri: /t + uri: /testTimeout plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService @@ -124,16 +124,18 @@ routes: --- config location /t { content_by_lua_block { - - local code, body = t('/t', - ngx.HTTP_GET - ) - if code == 502 then - ngx.say("passed") - else - ngx.say("fail") - end - + local http = require "resty.http" + local httpc = http.new() + local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/testTimeout" + local res, err = httpc:request_uri(uri, {method = "GET"}) + if not res then + ngx.say(err) + elseif res.status == 200 then + ngx.say("passed") + return + else + ngx.say("fail") + end } } --- request @@ -154,7 +156,7 @@ upstreams: id: 1 routes: - - uri: /t + uri: /testVoid plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService @@ -166,16 +168,18 @@ routes: --- config location /t { content_by_lua_block { - - local code, body = t('/t', - ngx.HTTP_GET - ) - if code == 200 then - ngx.say("passed") - else - ngx.say("fail") - end - + local http = require "resty.http" + local httpc = http.new() + local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/testVoid" + local res, err = httpc:request_uri(uri, {method = "GET"}) + if not res then + ngx.say(err) + elseif res.status == 200 then + ngx.say("passed") + return + else + ngx.say("fail") + end } } --- request @@ -208,16 +212,18 @@ routes: --- config location /t { content_by_lua_block { - - local code, body = t('/t', - ngx.HTTP_GET - ) - if code == 500 then - ngx.say("passed") - else - ngx.say("fail") - end - + local http = require "resty.http" + local httpc = http.new() + local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/test_fail" + local res, err = httpc:request_uri(uri, {method = "GET"}) + if not res then + ngx.say(err) + elseif res.status == 500 then + ngx.say("passed") + return + else + ngx.say("fail") + end } } --- request From ef24da963dd8a41ed0403ba13094dda60db1cc58 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 18:16:25 +0800 Subject: [PATCH 24/31] fix test --- t/plugin/http-dubbo.t | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index e9c82389a839..9e03c7fca0c4 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -97,7 +97,7 @@ POST /t -=== TEST 2: test_timeout +=== TEST 3: test_timeout --- apisix_yaml upstreams: - nodes: @@ -145,7 +145,7 @@ passed -=== TEST 2: test_void +=== TEST 4: test_void --- apisix_yaml upstreams: - nodes: @@ -189,7 +189,7 @@ passed -=== TEST 2: test_fail +=== TEST 5: test_fail --- apisix_yaml upstreams: - nodes: From 9ba34582649fcd54b758e60a4fb7e64307d5428e Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 18:28:56 +0800 Subject: [PATCH 25/31] fix test --- t/plugin/http-dubbo.t | 61 +++---------------------------------------- 1 file changed, 3 insertions(+), 58 deletions(-) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index 9e03c7fca0c4..3461b3bb2b3e 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -121,27 +121,9 @@ routes: send_timeout: 100 upstream_id: 1 #END ---- config - location /t { - content_by_lua_block { - local http = require "resty.http" - local httpc = http.new() - local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/testTimeout" - local res, err = httpc:request_uri(uri, {method = "GET"}) - if not res then - ngx.say(err) - elseif res.status == 200 then - ngx.say("passed") - return - else - ngx.say("fail") - end - } - } --- request GET /t ---- response_body -passed +--- error_code: 502 @@ -156,7 +138,7 @@ upstreams: id: 1 routes: - - uri: /testVoid + uri: /t plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService @@ -165,27 +147,8 @@ routes: service_version: 1.0.0 upstream_id: 1 #END ---- config - location /t { - content_by_lua_block { - local http = require "resty.http" - local httpc = http.new() - local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/testVoid" - local res, err = httpc:request_uri(uri, {method = "GET"}) - if not res then - ngx.say(err) - elseif res.status == 200 then - ngx.say("passed") - return - else - ngx.say("fail") - end - } - } --- request GET /t ---- response_body -passed @@ -209,24 +172,6 @@ routes: service_version: 1.0.0 upstream_id: 1 #END ---- config - location /t { - content_by_lua_block { - local http = require "resty.http" - local httpc = http.new() - local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/test_fail" - local res, err = httpc:request_uri(uri, {method = "GET"}) - if not res then - ngx.say(err) - elseif res.status == 500 then - ngx.say("passed") - return - else - ngx.say("fail") - end - } - } --- request GET /t ---- response_body -passed +--- error_code: 500 From 3707b29fba8b70cc9b1cbdf9b381591c899beb48 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 18:37:41 +0800 Subject: [PATCH 26/31] fix ci --- t/plugin/http-dubbo.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index 3461b3bb2b3e..c01c5a12fd83 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -108,7 +108,7 @@ upstreams: id: 1 routes: - - uri: /testTimeout + uri: /t plugins: http-dubbo: service_name: org.apache.dubbo.backend.DubboSerializationTestService From b948642648aef1d3c1c13b7d0325ea0cdf327331 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 19:02:10 +0800 Subject: [PATCH 27/31] fix ci --- t/plugin/http-dubbo.t | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/plugin/http-dubbo.t b/t/plugin/http-dubbo.t index c01c5a12fd83..8006f07ab824 100644 --- a/t/plugin/http-dubbo.t +++ b/t/plugin/http-dubbo.t @@ -124,6 +124,8 @@ routes: --- request GET /t --- error_code: 502 +--- error_log +failed to connect to upstream From a8027ef02fcb95e3234d7346134579df05fb7747 Mon Sep 17 00:00:00 2001 From: shenfeng Date: Wed, 24 Jan 2024 19:36:15 +0800 Subject: [PATCH 28/31] fix http-dubbo params len --- apisix/plugins/http-dubbo.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index 5320b6b3f80c..778f4714270d 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -199,8 +199,11 @@ local function get_dubbo_request(conf, ctx) end local attachments = "{}\n" - - local payload = #version + #service + #service_version + #method_name + #params_desc + #params + #attachments + local params_len = 0 + if params then + params_len = #params + end + local payload = #version + #service + #service_version + #method_name + #params_desc + params_len + #attachments return { first_byte4, requestId, From 43f42691117acd7d098469d6f5be194e8ed74677 Mon Sep 17 00:00:00 2001 From: ShenFeng312 <49786112+ShenFeng312@users.noreply.github.com> Date: Wed, 24 Jan 2024 20:27:20 +0800 Subject: [PATCH 29/31] fix http-dubbo params --- apisix/plugins/http-dubbo.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index 778f4714270d..da5ad52e684d 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -199,11 +199,10 @@ local function get_dubbo_request(conf, ctx) end local attachments = "{}\n" - local params_len = 0 - if params then - params_len = #params + if params == nil then + params = "" end - local payload = #version + #service + #service_version + #method_name + #params_desc + params_len + #attachments + local payload = #version + #service + #service_version + #method_name + #params_desc + #params + #attachments return { first_byte4, requestId, From 7084aa33e62355ed14e3d62d9cf0f091d91ea08a Mon Sep 17 00:00:00 2001 From: shenfeng Date: Fri, 26 Jan 2024 09:18:45 +0800 Subject: [PATCH 30/31] fix codestyle --- apisix/plugins/http-dubbo.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index da5ad52e684d..5a1075340c25 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -183,7 +183,7 @@ local function get_dubbo_request(conf, ctx) local body_data = core.request.get_body() if body_data then local lua_object = core.json.decode(body_data); - for k, v in pairs(lua_object) do + for _, v in pairs(lua_object) do local pt = type(v) if pt == "nil" then params = params .. "null" .. "\n" @@ -202,7 +202,8 @@ local function get_dubbo_request(conf, ctx) if params == nil then params = "" end - local payload = #version + #service + #service_version + #method_name + #params_desc + #params + #attachments + local payload = #version + #service + #service_version + + #method_name + #params_desc + #params + #attachments return { first_byte4, requestId, @@ -229,21 +230,21 @@ function _M.before_proxy(conf, ctx) return 502 end local request = get_dubbo_request(conf, ctx) - local bytes, err = sock:send(request) + local bytes, _ = sock:send(request) if bytes > 0 then - local header, err = sock:receiveany(16); + local header, _ = sock:receiveany(16); if header then local header_info = parse_dubbo_header(header) if header_info and header_info.status == 20 then local readline = sock:receiveuntil("\n") - local body_status, err, partial = readline() + local body_status, _, _ = readline() if body_status then local response_status = core.string.sub(body_status, 1, 1) if response_status == "2" or response_status == "5" then sock:close() return 200 elseif response_status == "1" or response_status == "4" then - local body, err, partial = readline() + local body, _, _ = readline() sock:close() return 200, body end From 45f319a0c49b256edff8bedba5b6dfc0195b838c Mon Sep 17 00:00:00 2001 From: shenfeng Date: Thu, 1 Feb 2024 10:20:19 +0800 Subject: [PATCH 31/31] fix codestyle --- apisix/plugins/http-dubbo.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apisix/plugins/http-dubbo.lua b/apisix/plugins/http-dubbo.lua index 5a1075340c25..f068654babc4 100644 --- a/apisix/plugins/http-dubbo.lua +++ b/apisix/plugins/http-dubbo.lua @@ -19,6 +19,7 @@ local require = require local core = require("apisix.core") local pairs = pairs local str_format = string.format +local bit = require("bit") local rshift = bit.rshift local band = bit.band local char = string.char @@ -27,6 +28,7 @@ local ngx = ngx local type = type local plugin_name = "http-dubbo" + local schema = { type = "object", properties = {