Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapterjava #2

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package logger

import (
"github.com/dubbogo/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"
Expand Down
5 changes: 5 additions & 0 deletions dubbo/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
5 changes: 4 additions & 1 deletion dubbo/call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package dubbo

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
)

import (
"github.com/stretchr/testify/assert"
)

var (
testDealGerRespString1 = `{
"devices": [{
Expand Down
10 changes: 6 additions & 4 deletions dubbo/dubbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dubbo

import (
"context"
"github.com/dubbogo/dubbo-go-proxy/common/config"

"strings"
"sync"
"time"
Expand All @@ -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 (
Expand Down
45 changes: 45 additions & 0 deletions dubbo/java.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dubbo

import (
pantianying marked this conversation as resolved.
Show resolved Hide resolved
"errors"
)

import (
"github.com/dubbogo/dubbo-go-proxy/common/logger"
)

// java class name elem
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
}
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ 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.3
github.com/dubbogo/getty v1.3.9
pantianying marked this conversation as resolved.
Show resolved Hide resolved
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
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -70,11 +72,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=
Expand Down Expand Up @@ -142,6 +148,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=
Expand Down Expand Up @@ -280,6 +288,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=
Expand Down Expand Up @@ -348,14 +358,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=
Expand Down
3 changes: 3 additions & 0 deletions service/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package service

import (
"context"
)

import (
"github.com/dubbogo/dubbo-go-proxy/dubbo"
)

Expand Down
10 changes: 7 additions & 3 deletions service/context/http_context.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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"
"github.com/dubbogo/dubbo-go-proxy/common/logger"
"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 {
Expand Down Expand Up @@ -86,6 +89,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,
Expand Down
10 changes: 8 additions & 2 deletions service/metadata/redis/redis.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 6 additions & 3 deletions service/proxy/http/http.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down