2

Is it possible to somehow dynamically change the value of the uri() method in spring-cloud-gateway?

I have this method:

    private <T extends RequestData> Function<PredicateSpec, Route.AsyncBuilder> walletRoute(String server, String path, String method, Class<T> inClass) {
    return r -> r.path(path)
                 .and().method(method)
                 .and().readBody(inClass, requestBody ->
                    findWalletInstanceWithUserRef(requestBody.getPlayerExternalReference()).equals(server))
                 .uri("http://" + server).id("th");
}

This method call returns the hostname I want to put inside uri():

findWalletInstanceWithUserRef(requestBody.getPlayerExternalReference())

Is it somehow possible to do that?

Thank you

C96
  • 477
  • 8
  • 33
  • 1
    not without writing another filter. The body is cached and a filter later can update the request attribute that has the target uri. – spencergibb Nov 16 '20 at 21:52
  • @spencergibb, thank you. Could you please provide an example with code? It would be really helpful. – C96 Nov 17 '20 at 15:20
  • @spencergibb even if you write a filter to mutate the request, uri is used anyway. I think that for Spring Gateway it's IMPOSSIBLE to do this simple thing. – Vinz486 May 04 '21 at 22:01
  • It's not impossible. We do it in gateway. It's a matter of ordering. – spencergibb May 04 '21 at 22:51

0 Answers0