title: Setting the route programmatically in Spring Cloud Netflix Zuul
body: <p>I have created two AWS Beanstalk envs, each with their own version of the applications.  The urls for these envs are <em><a href="https://beta.myserver.com/v1073" rel="nofollow noreferrer">https://beta.myserver.com/v1073</a></em> and <em><a href="https://beta.myserver.com/v1084" rel="nofollow noreferrer">https://beta.myserver.com/v1084</a>.</em>  These urls point to the load balancer.</p>
  
  <p>Now I also have a Zuul implementation that have the following configurations. </p>
  
  <pre><code>    zuul:
        routes:
          beta:
            path: /api/**
            serviceId: beta-root
            strip-prefix: false
            sensitive-headers: Cookie,Set-Cookie
  
      ribbon:
        eureka:
          enabled: false
  
      hystrix:
        command:
          default:
            execution:
              isolation:
                thread:
                  timeoutInMilliseconds: 5000
  
      beta-root:
        ribbon:
          listOfServers: https://beta.myserver.com
  </code></pre>
  
  <p>Request for my application must have a version header.  I have a Zuul "pre" filter that inspect this header value.  The goal is to route the request based on the header value.  </p>
  
  <p>I have been able to intercept the request, but have not been able to route it from the filter.  The code snippet is below.  After running the code the request still tries to go <a href="https://beta.myserver.com/api/" rel="nofollow noreferrer">https://beta.myserver.com/api/</a>...</p>
  
  <pre><code>@Override
  public Object run() {
      /* Logic to get version header etc */
  
      /* Set the new route */
      Map&lt;String, ZuulRoute&gt; routes = zuulProps.getRoutes();
      ZuulRoute currentRoute = routes.get("beta-root");
      currentRoute.setLocation("https://beta.myserver.com/v1073");
  
      /* Refresh the route */
      routeLocator.getRoutes();
  
      logger.warn("Current Route:" + currentRoute.getLocation());
      return null;
  }
  </code></pre>
  
  <p>Any suggestion how to resolve this issue?</p>