This is my contract,
@RequestLine("GET /products/{id}")
@Headers({"Content-Type: application/json"})
ApiResponse getProduct(@Param("id") String productId) throws Exception;
I want to fetch the product with id = "a/b",
If I send this as a param to getProduct("a/b")
then the URL that is formed is http://api/products/a/b
and I am getting a 404 instead the url should be http://api/products/a%2Fb
Is there a way around this?
A simple config did it,
@RequestLine(value = "GET /products/{id}", decodeSlash = false)
@Headers({"Content-Type: application/json"})
ApiResponse getProduct(@Param("id") String productId) throws Exception;
The path param was correctly getting encoded but the RequestTemplate was decoding the URL again (decodeSlash=true by default) before sending out the request which was causing the issue.
In my case, when code looks like this:
@GetMapping(path = "/document/{documentId}/files/{fileId}")
ResponseEntity<byte[]> getDocument(@PathVariable("documentId") String documentId, @PathVariable(value = "fileId") String fileId);
Also problem was that @PathVariable fileId
could be 123/SGINED
.
Setting application.property feign.client.decodeSlash=false
helped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With