Disable feign encoding of PathVariables

Tags: , ,



We have the following feign client

public interface MyServiceClient {

    @RequestMapping(method = RequestMethod.GET, value = "/item/{itemKey}")
    Item getItem (@PathVariable("itemKey") String itemKey);

the items can contains special characters like : or :: which are being encoded and the Request URL becomes something like https://myservice.com/item/a%3Ab%3A%3Ac rather than https://myservice.com/item/a:b::c

Can anyone help me understand how can we fix this issue?

Answer

OpenFeign has an issue tracking this https://github.com/OpenFeign/feign/issues/1190. Guess it will be implemented by spring-cloud-feign once its done.

Meanwhile, my workaround for this issue is to create a RequestInterceptor and replace %3A with :

public class MyRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        template.uri(template.path().replaceAll("%3A", ":"));
    }
}

and use this requestInterceptor to build your feignClient in the feignConfig

    @Bean
    public Feign.Builder tcsClientBuilder() {
        return Feign.builder().requestInterceptor(new MyRequestInterceptor());
    }


Source: stackoverflow