I set "RequestContext.getCurrentContext().setRouteHost(null)" to prevent SimpleHostRoutingFilter from running, but the Filter is still working. (Rerence code : https://cloud.spring.io/spring-cloud-netflix/multi/multi__router_and_filter_zuul.html#zuul-developer-guide-sample-route-filter)
I have seen the same issues on online communities, but i haven't the solution about that anywhere.
Comment From: spencergibb
That's not enough information. What version are you using? What is your configuration? What is the order of your custom filter?
Comment From: yesesyo
@spencergibb I set "RequestContext.getCurrentContext().setRouteHost(null)" in my custom route filter(extends ZuulFilter) to route another destination instead of the original destination written in application.yml.
When RequestContext.getCurrentContext().setRouteHost(null) , I expected routing services about the original destination written in application.yml doesn't work, but the routing services are still working.
- Spring Cloud Version : Greenwich.SR2
- Spring Boot Version : 2.1.8.RELEASE
// The original destination written in application.yml
zuul:
routes:
service-a:
path: /api/**
service-b:
path: /api/**
// The custom route filter
@Override
public String filterType() {
return ROUTE_TYPE;
}
@Override
public int filterOrder() {
return SIMPLE_HOST_ROUTING_FILTER_ORDER - 1;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() throws ZuulException {
RequestContext context = RequestContext.getCurrentContext();
context.setRouteHost(null); // prevent SimpleHostRoutingFilter from running
return null;
}
Comment From: spencergibb
My guess is the ordering is wrong, can you verify that your custom filter run() is run before SimpleHostRoutingFilter.shouldFilter()
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.