I have a very basic spring boot 3.3.6 app using spring cloud gateway to route request.
Below is the bean for configuring my routes.
@Bean
fun myRoutes(builder: RouteLocatorBuilder, openApiMap: Map<String, Map<HttpMethod, List<String>>>): RouteLocator {
val openApiMap = <map of routes. key is the path>
val routes = builder.routes()
.route { p: PredicateSpec ->
p
.path(*openApiMap.keys.toTypedArray())
.uri("https://sample-base-uri")
}
.build()
return routes
}
For local development, the base jdk image I use is arm64
based image. When I spin up I see no problems at all.
However, for remote environments, I use amd64
based image to deploy the app, and I see a weird issue when a path has got url encoded characters. This only happens in amd64
images or at least from what I could see.
For instance,
If the path is /user/1/file/-3CxBi2Z0t3GPhFXPKCnBw==
, this gets encoded as /user/1/file/-3CxBi2Z0t3GPhFXPKCnBw%253D%253D
and sent to the gateway, and assuming there is a route defined for /user/{userId}/file/{fileId}
I would expect it to work properly.
For this encoded path, gateway fails with a BAD_REQUEST
.
As I mentioned previously, this happens only when I use amd64
based jdk images and only for the routes with url encoding.
Another detail that might be helpful is that – this was working until I recently upgraded to spring boot 3.3.6
from 2.7.6
irrespective of the jdk base image type.
I tried to trouble shoot by enabling logging but there was nothing great that stood out to me as a reason.
Please let me know if you need more details on this.
Spring boot – 3.3.6
Spring dependency management version – 1.1.6
Java 17
Error Message:
[6b71b82c] Completed 400 BAD_REQUEST
2
Answers
Please find the below link for my resolution. It was definitely the double encoded path params. It is caused by the axios open api generator I was using. When I swapped out with a plain http client, I had no trouble with gateway serving my endpoint. At this stage, I haven't got the bottom of why axios generated client code is double encoding my path param. However, it was clearly the reason.
https://github.com/spring-cloud/spring-cloud-gateway/issues/3637#issuecomment-2540423503
I can infer that your
=
is getting double encoded.Check the parts of your code/compilation where it might be getting encoded twice.