• fegin调用关于session,请求头传递参数问题


    feign调用传递请求头?
    方案:写一个过滤器,将请求头传递过去
    public class FeignBasicAuthRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
    .getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    Enumeration headerNames = request.getHeaderNames();
    if (headerNames != null) {
    while (headerNames.hasMoreElements()) {
    String name = headerNames.nextElement();
    String values = request.getHeader(name);
    requestTemplate.header(name, values);
    }
    }
    }
    }
    feign调用传递参数?
    方案:写一个过滤器,将参数传递过去
    public class FeignBasicAuthRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
    .getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    Enumeration headerNames = request.getHeaderNames();
    if (headerNames != null) {
    while (headerNames.hasMoreElements()) {
    String name = headerNames.nextElement();
    String values = request.getHeader(name);
    requestTemplate.header(name, values);
    }
    }
    Enumeration bodyNames = request.getParameterNames();
    StringBuffer body =new StringBuffer();
    if (bodyNames != null) {
    while (bodyNames.hasMoreElements()) {
    String name = bodyNames.nextElement();
    String values = request.getParameter(name);
    body.append(name).append(“=”).append(values).append(“&”);
    }
    }
    if(body.length()!=0) {
    body.deleteCharAt(body.length()-1);
    template.body(body.toString());
    logger.info(“feign interceptor body:{}”,body.toString());
    }
    }
    }
    feign 调用传递session信息?
    问题:写一个过滤器将session信息传递过去,这里明确一个东西session信息是放在
    InheritableThreadLocal中,但是feign线程是存在复用的,如果上一个线程的threadLocal没有释放的话,后面复用该线程的时候,向threadLocal塞入session将无法塞入。此时会造成内存泄露的问题。具体表现为调用b线程,b线程去获取该线程的threadlocal(由于线程复用的原因)将会获取到a线程的threadlocal。
    方案:每次向threadLocal塞入数据之前,将threadlocal清空。

  • 相关阅读:
    redis 高可用
    STL之优先级队列(priority_queue)
    TCP 连接管理机制(二)——TCP四次挥手的TIME_WAIT、CLOSE_WAIT状态
    pandas cut 的方法
    http2分片流内容整合呈现方法
    C++ 构造函数实战指南:默认构造、带参数构造、拷贝构造与移动构造
    Linux 设备模型【1】-PLATFORM(平台)总线详解
    ELementUI之CURD及表单验证
    基于SSM的医院住院管理系统的设计与实现
    C# 对RabbitMQ使用
  • 原文地址:https://blog.csdn.net/xiao_xiao3601/article/details/125605712