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

Merge pull request #75 from fangyincheng/develop

Fix bug
parents 2e3dfb1f 0541c85f
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) #
[![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)
---
......
# 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)
---
......
......@@ -92,7 +92,7 @@ func (refconfig *ReferenceConfig) Refer() {
refconfig.urls = append(refconfig.urls, &serviceUrl)
} else {
if serviceUrl.Path == "" {
serviceUrl.Path = refconfig.InterfaceName + "/"
serviceUrl.Path = "/" + refconfig.InterfaceName
}
// merge url need to do
newUrl := common.MergeUrl(serviceUrl, url)
......
......@@ -27,11 +27,11 @@ import (
)
import (
"github.com/apache/dubbo-go/common/logger"
hessian "github.com/dubbogo/hessian2"
"github.com/dubbogo/hessian2"
)
import (
"github.com/apache/dubbo-go/common/logger"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/protocol/dubbo"
......@@ -102,6 +102,13 @@ func main() {
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")
err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser1(context.TODO(), []interface{}{"A003"}, user)
if err != nil {
......
......@@ -94,6 +94,7 @@ func (User) JavaClassName() string {
type UserProvider struct {
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
GetUser0 func(id string, name string) (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
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) {
var err error
......
......@@ -42,7 +42,7 @@ services:
protocols:
- name: "dubbo"
ip : "127.0.0.1"
# ip : "127.0.0.1"
port : 20000
#- name: "jsonrpc"
# ip: "127.0.0.1"
......
......@@ -42,7 +42,7 @@ services:
protocols:
- name: "dubbo"
ip : "127.0.0.1"
# ip : "127.0.0.1"
port : 20000
#- name: "jsonrpc"
# ip: "127.0.0.1"
......
......@@ -42,7 +42,7 @@ services:
protocols:
- name: "dubbo"
ip : "127.0.0.1"
# ip : "127.0.0.1"
port : 20000
#- name: "jsonrpc"
# ip: "127.0.0.1"
......
......@@ -51,7 +51,16 @@ public class Consumer {
System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
" UserInfo, Id:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().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) {
System.out.println("*************exception***********");
e.printStackTrace();
}
}
......
......@@ -20,6 +20,8 @@ import java.util.List;
public interface UserProvider {
User GetUser(String userId);
User GetErr(String userId) throws Exception;
User GetUser1(String userId);
List<User> GetUsers(List<String> userIdList);
User GetUser0(String userId, String name);
......
......@@ -14,6 +14,8 @@ public interface UserProvider {
User GetUser0(String userId, String name);
User GetErr(String userId) throws Exception;
Map<String, User> GetUserMap(List<String> userIdList);
User getUser(int usercode);
......
......@@ -35,7 +35,9 @@ public class UserProviderAnotherImpl implements UserProvider {
public User GetUser0(String userId, String name) {
return new User(userId, name, 48);
}
public User GetErr(String userId) throws Exception {
throw new Exception("exception");
}
public List<User> GetUsers(ArrayList<String> userIdList) {
Iterator it = userIdList.iterator();
List<User> userList = new ArrayList<User>();
......
......@@ -32,6 +32,9 @@ public class UserProviderImpl implements UserProvider {
public User GetUser(String userId) {
return new User(userId, "zhangsan", 18);
}
public User GetErr(String userId) throws Exception {
throw new Exception("exception");
}
public User GetUser0(String userId, String name) {
return new User(userId, name, 18);
}
......
......@@ -28,9 +28,6 @@ import (
import (
"github.com/apache/dubbo-go/common/logger"
)
import (
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/protocol/jsonrpc"
......
......@@ -17,13 +17,10 @@
package impl
import (
"github.com/apache/dubbo-go/common/logger"
)
import (
"github.com/apache/dubbo-go/common/constant"
"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/protocol"
)
......
......@@ -2,7 +2,7 @@ module github.com/apache/dubbo-go
require (
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/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec
github.com/stretchr/testify v1.3.0
......
......@@ -22,13 +22,17 @@ import (
"sync"
"testing"
"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/protocol"
perrors "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
type (
......@@ -80,7 +84,7 @@ func TestClient_Call(t *testing.T) {
user = &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{}{}
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{}) {
constant.VERSION_KEY: p.Service.Version,
}))
if err := result.Error(); err != nil {
p.Header.ResponseStatus = hessian.Response_SERVER_ERROR
p.Header.ResponseStatus = hessian.Response_OK
p.Body = err
h.reply(session, p, hessian.PackageResponse)
return
......@@ -260,15 +260,15 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) {
defer func() {
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 {
logger.Errorf("callService panic: %#v", err)
req.Body = e.(error)
req.Body = perrors.WithStack(err)
} else if err, ok := e.(string); ok {
logger.Errorf("callService panic: %#v", perrors.New(err))
req.Body = perrors.New(err)
} else {
logger.Errorf("callService panic: %#v", e)
logger.Errorf("callService panic: %#v, this is impossible.", e)
req.Body = e
}
}
......@@ -277,7 +277,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) {
svcIf := req.Body.(map[string]interface{})["service"]
if svcIf == nil {
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")
return
}
......@@ -285,7 +285,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) {
method := svc.Method()[req.Service.Method]
if method == nil {
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")
return
}
......@@ -322,8 +322,8 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) {
retErr = returnValues[1].Interface()
}
if retErr != nil {
req.Header.ResponseStatus = hessian.Response_SERVER_ERROR
req.Body = retErr.(error)
req.Header.ResponseStatus = hessian.Response_OK
req.Body = perrors.WithStack(retErr.(error))
} else {
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