我们有以下假装客户
public interface MyServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/item/{itemKey}")
Item getItem (@PathVariable("itemKey") String itemKey);
这些项目可以包含正在编码的特殊字符,例如:
或::
,并且请求URL变成类似于https://myservice.com/item/a%3Ab%3A%3Ac
而不是https://myservice.com/item/a:b::c
的字符
有人可以帮助我了解如何解决此问题吗?
OpenFeign跟踪此https://github.com/OpenFeign/feign/issues/1190时遇到问题。猜猜一旦完成,它将由spring-cloud-feign实现。
与此同时,我针对此问题的解决方法是创建一个RequestInterceptor并将%3A
替换为:
public class MyRequestInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate template) {
template.uri(template.path().replaceAll("%3A", ":"));
}
}
并使用此requestInterceptor在feignConfig中构建您的feignClient
@Bean
public Feign.Builder tcsClientBuilder() {
return Feign.builder().requestInterceptor(new MyRequestInterceptor());
}