zoukankan      html  css  js  c++  java
  • 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;
        }
    }
    

    配置参考白名单示例


  • 相关阅读:
    jar强退出 JVM报错:Failed to write core dump. Core dumps have been disabled.
    配置 DHCP Snooping 和 IPSG
    OpenOffice
    RabbitMQ ADD
    YAPI 接口管理
    mysql:1153 Got a packet bigger than ‘max_allowed_packet’ bytes的解决方法
    修改端口的VLAN
    阿里云OSS设置跨域访问
    seata连接nacos 报错
    Linux登录超时问题
  • 原文地址:https://www.cnblogs.com/luleiitlife/p/8545026.html
Copyright © 2011-2022 走看看