• dubbo Filter


    对于Java Web应用,spring的拦截器可以拦截Web接口的调用,而对于dubbo接口,Spring的拦截器就不管用了。要实现此功能,需要dubbo提供Filter
    dubbo中的Filter过滤器的使用场景:
    1 、IP白名单
    示例:给dubbo接口添加白名单——dubbo Filter的使用
    http://blog.csdn.net/mj158518/article/details/47379799
    2 、soa调用异常处理

    import com.alibaba.dubbo.rpc.*;
    import com.#.service.channel.dto.response.ResponseResult;
    import com.##.service.channel.dto.response.ResponseResult.ResponseCode;
    import com.##.service.common.exception.BusinessException;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    
    public class EPayFilter implements Filter {
    
        private static final Logger LOGGER = LoggerFactory.getLogger(EPayFilter.class);
    
        @Override
        public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
            Result result = invoker.invoke(invocation);
            if (result.hasException()) {
                Throwable exception = result.getException();
                if (exception instanceof BusinessException) {
                    LOGGER.error("调用方法{}出现异常,请求参数为:{},异常信息为:{}", invocation.getMethodName(), invocation.getArguments(), exception.getMessage());
                    BusinessException e = (BusinessException) exception;
                    ResponseResult responseResult = new ResponseResult(e.getResponseCode(), e.getMessage());
                    return new RpcResult(responseResult);
                }
                LOGGER.error("调用方法{}出现异常,请求参数为:{}", invocation.getMethodName(), invocation.getArguments(), exception);
                ResponseResult responseResult = new ResponseResult(ResponseCode.EXCEPTION, exception.getMessage());
                return new RpcResult(responseResult);
            }
            return result;
        }
    }
    

    配置参考白名单示例


  • 相关阅读:
    PAT 甲级 1101 Quick Sort
    PAT 甲级 1038 Recover the Smallest Number
    #Leetcode# 112. Path Sum
    #Leetcode# 17. Letter Combinations of a Phone Number
    #Leetcode# 235. Lowest Common Ancestor of a Binary Search Tree
    C++结构体重构
    【NOIP2016提高A组模拟9.7】鼎纹
    快速幂总结
    【NOIP2013提高组】货车运输
    【NOIP2015提高组】运输计划
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13310662.html
Copyright © 2020-2023  润新知