spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

i use setRouteHost method has error #1197

Closed liutaohua closed 8 years ago

liutaohua commented 8 years ago
@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
liutaohua commented 8 years ago

@royclarkson @spencergibb can U help me ?

ryanjbaxter commented 8 years ago

Can you provide a more concrete example and description of what the problem is?

spencergibb commented 8 years ago

Closing this due to inactivity. Please re-open if there's more to discuss.