@Component
public class CustomZuulFilter extends ZuulFilter {
@Override
public boolean shouldFilter() {
return true;
}
@Override
public int filterOrder() {
return 1;
}
@Override
public String filterType() {
return "pre";
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
String url = ctx.getRequest().getRequestURI();
url = url.replaceFirst("/zuul", "");
System.out.println(url);
if (url.startsWith("/proxy")) {
// sets origin
try {
ctx.setRouteHost(new URL("http://baidu.com"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
// sets custom header to send to the origin
ctx.addOriginResponseHeader("cache-control", "max-age=3600");
} else {
ctx.set("forward.to", url);
}
return null;
}
}
com.netflix.zuul.exception.ZuulException: Filter threw Exception
Caused by: java.lang.NoSuchMethodError: com.netflix.zuul.context.RequestContext.getOriginContentLength()Ljava/lang/Long;
at org.springframework.cloud.netflix.zuul.filters.post.SendResponseFilter.addResponseHeaders(SendResponseFilter.java:209) ~[spring-cloud-netflix-core-1.1.4.RELEASE.jar:1.1.4.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.post.SendResponseFilter.run(SendResponseFilter.java:80) ~[spring-cloud-netflix-core-1.1.4.RELEASE.jar:1.1.4.RELEASE]
at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:114) ~[zuul-core-1.0.0.jar:na]
at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:175) ~[zuul-core-1.0.0.jar:na]
... 53 common frames omitted