Skip to content

Using java.net.URI as @Param in FeignClient - expected behaviour ? #1016

Closed
@animesh1993

Description

@animesh1993

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();
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationIssues that require updates to our documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions