6
votes

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?

2
I am using <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-core</artifactId> <version>9.5.0</version> </dependency> - NitishDeshpande

2 Answers

4
votes

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.

1
votes

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.