Description
When using a URI object as a param in a FeignClient - the URI object replaces the base url instead of correctly doing param expansion.
Example :
@FeignClient(value = "gateway", url = "${clients.gateway.endpoint}")
public interface GatewayClient {
@RequestLine("POST /gateway/testWithString")
@Headers({
"forwardUrl: {url}"
})
public Response sendMessageToGatewayString(@Param("url") String url) ;
@RequestLine("POST /gateway/testWithURI")
@Headers({
"forwardUrl: {url}"
})
public Response sendMessageToGatewayUri(@Param("url") URI url) ;
}
Test Case :
@RunWith(SpringRunner.class)
@SpringBootTest
public class GatewayClientTest {
@Autowired
GatewayClient gatewayClient ;
@Test
public void sendMessageToGatewayString() {
gatewayClient.sendMessageToGatewayString("http://foobar/inputURI") ;
}
@Test
public void sendMessageToGatewayUri() throws URISyntaxException {
gatewayClient.sendMessageToGatewayUri(new URI("http://foobar/inputURI")) ;
}
}
Relevant Output / Logs :
sendMessageToGatewayUri :
feign.RetryableException: foobar executing POST http://foobar/inputURI/gateway/testWithURI
sendMessageToGatewayString :
feign.RetryableException: Connection refused (Connection refused) executing POST http://localhost/gateway/testWithString
Question
As you can see from the above, the sendMessageToGatewayString works as expected, however sendMessageToGateUri takes the input URI and prepends it to the path of the method ( Essentially making it the baseURL and adding RequestLine path to it ) - Is this expected behaviour ?
Side Note:
Version Used : 'org.springframework.cloud:spring-cloud-openfeign-core:2.1.1.RELEASE'
I understand to use Spring Boot Feign annotations, however I have certain use cases such as HeaderMap and ParamMap which I wasn't able to properly decipher in Spring Boot Feign.
Making feign annotations work by using the underlying codeblock :
@Bean
public Contract useFeignAnnotations() {
return new Contract.Default();
}