GongLe opened a new issue, #14416:
URL: https://github.com/apache/dubbo/issues/14416

   ### Pre-check
   
   - [X] I am sure that all the content I provide is in English.
   
   
   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/dubbo/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Apache Dubbo Component
   
   Java SDK (apache/dubbo)
   
   ### Dubbo Version
   
   3.2.14
   
   ### Steps to reproduce this issue
   
    How to get attachment data in the consumer ,attachment  data set  from 
provider cusome exception filter ?
    DubboProviderExceptionFilter:
    RpcContextAttachment serverContext = RpcContext.getServerContext();
                       
serverContext.setObjectAttachment(ATTA_NAME_EXCEPTION_CODE, br.getCode());
   DubboConsumerExceptionFilter:
    RpcContext.getServerContext().getObjectAttachments() 
,RpcContext.getContext().getAttachments();
   Neither method can be obtained
   
   ### What you expected to happen
   
   DubboProviderExceptionFilter set attachment data , 
DubboConsumerExceptionFilter get server attachment data ,used to customize 
exceptions extra data 
   
   ### Anything else
   
   source code:
   ```
   @Activate(group = CommonConstants.PROVIDER )
   public class DubboProviderExceptionFilter implements Filter, Filter.Listener 
{
       protected final Logger logger = LoggerFactory.getLogger(this.getClass());
       public static String ATTA_NAME_EXCEPTION_CODE = "__code";
       public static String ATTA_NAME_EXCEPTION_DETAIL_MSG = "__detailMsg";
       public static String ATTA_NAME_EXCEPTION_DETAIL_DATA = "__data";
   
       @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();
   
                   String className = exception.getClass().getName();
                   //如果是我们系统自定义异常直接返回
                   if ( ClassUtil2.isAssignable(ServiceException.class, 
exception.getClass())) {
                       //服务提供方写入回传参数
                       ServiceException br = (ServiceException) exception;
                       invocation.setObjectAttachment(ATTA_NAME_EXCEPTION_CODE, 
br.getCode());
                       
invocation.setObjectAttachment(ATTA_NAME_EXCEPTION_DETAIL_MSG, 
br.getDetailMsg());
                       
invocation.setObjectAttachment(ATTA_NAME_EXCEPTION_DETAIL_DATA, 
br.getExtraData());
   
                       RpcContextAttachment serverContext = 
RpcContext.getServerContext();
                       
serverContext.setObjectAttachment(ATTA_NAME_EXCEPTION_CODE, br.getCode());
                       
serverContext.setObjectAttachment(ATTA_NAME_EXCEPTION_DETAIL_MSG, 
br.getDetailMsg());
                       
serverContext.setObjectAttachment(ATTA_NAME_EXCEPTION_DETAIL_DATA, 
br.getExtraData());
   
                       return;
                   }
   
   ```
    ```
   @Activate(group = CommonConstants.CONSUMER )
   public class DubboConsumerExceptionFilter implements Filter, Filter.Listener 
{
   
       @Override
       public void onResponse(Result appResponse, Invoker<?> invoker, 
Invocation invocation) {
           Throwable exec = appResponse.getException();
           if (exec != null && 
ServiceException.class.isAssignableFrom(exec.getClass())) {
               Map<String, String> attachments = invocation.getAttachments();
   
   
               if (attachments.containsKey(ATTA_NAME_EXCEPTION_CODE)) {
                   ReflectionUtil.setFieldValue(exec, "code", 
attachments.get(ATTA_NAME_EXCEPTION_CODE));
               }
   
               if (attachments.containsKey(ATTA_NAME_EXCEPTION_DETAIL_MSG)) {
                   ReflectionUtil.setFieldValue(exec, "detailMsg", 
attachments.get(ATTA_NAME_EXCEPTION_DETAIL_MSG));
               }
   
               if (attachments.containsKey(ATTA_NAME_EXCEPTION_DETAIL_DATA)) {
                   ReflectionUtil.setFieldValue(exec, "extraData", 
attachments.get(ATTA_NAME_EXCEPTION_DETAIL_DATA));
               }
   
   
           }
       }
   
   ```
   
   ### Are you willing to submit a pull request to fix on your own?
   
   - [X] Yes I am willing to submit a pull request on my own!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to