码迷,mamicode.com
首页 > 其他好文 > 详细

自定义filter response 处理

时间:2019-12-17 14:56:18      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:div   esc   tostring   import   and   exce   ack   end   tco   

package com.example.apigeteway.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;

import java.util.UUID;

import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.POST_TYPE;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.SEND_RESPONSE_FILTER_ORDER;

/**
 * @Title: ResponseFilter
 * @ProjectName api-geteway
 * @date 2019/12/1714:19
 * @Desc response 处理
 */
@Component
public class ResponseFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return POST_TYPE;
    }

    @Override
    public int filterOrder() {
        return SEND_RESPONSE_FILTER_ORDER - 1;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        RequestContext requestContext = RequestContext.getCurrentContext();
        HttpServletResponse response = requestContext.getResponse();
        response.setHeader("X-Foo_AAA", UUID.randomUUID().toString());
        return null;
    }
}

  

自定义filter response 处理

标签:div   esc   tostring   import   and   exce   ack   end   tco   

原文地址:https://www.cnblogs.com/412013cl/p/12054298.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!