Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
animesh1993 opened this issue Jul 24, 2019 · 3 comments
Closed
Labels
documentation Issues that require updates to our documentation

Comments

@animesh1993
Copy link

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();
	}
@kdavisk6
Copy link
Member

@animesh1993

Yes, this is expected. If the first parameter in a method signature is a URI it will be used as the base URI for the request. I've looked back over the documentation and history and it appears that this feature has been present from the beginning and is missing from the current README. We should update the documentation accordingly.

@kdavisk6 kdavisk6 added the documentation Issues that require updates to our documentation label Jul 26, 2019
@animesh1993
Copy link
Author

The issue is not only for the first parameter. Even if it's not the first parameter - it picks it up and replaces the base URI.

@kdavisk6
Copy link
Member

Closed via #1056

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues that require updates to our documentation
Projects
None yet
Development

No branches or pull requests

2 participants