首页 > 其他分享 >接口过期过滤器

接口过期过滤器

时间:2023-04-28 13:45:28浏览次数:26  
标签:lang 过期 expiredInterfaceFilter 接口 import 过滤器 org annotation

注解类

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 过期接口通知
 */
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ExpiredInterface {
    /** 接口删除时间戳 */
    String deadline() default "2023-06-30";

    /** 是否抛出异常信息 */
    boolean throwError() default false;

    /** 新接口信息 */
    String newInterface() default "";

    /** 返回的提示信息 */
    String msg() default "接口已过期,请更换接口!";
}

过滤器

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.lang.reflect.Method;
import java.util.Date;

/**
 * @Description : 过期接口通知过滤器
 * @Author : cxw
 * @Date : 2022/11/30 10:56
 * @Version : 1.0
 **/
@Component
@Aspect
@Order(100)
public class ExpiredInterfaceFilter {

    Logger logger= LoggerFactory.getLogger(ExpiredInterfaceFilter.class);

    // 定义 注解 类型的切点
    @Pointcut("@annotation(ExpiredInterface)|| @within(ExpiredInterface)")
    public void arrPointcut() {}

    // 实现过期接口功能
    @Around("arrPointcut()")
    public Object arrBusiness(ProceedingJoinPoint joinPoint) throws Throwable {
        // 获取方法的 AvoidRepeatRequest 注解
        Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
        ExpiredInterface annotation = method.getAnnotation(ExpiredInterface.class);
        if(annotation==null){
            annotation = joinPoint.getTarget().getClass().getAnnotation(ExpiredInterface.class);
        }
        if(annotation!=null){
            logger.error(annotation.msg()+"接口删除时间节点:"+annotation.deadline() +" 请使用新接口: "+annotation.newInterface());
        }
        String expiredInterfaceFilter = System.getProperty("ExpiredInterfaceFilter");
        if(annotation.throwError()||isDebug(expiredInterfaceFilter)){
            throw new Exception(annotation.msg()+"接口删除时间节点:"+new Date(annotation.deadline()) +" 请使用新接口: "+annotation.newInterface());
        }
        return joinPoint.proceed();
    }

    /**
     * 判断是否抛出异常
     * @param expiredInterfaceFilter
     * @return
     */
    private boolean isDebug(String expiredInterfaceFilter) {
        if(StringUtils.isEmpty(expiredInterfaceFilter))return false;
        if(expiredInterfaceFilter.equals("throwError"))return true;
        return false;
    }
}

 

标签:lang,过期,expiredInterfaceFilter,接口,import,过滤器,org,annotation
From: https://www.cnblogs.com/raorao1994/p/17361867.html

相关文章

  • 接口重复调用限制过滤器
    注解类importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;/***重复请求过滤器*/@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.METHOD......
  • 面试官:抽象类和接口有什么区别?
    关注“Java后端技术全栈”回复“000”获取大量电子书抽象类和接口有什么区别?这是一道初中级面试中频率相当高的,下面我们就来看看如何应答。初级回答实现:抽象类的子类使用extends来继承;接口必须使用implements来实现接口。构造函数:抽象类可以有构造函数;接口不能有。实现数量:类可......
  • 接口测试面试题整理
    1.什么是接口测试?接口测试:是测试系统组件间接口的一种测试方法接口测试的重点:检查数据的交换,数据传递的正确性,以及接口间的逻辑依赖关系接口测试的意义:在软件开发的同时实现并行测试,减少页面层测试的深度,缩短整个项目的测试周期2.接口自动化测试的流程?基本的接口功能自动......
  • EBS:OM接口表导入销售订单失败
     用户通过集成器程序导入销售订单,过程调用了定义程序包(CUX2056_网络销售订单导入)向OM接口表,再调用标准程序将接口转销售订单用户收到错误信息“价目表价格或销售价格不正确。请输入值为正的价目表价格和销售价格。” 从OM的处理信息表查到最近处理错误信息SELECTm.*,m......
  • Python_14 接口测试报告
    一、查缺补漏 1.测试用例要复制到pycharm执行的项目中,才能显示 2.函数用下划线,类用大驼峰 3.pycharm一行显示(不换行): File->settings->Editor->General->Console中把Usesoftwrapsin取消 4.设置成unittest在File->settings->Tools->PythonIntegratedTools->Test......
  • 解析后端接口的文件流
    下面使用的是若依框架中的axios请求api:通用importrequestfrom'@/utils/request'exportfunctionguideCome(data){returnrequest({url:'/sys/client/export',method:'post',responseType:&#......
  • jeecgboot启动时日志打印所有接口,作为开发时的参考作用吧。
    主要的方式是使用了RequestMappingHandlerMapping这个bean当中保存了所有的映射、对应的controller类、方法等等的信息。在单体启动类中取出这个bean然后遍历就可以了,代码如下:/***单体启动类(采用此类启动为单体模式)*/@Slf4j@SpringBootApplicationpublicclassJeecgSyste......
  • 接口开发文档及注意事项
    接口开发是指通过定义一组接口,使不同的系统或设备之间能够进行数据通信和互操作的过程。以下是一些在接口开发过程中需要注意的事项:  接口定义:在定义接口时,需要明确接口的输入输出参数、数据类型、异常处理等信息,以确保不同的系统或设备之间能够正确地交换数据。  接口实现......
  • API 接口规范
    [API接口规范-BNDong-博客园](https://www.cnblogs.com/bndong/p/6139598.html)整体规范建议采用RESTful方式来实施。协议API与客户端通讯协议主要包含 http 和 https,建议使用 https 确保交互数据的传输安全。域名应该尽量将API部署在专用域名之下。Gohttps:/......
  • lazada按关键字搜索商品API接口
    ​lazada按关键字搜索商品API接口,在lazada上搜索产品,如果只需要搜索单个产品的话,那么直接在搜索框输入“关键字”即可,如果需要多个产品,那么则需要进行关键字扩展。lazada按关键字搜索商品API接口分为两部分:1.查询列表部分:在列表部分输入“关键字”,即可查询到对应的商品列表;2......