Search code examples
spring-bootspring-cloudspring-cloud-gateway

Spring Gateway builds incorrect URL with query string parameters


I have a Spring gateway microservices with this mapping:

  - id: advertisementService4
    uri: lb://advertisementService
    predicates:
      - Path=/public/breeds/**
    filters:
      - RewritePath=/public/breeds/(?<segment>/?.*), /v1/public/breeds/$\{segment}

If I make a call with Postman to this url: http://192.168.99.1:8050/public/breeds/500, the gateWay service solves the mapping and build the new url in the correct way (to /v1/public/breeds/500):

enter image description here

But if I call to this url http://192.168.99.1:8050/public/breeds?petType=Dog, the gateWay service chooses the correct mapping, but it builds the url in a incorrect way:

enter image description here

The gateWay service builds http://7a32a826ec7a:8070/public/breeds?petType=Dog instead of http://7a32a826ec7a:8070/v1/public/breeds?petType=Dog (with v1 in the URL)

I don't understand why. Could you help me please?


Solution

  • I fixed it changing the RewritePath:

    from RewritePath=/public/breeds/(?/?.), /v1/public/breeds/${segment}
    to RewritePath=/(?/?.
    ), /v1/${segment}