How Zuul is request setAttribute within pre Filter

I hope to be able to perform setAttribute ("key", value) operation on request in filter of zuul, and then the downstream service can obtain data through request.getAttribute ("key"); but the result does not happen as expected. Adding attribute to request in filter is not passed to the downstream service.

/**
 * Created by zhaoyuening on 2018/1/26.
 */
@Component
public class TokenCheckFilter extends ZuulFilter {

    private final String JWT_HEADER_NAME = "token";
    private final Logger logger = LoggerFactory.getLogger(TokenCheckFilter.class);

    @Value("${token.filter}")
    private boolean IS_FILTER;

    @Autowired
    private RoleResourceManager roleResourceManager;

    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 5;
    }

    @Override
    public boolean shouldFilter() {
        if (IS_FILTER){
            logger.info("token");
        }else{
            logger.info("token");
        }
        return IS_FILTER;
    }

    //
    @Value("${root.role}")
    private String ROOT_ROLE;


    @Override
    //TODO  
    //mq 
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        String url = request.getRequestURI();
        String method = request.getMethod();

        //   
        // 0  1  2 
        Integer resourceStatus = roleResourceManager.checkStatusForResource(method, url);
        if (resourceStatus == null || resourceStatus == -1||resourceStatus == 2){
            createResponce("request fail!",ctx);
            return null;
        } else if (resourceStatus == 0){
            // 
            return null;
        }

        //jwtBeanjwt
        CodecUtils.JwtBean jwtBean = CodecUtils.JwtBean.getJwtBean(request.getHeader(JWT_HEADER_NAME));
        //request
        addRequestAttribute(jwtBean,request);
        if (jwtBean != null){
            //jwt 
            List<String> roleIdList = (List<String>) jwtBean.getPlayload(JwtFieldEnum.ROLES.getField());
            //id1 
            if (roleIdList != null && roleIdList.contains(ROOT_ROLE)){
                return null;
            }

            if (roleIdList != null && roleResourceManager.checkAuthority(method, url, roleIdList)) {
                // 
                return null;
            }
        }
        //
        //Resource
        createResponce("request fail",ctx);
        return null;
    }

    /**
     *  
     * @param msg
     * @param ctx
     */
    private void createResponce(String msg,RequestContext ctx){
        // 
        ctx.setSendZuulResponse(false);
        // 
        ctx.setResponseStatusCode(50008);
        // 
        ctx.setResponseBody(msg);
        ctx.set("isSuccess", false);
    }

    /**
     * jwtBeanrequest
     * @param jwtBean
     * @param request
     */
    private void addRequestAttribute(CodecUtils.JwtBean jwtBean,HttpServletRequest request) {
        if (jwtBean == null) {
            return;
        }
        //roles
        Object roles = jwtBean.getPlayload(JwtFieldEnum.ROLES.getField());
        Object username = jwtBean.getPlayload(JwtFieldEnum.USERNAME.getField());
        Object admin = jwtBean.getPlayload(JwtFieldEnum.ADMIN.getField());
        //save info to request
        request.setAttribute(RequestAttributeKeyEnum.ACCOUNT_ROLES.getKey(),roles);
        request.setAttribute(RequestAttributeKeyEnum.ACCOUNT_USERNAME.getKey(),username);
        request.setAttribute(RequestAttributeKeyEnum.ACCOUNT_ADMIN.getKey(),admin);

        RequestContext.getCurrentContext().setRequest(request);
    }
}

this is my custom pre filter to operate on request, which occurs in the last addRequestAttribute method. How to let the downstream receive the data I added to request in filter?

The content passed by

RequestContext-sharpaddZuulRequestHeader, is placed in the header. In this way, downstream applications can be obtained from the header. The


problem solves the problem that setAttribute simply transmits data within a single program using a request object as a carrier, and in the http specification, it will not be forwarded anywhere else. Only requestHeader can be used to transmit

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e83ef8-5bab2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e83ef8-5bab2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?