Skip to content
Snippets Groups Projects
Commit fdb8b37f authored by Huxing Zhang's avatar Huxing Zhang Committed by GitHub
Browse files

Merge pull request #75 from fangyincheng/develop

Fix bug
parents 4dc63ad1 5ca095a7
No related branches found
No related tags found
No related merge requests found
Showing
with 59 additions and 31 deletions
# Apache Dubbo-go [中文](./README_CN.md) # # Apache Dubbo-go [中文](./README_CN.md) #
[![Build Status](https://travis-ci.com/apache/dubbo-go.svg?branch=master)](https://travis-ci.com/apache/dubbo-go) [![Build Status](https://travis-ci.org/apache/dubbo-go.svg?branch=master)](https://travis-ci.org/apache/dubbo-go)
[![codecov](https://codecov.io/gh/apache/dubbo-go/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-go) [![codecov](https://codecov.io/gh/apache/dubbo-go/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-go)
--- ---
......
# Apache Dubbo-go [English](./README.md) # # Apache Dubbo-go [English](./README.md) #
[![Build Status](https://travis-ci.com/apache/dubbo-go.svg?branch=master)](https://travis-ci.com/apache/dubbo-go) [![Build Status](https://travis-ci.org/apache/dubbo-go.svg?branch=master)](https://travis-ci.org/apache/dubbo-go)
[![codecov](https://codecov.io/gh/apache/dubbo-go/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-go) [![codecov](https://codecov.io/gh/apache/dubbo-go/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-go)
--- ---
......
...@@ -92,7 +92,7 @@ func (refconfig *ReferenceConfig) Refer() { ...@@ -92,7 +92,7 @@ func (refconfig *ReferenceConfig) Refer() {
refconfig.urls = append(refconfig.urls, &serviceUrl) refconfig.urls = append(refconfig.urls, &serviceUrl)
} else { } else {
if serviceUrl.Path == "" { if serviceUrl.Path == "" {
serviceUrl.Path = refconfig.InterfaceName + "/" serviceUrl.Path = "/" + refconfig.InterfaceName
} }
// merge url need to do // merge url need to do
newUrl := common.MergeUrl(serviceUrl, url) newUrl := common.MergeUrl(serviceUrl, url)
......
...@@ -27,11 +27,11 @@ import ( ...@@ -27,11 +27,11 @@ import (
) )
import ( import (
"github.com/apache/dubbo-go/common/logger" "github.com/dubbogo/hessian2"
hessian "github.com/dubbogo/hessian2"
) )
import ( import (
"github.com/apache/dubbo-go/common/logger"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory" _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config" "github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/protocol/dubbo" _ "github.com/apache/dubbo-go/protocol/dubbo"
...@@ -102,6 +102,13 @@ func main() { ...@@ -102,6 +102,13 @@ func main() {
println("response result: %v", user) println("response result: %v", user)
} }
println("\n\n\nstart to test dubbo - getErr")
user = &User{}
err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetErr(context.TODO(), []interface{}{"A003"}, user)
if err != nil {
println("getErr - error: %v", err)
}
println("\n\n\nstart to test dubbo illegal method") println("\n\n\nstart to test dubbo illegal method")
err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser1(context.TODO(), []interface{}{"A003"}, user) err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser1(context.TODO(), []interface{}{"A003"}, user)
if err != nil { if err != nil {
......
...@@ -94,6 +94,7 @@ func (User) JavaClassName() string { ...@@ -94,6 +94,7 @@ func (User) JavaClassName() string {
type UserProvider struct { type UserProvider struct {
GetUsers func(req []interface{}) ([]interface{}, error) GetUsers func(req []interface{}) ([]interface{}, error)
GetErr func(ctx context.Context, req []interface{}, rsp *User) error
GetUser func(ctx context.Context, req []interface{}, rsp *User) error GetUser func(ctx context.Context, req []interface{}, rsp *User) error
GetUser0 func(id string, name string) (User, error) GetUser0 func(id string, name string) (User, error)
GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error
......
...@@ -145,6 +145,10 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User ...@@ -145,6 +145,10 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User
return err return err
} }
func (u *UserProvider) GetErr(ctx context.Context, req []interface{}, rsp *User) error {
return perrors.New("exception")
}
func (u *UserProvider) GetUser0(id string, name string) (User, error) { func (u *UserProvider) GetUser0(id string, name string) (User, error) {
var err error var err error
......
...@@ -42,7 +42,7 @@ services: ...@@ -42,7 +42,7 @@ services:
protocols: protocols:
- name: "dubbo" - name: "dubbo"
ip : "127.0.0.1" # ip : "127.0.0.1"
port : 20000 port : 20000
#- name: "jsonrpc" #- name: "jsonrpc"
# ip: "127.0.0.1" # ip: "127.0.0.1"
......
...@@ -42,7 +42,7 @@ services: ...@@ -42,7 +42,7 @@ services:
protocols: protocols:
- name: "dubbo" - name: "dubbo"
ip : "127.0.0.1" # ip : "127.0.0.1"
port : 20000 port : 20000
#- name: "jsonrpc" #- name: "jsonrpc"
# ip: "127.0.0.1" # ip: "127.0.0.1"
......
...@@ -42,7 +42,7 @@ services: ...@@ -42,7 +42,7 @@ services:
protocols: protocols:
- name: "dubbo" - name: "dubbo"
ip : "127.0.0.1" # ip : "127.0.0.1"
port : 20000 port : 20000
#- name: "jsonrpc" #- name: "jsonrpc"
# ip: "127.0.0.1" # ip: "127.0.0.1"
......
...@@ -51,7 +51,16 @@ public class Consumer { ...@@ -51,7 +51,16 @@ public class Consumer {
System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
" UserInfo, Id:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() " UserInfo, Id:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString()
+ ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString());
User user9 = userProvider.GetUser1("A003");
} catch (Exception e) {
System.out.println("*************exception***********");
e.printStackTrace();
}
try {
userProvider.GetErr("A003");
} catch (Exception e) { } catch (Exception e) {
System.out.println("*************exception***********");
e.printStackTrace(); e.printStackTrace();
} }
} }
......
...@@ -20,6 +20,8 @@ import java.util.List; ...@@ -20,6 +20,8 @@ import java.util.List;
public interface UserProvider { public interface UserProvider {
User GetUser(String userId); User GetUser(String userId);
User GetErr(String userId) throws Exception;
User GetUser1(String userId);
List<User> GetUsers(List<String> userIdList); List<User> GetUsers(List<String> userIdList);
User GetUser0(String userId, String name); User GetUser0(String userId, String name);
......
...@@ -14,6 +14,8 @@ public interface UserProvider { ...@@ -14,6 +14,8 @@ public interface UserProvider {
User GetUser0(String userId, String name); User GetUser0(String userId, String name);
User GetErr(String userId) throws Exception;
Map<String, User> GetUserMap(List<String> userIdList); Map<String, User> GetUserMap(List<String> userIdList);
User getUser(int usercode); User getUser(int usercode);
......
...@@ -35,7 +35,9 @@ public class UserProviderAnotherImpl implements UserProvider { ...@@ -35,7 +35,9 @@ public class UserProviderAnotherImpl implements UserProvider {
public User GetUser0(String userId, String name) { public User GetUser0(String userId, String name) {
return new User(userId, name, 48); return new User(userId, name, 48);
} }
public User GetErr(String userId) throws Exception {
throw new Exception("exception");
}
public List<User> GetUsers(ArrayList<String> userIdList) { public List<User> GetUsers(ArrayList<String> userIdList) {
Iterator it = userIdList.iterator(); Iterator it = userIdList.iterator();
List<User> userList = new ArrayList<User>(); List<User> userList = new ArrayList<User>();
......
...@@ -32,6 +32,9 @@ public class UserProviderImpl implements UserProvider { ...@@ -32,6 +32,9 @@ public class UserProviderImpl implements UserProvider {
public User GetUser(String userId) { public User GetUser(String userId) {
return new User(userId, "zhangsan", 18); return new User(userId, "zhangsan", 18);
} }
public User GetErr(String userId) throws Exception {
throw new Exception("exception");
}
public User GetUser0(String userId, String name) { public User GetUser0(String userId, String name) {
return new User(userId, name, 18); return new User(userId, name, 18);
} }
......
...@@ -28,9 +28,6 @@ import ( ...@@ -28,9 +28,6 @@ import (
import ( import (
"github.com/apache/dubbo-go/common/logger" "github.com/apache/dubbo-go/common/logger"
)
import (
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory" _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config" "github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/protocol/jsonrpc" _ "github.com/apache/dubbo-go/protocol/jsonrpc"
......
...@@ -17,13 +17,10 @@ ...@@ -17,13 +17,10 @@
package impl package impl
import (
"github.com/apache/dubbo-go/common/logger"
)
import ( import (
"github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/filter" "github.com/apache/dubbo-go/filter"
"github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol"
) )
......
...@@ -2,7 +2,7 @@ module github.com/apache/dubbo-go ...@@ -2,7 +2,7 @@ module github.com/apache/dubbo-go
require ( require (
github.com/dubbogo/getty v0.0.0-20190523180329-bdf5e640ea53 github.com/dubbogo/getty v0.0.0-20190523180329-bdf5e640ea53
github.com/dubbogo/hessian2 v0.0.0-20190526221400-d5610bbd0a41 github.com/dubbogo/hessian2 v0.0.0-20190604191323-5290af08fb56
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec
github.com/stretchr/testify v1.3.0 github.com/stretchr/testify v1.3.0
......
...@@ -6,8 +6,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs ...@@ -6,8 +6,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dubbogo/getty v0.0.0-20190523180329-bdf5e640ea53 h1:bniSNoC4xnAbrx4estwc9F0qkWnh6ZDsAS0y9d7mPos= github.com/dubbogo/getty v0.0.0-20190523180329-bdf5e640ea53 h1:bniSNoC4xnAbrx4estwc9F0qkWnh6ZDsAS0y9d7mPos=
github.com/dubbogo/getty v0.0.0-20190523180329-bdf5e640ea53/go.mod h1:cRMSuoCmwc5lULFFnYZTxyCfZhObmRTNbS7XRnPNHSo= github.com/dubbogo/getty v0.0.0-20190523180329-bdf5e640ea53/go.mod h1:cRMSuoCmwc5lULFFnYZTxyCfZhObmRTNbS7XRnPNHSo=
github.com/dubbogo/hessian2 v0.0.0-20190526221400-d5610bbd0a41 h1:lNtW7+aN8oBdCoEuny0rOqOkL5duI4Cu3+G8vqibX48= github.com/dubbogo/hessian2 v0.0.0-20190604191323-5290af08fb56 h1:5ZhIvx1pqtpRSfUzcc6jkF9pFsx/DcwymDuuaM3jFuw=
github.com/dubbogo/hessian2 v0.0.0-20190526221400-d5610bbd0a41/go.mod h1:XFGDn4oSZX26zkcfhkM/fCJrOqwQJxk/xgWW1KMJBKM= github.com/dubbogo/hessian2 v0.0.0-20190604191323-5290af08fb56/go.mod h1:XFGDn4oSZX26zkcfhkM/fCJrOqwQJxk/xgWW1KMJBKM=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
......
...@@ -22,13 +22,17 @@ import ( ...@@ -22,13 +22,17 @@ import (
"sync" "sync"
"testing" "testing"
"time" "time"
)
hessian "github.com/dubbogo/hessian2" import (
"github.com/dubbogo/hessian2"
perrors "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
import (
"github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol"
perrors "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
type ( type (
...@@ -80,7 +84,7 @@ func TestClient_Call(t *testing.T) { ...@@ -80,7 +84,7 @@ func TestClient_Call(t *testing.T) {
user = &User{} user = &User{}
err = c.Call("127.0.0.1:20000", url, "GetUser1", []interface{}{"1", "username"}, user) err = c.Call("127.0.0.1:20000", url, "GetUser1", []interface{}{"1", "username"}, user)
assert.EqualError(t, err, "java exception:error") assert.EqualError(t, err, "got exception: error")
user2 := []interface{}{} user2 := []interface{}{}
err = c.Call("127.0.0.1:20000", url, "GetUser2", []interface{}{"1", "username"}, &user2) err = c.Call("127.0.0.1:20000", url, "GetUser2", []interface{}{"1", "username"}, &user2)
......
...@@ -211,7 +211,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) { ...@@ -211,7 +211,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
constant.VERSION_KEY: p.Service.Version, constant.VERSION_KEY: p.Service.Version,
})) }))
if err := result.Error(); err != nil { if err := result.Error(); err != nil {
p.Header.ResponseStatus = hessian.Response_SERVER_ERROR p.Header.ResponseStatus = hessian.Response_OK
p.Body = err p.Body = err
h.reply(session, p, hessian.PackageResponse) h.reply(session, p, hessian.PackageResponse)
return return
...@@ -260,15 +260,15 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { ...@@ -260,15 +260,15 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) {
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {
req.Header.ResponseStatus = hessian.Response_BAD_REQUEST req.Header.ResponseStatus = hessian.Response_SERVER_ERROR
if err, ok := e.(error); ok { if err, ok := e.(error); ok {
logger.Errorf("callService panic: %#v", err) logger.Errorf("callService panic: %#v", err)
req.Body = e.(error) req.Body = perrors.WithStack(err)
} else if err, ok := e.(string); ok { } else if err, ok := e.(string); ok {
logger.Errorf("callService panic: %#v", perrors.New(err)) logger.Errorf("callService panic: %#v", perrors.New(err))
req.Body = perrors.New(err) req.Body = perrors.New(err)
} else { } else {
logger.Errorf("callService panic: %#v", e) logger.Errorf("callService panic: %#v, this is impossible.", e)
req.Body = e req.Body = e
} }
} }
...@@ -277,7 +277,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { ...@@ -277,7 +277,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) {
svcIf := req.Body.(map[string]interface{})["service"] svcIf := req.Body.(map[string]interface{})["service"]
if svcIf == nil { if svcIf == nil {
logger.Errorf("service not found!") logger.Errorf("service not found!")
req.Header.ResponseStatus = hessian.Response_SERVICE_NOT_FOUND req.Header.ResponseStatus = hessian.Response_BAD_REQUEST
req.Body = perrors.New("service not found") req.Body = perrors.New("service not found")
return return
} }
...@@ -285,7 +285,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { ...@@ -285,7 +285,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) {
method := svc.Method()[req.Service.Method] method := svc.Method()[req.Service.Method]
if method == nil { if method == nil {
logger.Errorf("method not found!") logger.Errorf("method not found!")
req.Header.ResponseStatus = hessian.Response_SERVICE_NOT_FOUND req.Header.ResponseStatus = hessian.Response_BAD_REQUEST
req.Body = perrors.New("method not found") req.Body = perrors.New("method not found")
return return
} }
...@@ -322,8 +322,8 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { ...@@ -322,8 +322,8 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) {
retErr = returnValues[1].Interface() retErr = returnValues[1].Interface()
} }
if retErr != nil { if retErr != nil {
req.Header.ResponseStatus = hessian.Response_SERVER_ERROR req.Header.ResponseStatus = hessian.Response_OK
req.Body = retErr.(error) req.Body = perrors.WithStack(retErr.(error))
} else { } else {
req.Body = replyv.Interface() req.Body = replyv.Interface()
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment