自定义filter response 处理
Posted 412013cl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义filter response 处理相关的知识,希望对你有一定的参考价值。
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 处理的主要内容,如果未能解决你的问题,请参考以下文章