Search code examples
netflix-zuul

How to check netflix zuul is redirecting request to appropriate service


Could you please help me with the code snippet which will help to determine whether netflix zuul is redirecting request to appropriate service.

I am using spring boot & zuul 1.x.

RequestContext.getCurrentContext().getRequest().getRequestURI().toString(); gives me the url which is initiated by browser client, however I am not able to figure out how to make sure zuul is redirecting this request internally to proper service.Which will help in testing without running the actual service.

Thanks, Shekhar


Solution

  • try looking at the source code of pre-decoration filter, basically what it does is determines where and how to route based on the supplied. Also sets various proxy related headers for downstream requests

    context = RequestContext.getCurrentContext();    
    request = context.getRequest();
    

    call the getRouteHost method on context object it will give you all the route related information like protocol, host, port etc..

    RequestContext.getCurrentContext().getRouteHost();
    

    to get the uri call getRequestURI on request object

     request.getRequestURI()
    

    NOTE: the problem you might be having was the order of your filter, since preDecorationFilter has order of 5

    @Override
        public int filterOrder() {
            return PRE_DECORATION_FILTER_ORDER;
        }
    

    which is actually 5 (as far as i remember), make sure your filter order is greater than 5, i tried with filter order 7 and everything is working as expected, put your intelligence code in the run method()