Skip to content
Snippets Groups Projects
Commit 1a6f1cf4 authored by fangyincheng's avatar fangyincheng
Browse files

Fix:return error should be Response_OK

parent 564b63cd
No related branches found
No related tags found
No related merge requests found
Showing
with 52 additions and 31 deletions
...@@ -24,11 +24,11 @@ import ( ...@@ -24,11 +24,11 @@ import (
) )
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common/logger"
"github.com/dubbogo/hessian2" "github.com/dubbogo/hessian2"
) )
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common/logger"
_ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory" _ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory"
"github.com/dubbo/go-for-apache-dubbo/config" "github.com/dubbo/go-for-apache-dubbo/config"
_ "github.com/dubbo/go-for-apache-dubbo/protocol/dubbo" _ "github.com/dubbo/go-for-apache-dubbo/protocol/dubbo"
...@@ -99,6 +99,13 @@ func main() { ...@@ -99,6 +99,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
......
...@@ -142,6 +142,10 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User ...@@ -142,6 +142,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);
} }
......
...@@ -25,9 +25,6 @@ import ( ...@@ -25,9 +25,6 @@ import (
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/common/logger"
)
import (
_ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory" _ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory"
"github.com/dubbo/go-for-apache-dubbo/config" "github.com/dubbo/go-for-apache-dubbo/config"
_ "github.com/dubbo/go-for-apache-dubbo/protocol/jsonrpc" _ "github.com/dubbo/go-for-apache-dubbo/protocol/jsonrpc"
......
...@@ -14,13 +14,10 @@ ...@@ -14,13 +14,10 @@
package impl package impl
import (
"github.com/dubbo/go-for-apache-dubbo/common/logger"
)
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common/constant" "github.com/dubbo/go-for-apache-dubbo/common/constant"
"github.com/dubbo/go-for-apache-dubbo/common/extension" "github.com/dubbo/go-for-apache-dubbo/common/extension"
"github.com/dubbo/go-for-apache-dubbo/common/logger"
"github.com/dubbo/go-for-apache-dubbo/filter" "github.com/dubbo/go-for-apache-dubbo/filter"
"github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol"
) )
......
...@@ -2,7 +2,7 @@ module github.com/dubbo/go-for-apache-dubbo ...@@ -2,7 +2,7 @@ module github.com/dubbo/go-for-apache-dubbo
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=
......
...@@ -16,13 +16,13 @@ package dubbo ...@@ -16,13 +16,13 @@ package dubbo
import ( import (
"context" "context"
"github.com/dubbogo/hessian2"
"sync" "sync"
"testing" "testing"
"time" "time"
) )
import ( import (
"github.com/dubbogo/hessian2"
perrors "github.com/pkg/errors" perrors "github.com/pkg/errors"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
...@@ -81,7 +81,7 @@ func TestClient_Call(t *testing.T) { ...@@ -81,7 +81,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)
......
...@@ -212,7 +212,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) { ...@@ -212,7 +212,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
...@@ -261,15 +261,15 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { ...@@ -261,15 +261,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
} }
} }
...@@ -278,7 +278,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { ...@@ -278,7 +278,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
} }
...@@ -286,7 +286,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { ...@@ -286,7 +286,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
} }
...@@ -323,8 +323,8 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { ...@@ -323,8 +323,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()
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
package protocolwrapper package protocolwrapper
import ( import (
"github.com/dubbo/go-for-apache-dubbo/filter"
"strings" "strings"
) )
...@@ -23,6 +22,7 @@ import ( ...@@ -23,6 +22,7 @@ import (
"github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common"
"github.com/dubbo/go-for-apache-dubbo/common/constant" "github.com/dubbo/go-for-apache-dubbo/common/constant"
"github.com/dubbo/go-for-apache-dubbo/common/extension" "github.com/dubbo/go-for-apache-dubbo/common/extension"
"github.com/dubbo/go-for-apache-dubbo/filter"
"github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol"
) )
......
...@@ -20,7 +20,6 @@ import ( ...@@ -20,7 +20,6 @@ import (
) )
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common/logger"
perrors "github.com/pkg/errors" perrors "github.com/pkg/errors"
) )
...@@ -29,6 +28,7 @@ import ( ...@@ -29,6 +28,7 @@ import (
"github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common"
"github.com/dubbo/go-for-apache-dubbo/common/constant" "github.com/dubbo/go-for-apache-dubbo/common/constant"
"github.com/dubbo/go-for-apache-dubbo/common/extension" "github.com/dubbo/go-for-apache-dubbo/common/extension"
"github.com/dubbo/go-for-apache-dubbo/common/logger"
"github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol"
"github.com/dubbo/go-for-apache-dubbo/protocol/protocolwrapper" "github.com/dubbo/go-for-apache-dubbo/protocol/protocolwrapper"
"github.com/dubbo/go-for-apache-dubbo/registry" "github.com/dubbo/go-for-apache-dubbo/registry"
......
...@@ -18,14 +18,11 @@ import ( ...@@ -18,14 +18,11 @@ import (
"sync" "sync"
) )
import (
"github.com/dubbo/go-for-apache-dubbo/common/logger"
)
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common"
"github.com/dubbo/go-for-apache-dubbo/common/constant" "github.com/dubbo/go-for-apache-dubbo/common/constant"
"github.com/dubbo/go-for-apache-dubbo/common/extension" "github.com/dubbo/go-for-apache-dubbo/common/extension"
"github.com/dubbo/go-for-apache-dubbo/common/logger"
"github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol"
"github.com/dubbo/go-for-apache-dubbo/protocol/protocolwrapper" "github.com/dubbo/go-for-apache-dubbo/protocol/protocolwrapper"
"github.com/dubbo/go-for-apache-dubbo/registry" "github.com/dubbo/go-for-apache-dubbo/registry"
......
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