From bc36758cc24ad3a282cac5862e787dd82bb3fae2 Mon Sep 17 00:00:00 2001 From: pantianying Date: Fri, 14 Aug 2020 17:30:39 +0800 Subject: [PATCH 1/4] add code --- dubbo/call.go | 5 ++++ dubbo/java.go | 41 +++++++++++++++++++++++++++++++++ go.mod | 6 ++--- go.sum | 14 +++++++++++ service/context/http_context.go | 1 + 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 dubbo/java.go diff --git a/dubbo/call.go b/dubbo/call.go index 98025f441..2500c65e5 100644 --- a/dubbo/call.go +++ b/dubbo/call.go @@ -22,6 +22,11 @@ type InvokeData struct { func (d *GenericClientPool) Call(inData InvokeData) (resp interface{}, ret int) { var err error + inData.ReqData, err = AdapterForJava(inData.ParameterTypes, inData.ReqData) + if err != nil { + ret = errcode.ServerBusy + return + } c := d.Get(inData.InterfaceName, inData.Version, inData.Group) ctx := context.Background() resp, err = c.Invoke(ctx, []interface{}{inData.Method, inData.ParameterTypes, inData.ReqData}) diff --git a/dubbo/java.go b/dubbo/java.go new file mode 100644 index 000000000..2d7a970f3 --- /dev/null +++ b/dubbo/java.go @@ -0,0 +1,41 @@ +package dubbo + +import ( + "errors" + "github.com/dubbogo/dubbo-go-proxy/common/logger" +) + +const ( + JavaStringClassName = "java.lang.String" + JavaLangClassName = "java.lang.Long" + JavalangIntegerClassName = "java.lang.Integer" + JavaStringListClassName = "[Ljava.lang.String;" + JavaIntegerListClassName = "[Ljava.lang.Integer;" + JavaMapClassName = "java.util.Map" +) + +func AdapterForJava(ParameterTypes []string, inData []interface{}) ([]interface{}, error) { + var ( + outData = make([]interface{}, len(ParameterTypes)) + err error + ) + defer func() { + if r := recover(); r != nil { + logger.Error(r) + err = errors.New("adapterForJava get err") + return + } + }() + + for i := range ParameterTypes { + switch ParameterTypes[i] { + case JavaStringClassName: + outData[i] = inData[i].(string) + case JavaLangClassName: + outData[i] = inData[i].(int) + default: + outData[i] = inData[i] + } + } + return outData, err +} diff --git a/go.mod b/go.mod index 03e354ebe..564f38093 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,11 @@ go 1.12 require ( github.com/apache/dubbo-go v1.4.0-rc1 github.com/apache/dubbo-go-hessian2 v1.4.0 - github.com/dubbogo/getty v1.3.3 + github.com/dubbogo/getty v1.3.9 github.com/go-redis/redis v6.15.6+incompatible github.com/json-iterator/go v1.1.9 - github.com/pkg/errors v0.8.1 + github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.5.1 - go.uber.org/zap v1.13.0 + go.uber.org/zap v1.15.0 gopkg.in/yaml.v2 v2.2.7 ) diff --git a/go.sum b/go.sum index 2f94a6237..7fb7094ba 100644 --- a/go.sum +++ b/go.sum @@ -70,11 +70,15 @@ github.com/docker/go-connections v0.3.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dubbogo/getty v1.3.3 h1:8m4zZBqFHO+NmhH7rMPlFuuYRVjcPD7cUhumevqMZZs= github.com/dubbogo/getty v1.3.3/go.mod h1:U92BDyJ6sW9Jpohr2Vlz8w2uUbIbNZ3d+6rJvFTSPp0= +github.com/dubbogo/getty v1.3.9 h1:Ip/4Yl7GyDzt3ddZhjXN1Vmxvo9y/hdtoJ4yFc7czLk= +github.com/dubbogo/getty v1.3.9/go.mod h1:JIN5lNZznGnBuoYjlEe/yjNmq7eSjKaawHdnBAdtiEo= github.com/dubbogo/go-zookeeper v1.0.0 h1:RsYdlGwhDW+iKXM3eIIcvt34P2swLdmQfuIJxsHlGoM= github.com/dubbogo/go-zookeeper v1.0.0/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= github.com/dubbogo/gost v1.5.1/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= github.com/dubbogo/gost v1.5.2 h1:ri/03971hdpnn3QeCU+4UZgnRNGDXLDGDucR/iozZm8= github.com/dubbogo/gost v1.5.2/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= +github.com/dubbogo/gost v1.9.0 h1:UT+dWwvLyJiDotxJERO75jB3Yxgsdy10KztR5ycxRAk= +github.com/dubbogo/gost v1.9.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74/go.mod h1:UqXY1lYT/ERa4OEAywUqdok1T4RCRdArkhic1Opuavo= github.com/elazarl/go-bindata-assetfs v0.0.0-20160803192304-e1a2a7ec64b0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= @@ -142,6 +146,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= @@ -280,6 +286,8 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -348,14 +356,20 @@ go.etcd.io/etcd v3.3.13+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSF go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM= +go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/service/context/http_context.go b/service/context/http_context.go index 8f872067b..8b38becc7 100644 --- a/service/context/http_context.go +++ b/service/context/http_context.go @@ -86,6 +86,7 @@ func (hc *httpContext) InvokeData() *dubbo.InvokeData { logger.Warn("get paramValues fail") return nil } + invokeData := &dubbo.InvokeData{ InterfaceName: hc.mdKey.ServiceInterface, Group: hc.mdKey.Group, From 27dc62a2a69819e2a59dfa96f3082a939cc43126 Mon Sep 17 00:00:00 2001 From: pantianying Date: Fri, 14 Aug 2020 17:34:36 +0800 Subject: [PATCH 2/4] add code --- dubbo/call.go | 2 +- dubbo/java.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dubbo/call.go b/dubbo/call.go index 2500c65e5..d3e53ca35 100644 --- a/dubbo/call.go +++ b/dubbo/call.go @@ -22,7 +22,7 @@ type InvokeData struct { func (d *GenericClientPool) Call(inData InvokeData) (resp interface{}, ret int) { var err error - inData.ReqData, err = AdapterForJava(inData.ParameterTypes, inData.ReqData) + inData.ReqData, err = adapterForJava(inData.ParameterTypes, inData.ReqData) if err != nil { ret = errcode.ServerBusy return diff --git a/dubbo/java.go b/dubbo/java.go index 2d7a970f3..c9083fd6b 100644 --- a/dubbo/java.go +++ b/dubbo/java.go @@ -5,6 +5,7 @@ import ( "github.com/dubbogo/dubbo-go-proxy/common/logger" ) +// java class name elem const ( JavaStringClassName = "java.lang.String" JavaLangClassName = "java.lang.Long" @@ -14,7 +15,7 @@ const ( JavaMapClassName = "java.util.Map" ) -func AdapterForJava(ParameterTypes []string, inData []interface{}) ([]interface{}, error) { +func adapterForJava(ParameterTypes []string, inData []interface{}) ([]interface{}, error) { var ( outData = make([]interface{}, len(ParameterTypes)) err error From 028715dc4d87427ef0c3aeddac52f2554d7ff92d Mon Sep 17 00:00:00 2001 From: pantianying Date: Tue, 15 Sep 2020 09:46:10 +0800 Subject: [PATCH 3/4] fix review issue --- common/logger/logger.go | 2 +- dubbo/dubbo.go | 10 ++++++---- dubbo/java.go | 3 +++ go.mod | 1 + go.sum | 2 ++ service/context.go | 3 +++ service/context/http_context.go | 9 ++++++--- service/metadata/redis/redis.go | 10 ++++++++-- 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/common/logger/logger.go b/common/logger/logger.go index d7951a3c6..d0d431e46 100644 --- a/common/logger/logger.go +++ b/common/logger/logger.go @@ -1,7 +1,7 @@ package logger import ( - "github.com/dubbogo/getty" + getty "github.com/apache/dubbo-getty" "io/ioutil" "log" "path" diff --git a/dubbo/dubbo.go b/dubbo/dubbo.go index 22d69541c..f7c747aac 100644 --- a/dubbo/dubbo.go +++ b/dubbo/dubbo.go @@ -2,7 +2,7 @@ package dubbo import ( "context" - "github.com/dubbogo/dubbo-go-proxy/common/config" + "strings" "sync" "time" @@ -11,18 +11,20 @@ import ( import ( _ "github.com/apache/dubbo-go/cluster/cluster_impl" _ "github.com/apache/dubbo-go/cluster/loadbalance" + "github.com/apache/dubbo-go/common/constant" _ "github.com/apache/dubbo-go/common/logger" _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" _ "github.com/apache/dubbo-go/config" + dg "github.com/apache/dubbo-go/config" _ "github.com/apache/dubbo-go/filter/filter_impl" + "github.com/apache/dubbo-go/protocol/dubbo" _ "github.com/apache/dubbo-go/protocol/dubbo" _ "github.com/apache/dubbo-go/registry/protocol" _ "github.com/apache/dubbo-go/registry/zookeeper" ) + import ( - "github.com/apache/dubbo-go/common/constant" - dg "github.com/apache/dubbo-go/config" - "github.com/apache/dubbo-go/protocol/dubbo" + "github.com/dubbogo/dubbo-go-proxy/common/config" ) var ( diff --git a/dubbo/java.go b/dubbo/java.go index c9083fd6b..e511c4085 100644 --- a/dubbo/java.go +++ b/dubbo/java.go @@ -2,6 +2,9 @@ package dubbo import ( "errors" +) + +import ( "github.com/dubbogo/dubbo-go-proxy/common/logger" ) diff --git a/go.mod b/go.mod index 564f38093..bfc3353ee 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/dubbogo/dubbo-go-proxy go 1.12 require ( + github.com/apache/dubbo-getty v1.3.10 github.com/apache/dubbo-go v1.4.0-rc1 github.com/apache/dubbo-go-hessian2 v1.4.0 github.com/dubbogo/getty v1.3.9 diff --git a/go.sum b/go.sum index 7fb7094ba..62d3df568 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,8 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190802083043-4cd0c391755e/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ= github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= +github.com/apache/dubbo-getty v1.3.10 h1:ys5mwjPdxG/KwkPjS6EI0RzQtU6p6FCPoKpaFEzpAL0= +github.com/apache/dubbo-getty v1.3.10/go.mod h1:x6rraK01BL5C7jUM2fPl5KMkAxLVIx54ZB8/XEOik9Y= github.com/apache/dubbo-go v1.4.0-rc1 h1:kSUhKKJjB0hokjpOgb/iIiP0RQ849dm6WplHsd0Kb1A= github.com/apache/dubbo-go v1.4.0-rc1/go.mod h1:hzP9PQkcYFcBUgedttDeimugDNqbmGzh18QQy/vBjnw= github.com/apache/dubbo-go-hessian2 v1.4.0 h1:Cb9FQVTy3G93dnDr7P93U8DeKFYpDTJjQp44JG5TafA= diff --git a/service/context.go b/service/context.go index 3351373ef..5f6d8931a 100644 --- a/service/context.go +++ b/service/context.go @@ -2,6 +2,9 @@ package service import ( "context" +) + +import ( "github.com/dubbogo/dubbo-go-proxy/dubbo" ) diff --git a/service/context/http_context.go b/service/context/http_context.go index 8b38becc7..521f37e4f 100644 --- a/service/context/http_context.go +++ b/service/context/http_context.go @@ -1,5 +1,11 @@ package context +import ( + "io/ioutil" + "net/http" + "strings" +) + import ( "github.com/dubbogo/dubbo-go-proxy/common/constant" "github.com/dubbogo/dubbo-go-proxy/common/errcode" @@ -7,9 +13,6 @@ import ( "github.com/dubbogo/dubbo-go-proxy/common/util" "github.com/dubbogo/dubbo-go-proxy/dubbo" "github.com/dubbogo/dubbo-go-proxy/service" - "io/ioutil" - "net/http" - "strings" ) type httpContext struct { diff --git a/service/metadata/redis/redis.go b/service/metadata/redis/redis.go index 17453c335..d35b5f780 100644 --- a/service/metadata/redis/redis.go +++ b/service/metadata/redis/redis.go @@ -1,12 +1,18 @@ package redis +import ( + "time" +) + +import ( + "github.com/go-redis/redis" +) + import ( "github.com/dubbogo/dubbo-go-proxy/common/config" "github.com/dubbogo/dubbo-go-proxy/common/logger" "github.com/dubbogo/dubbo-go-proxy/common/util" "github.com/dubbogo/dubbo-go-proxy/service" - "github.com/go-redis/redis" - "time" ) var rc *redis.Client From f8d7757e4cbf9f258d160d0baec6c740ae4b0763 Mon Sep 17 00:00:00 2001 From: pantianying Date: Tue, 15 Sep 2020 18:01:04 +0800 Subject: [PATCH 4/4] spit import pkg --- common/logger/logger.go | 2 +- dubbo/call_test.go | 5 ++++- service/proxy/http/http.go | 9 ++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/logger/logger.go b/common/logger/logger.go index d0d431e46..d2b603f37 100644 --- a/common/logger/logger.go +++ b/common/logger/logger.go @@ -1,13 +1,13 @@ package logger import ( - getty "github.com/apache/dubbo-getty" "io/ioutil" "log" "path" ) import ( + getty "github.com/apache/dubbo-getty" perrors "github.com/pkg/errors" "go.uber.org/zap" "go.uber.org/zap/zapcore" diff --git a/dubbo/call_test.go b/dubbo/call_test.go index 38ed73537..b3095f262 100644 --- a/dubbo/call_test.go +++ b/dubbo/call_test.go @@ -2,10 +2,13 @@ package dubbo import ( "encoding/json" - "github.com/stretchr/testify/assert" "testing" ) +import ( + "github.com/stretchr/testify/assert" +) + var ( testDealGerRespString1 = `{ "devices": [{ diff --git a/service/proxy/http/http.go b/service/proxy/http/http.go index bb547af36..023ddb4a8 100644 --- a/service/proxy/http/http.go +++ b/service/proxy/http/http.go @@ -1,5 +1,11 @@ package http +import ( + "io" + "net/http" + "time" +) + import ( "github.com/dubbogo/dubbo-go-proxy/common/config" "github.com/dubbogo/dubbo-go-proxy/common/errcode" @@ -8,9 +14,6 @@ import ( "github.com/dubbogo/dubbo-go-proxy/dubbo" ct "github.com/dubbogo/dubbo-go-proxy/service/context" "github.com/dubbogo/dubbo-go-proxy/service/metadata/redis" - "io" - "net/http" - "time" ) var srv http.Server