You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/28 13:50:48 UTC
[GitHub] [dubbo] EarthChen opened a new issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
EarthChen opened a new issue #8363:
URL: https://github.com/apache/dubbo/issues/8363
### Environment
* Dubbo version: 3.0.1
* Operating System version: macos
* Java version: 8
### Steps to reproduce this issue
i use custom exceptionFilter for return bizException ,
```java
public class DubboExceptionFilter implements Filter, Filter.Listener {
private static Logger log = LoggerFactory.getLogger(DubboExceptionFilter.class);
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}
@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
// ...
// my customer exception
if (className.startsWith("com.test.excepiton")) {
return;
}
// directly throw if it's dubbo exception
if (exception instanceof RpcException) {
return;
}
// otherwise, wrap with RuntimeException and throw back to the client
appResponse.setException(new RuntimeException(StringUtils.toString(exception)));
} catch (Throwable e) {
log.warn("Fail to ExceptionFilter when called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
}
}
}
}
```
2. The provider provides an interface
```java
@Override
public SetMealCreateResponse createSetMealByUserIdAndTeamId(SetMealCreateRequest setMealCreateRequest) {
throw new BizRpcException(1111, "test");
}
```
## use dubbo protocol
![image](https://user-images.githubusercontent.com/20179425/127333688-032ae0ec-cb2d-4a21-a5c8-889e3019efb4.png)
## use tri protocol
![image](https://user-images.githubusercontent.com/20179425/127333289-445d1b02-0dde-4539-a5eb-006935da8015.png)
Pls. provide [GitHub address] to reproduce this issue.
### Expected Result
use tri protocol should return real exception
### Actual Result
return rpcException
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] EarthChen commented on issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
Posted by GitBox <gi...@apache.org>.
EarthChen commented on issue #8363:
URL: https://github.com/apache/dubbo/issues/8363#issuecomment-1044107226
> 3.0.5需要怎么解决呢,在consumer filter拿不到attachments @EarthChen
有什么问题嘛,filter 中可以拿到阿
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] EarthChen closed issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
Posted by GitBox <gi...@apache.org>.
EarthChen closed issue #8363:
URL: https://github.com/apache/dubbo/issues/8363
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] guohao commented on issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
Posted by GitBox <gi...@apache.org>.
guohao commented on issue #8363:
URL: https://github.com/apache/dubbo/issues/8363#issuecomment-897533563
Scenario1 : Non-Protobuf
Exception will be serialized and rethrowed at client side.
Scenario2 : Protobuf
Serialization of origin exception is not supported, insteadly a `TripleRpcException` will be returned. Users can return and get custom error code in response's attachments like this
```java
@Activate(group = {CommonConstants.CONSUMER})
public class BizErrorCodeClientFilter implements ClusterFilter, BaseFilter.Listener {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}
@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
appResponse.getObjectAttachment("biz-err-code");
}
@Override
public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] feng996 commented on issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
Posted by GitBox <gi...@apache.org>.
feng996 commented on issue #8363:
URL: https://github.com/apache/dubbo/issues/8363#issuecomment-1042865385
3.0.5需要怎么解决呢,在consumer filter拿不到attachments @EarthChen
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] EarthChen commented on issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
Posted by GitBox <gi...@apache.org>.
EarthChen commented on issue #8363:
URL: https://github.com/apache/dubbo/issues/8363#issuecomment-888802816
> Probably we shoude consider wrap custom exception when use triple/hessian, could you help to fix it ? @EarthChen
I'm willing to try and fix it, but I think i dont know enough about dubbo details and it might take a lot of time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] EarthChen commented on issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
Posted by GitBox <gi...@apache.org>.
EarthChen commented on issue #8363:
URL: https://github.com/apache/dubbo/issues/8363#issuecomment-897643718
if you want read more,this is demo https://github.com/EarthChen/dubbo-triple-demo/tree/transmit-exception-by-attachment
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] EarthChen commented on issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
Posted by GitBox <gi...@apache.org>.
EarthChen commented on issue #8363:
URL: https://github.com/apache/dubbo/issues/8363#issuecomment-897639172
> Scenario1 : Non-Protobuf
> Exception will be serialized and rethrowed at client side.
> Scenario2 : Protobuf
> Serialization of origin exception is not supported, insteadly a `TripleRpcException` will be returned. Users can return and get custom error code in response's attachments like this
>
> ```java
> @Activate(group = {CommonConstants.CONSUMER})
> public class BizErrorCodeClientFilter implements ClusterFilter, BaseFilter.Listener {
> @Override
> public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
> return invoker.invoke(invocation);
> }
>
> @Override
> public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
> appResponse.getObjectAttachment("biz-err-code");
> }
>
> @Override
> public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {
> }
> }
> ```
# follow Scenario2 ,this is more detailed demo
# provider
## biz code
```java
@DubboService
@Slf4j
public class MyServiceImpl implements MyService {
@Override
public HelloReply sayHello(HelloRequest helloRequest) {
log.error("test runtimeException helloRequest={}", helloRequest);
throw new DubboBizException(1111, "test");
}
@Override
public CompletableFuture<HelloReply> sayHelloAsync(HelloRequest helloRequest) {
return null;
}
}
```
## filter
copy `org.apache.dubbo.rpc.filter.ExceptionFilter` and add yours biz exception logic
```java
@Activate(group = CommonConstants.PROVIDER)
public class DubboProviderExceptionFilter implements Filter, Filter.Listener {
private static Logger log = LoggerFactory.getLogger(DubboProviderExceptionFilter2.class);
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}
@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
if (appResponse.hasException() && GenericService.class != invoker.getInterface()) {
try {
Throwable exception = appResponse.getException();
//。。。。
// user-defined biz exception
if (exception instanceof DubboBizException) {
DubboBizException bizException = (DubboBizException) exception;
Map<String, String> attach = appResponse.getAttachments();
attach.put(DubboConstant.CODE, bizException.getCode().toString());
attach.put(DubboConstant.MSG, bizException.getMessage());
return;
}
//。。。。
// directly throw if it's dubbo exception
if (exception instanceof RpcException) {
return;
}
// otherwise, wrap with RuntimeException and throw back to the client
appResponse.setException(new RuntimeException(StringUtils.toString(exception)));
} catch (Throwable e) {
log.warn("Fail to ExceptionFilter when called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
}
}
}
@Override
public void onError(Throwable e, Invoker<?> invoker, Invocation invocation) {
log.error("Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
}
}
```
# Consumer
## filter
```java
@Activate(group = {CommonConstants.CONSUMER})
public class DubboConsumerClusterExceptionFilter implements ClusterFilter, ClusterFilter.Listener {
private static Logger log = LoggerFactory.getLogger(DubboConsumerClusterExceptionFilter.class);
@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
Map<String, String> attach = appResponse.getAttachments();
String code = attach.get(DubboConstant.CODE);
String msg = attach.get(DubboConstant.MSG);
if (!StringUtils.isBlank(code)) {
appResponse.setException(new DubboBizException(Integer.parseInt(code), msg));
}
}
@Override
public void onError(Throwable e, Invoker<?> invoker, Invocation invocation) {
log.error("Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
}
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}
}
```
## result
![image](https://user-images.githubusercontent.com/20179425/129204617-62326d9f-1cd3-4ed8-84d5-8f8c7091282e.png)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] guohao commented on issue #8363: [Dubbo 3.0.1] use triple protocol cant return real exception
Posted by GitBox <gi...@apache.org>.
guohao commented on issue #8363:
URL: https://github.com/apache/dubbo/issues/8363#issuecomment-888799438
Probably we shoude consider wrap custom exception when use triple/hessian, could you help to fix it ? @EarthChen
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org