7

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?

NitishDeshpande
  • 435
  • 2
  • 6
  • 19

2 Answers2

6

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.

Nikita Bosik
  • 851
  • 1
  • 14
  • 20
NitishDeshpande
  • 435
  • 2
  • 6
  • 19
  • 1
    I found the same problem. IMHO it should be a default behaviour :/ If I am passing a path argument, it should be from now on simply encoded till the end... :/ Thanks anyway for showing the solution – Tomasz Jul 23 '18 at 14:11
  • 1
    Thanks, this lead me in the right direction. In my case the FeignClient was generated by the openapi-generator so I couldn't change it straight away but I had to adapt the templates. See my answer here: https://stackoverflow.com/a/58712381/1326662 – Ralf Nov 05 '19 at 13:40
2

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.

Raba_Ababa
  • 53
  • 6