Skip to content

HTTP Service Interface Client doesn't work for Native Image #49274

@imaxvell

Description

@imaxvell

It appears that new http service clients are not getting proper configuration from application.properties, as a result these clients don't work at all. This happening when running Spring Boot application in Native Image mode.

For example:
we have following application.properties

spring:
  http:
    clients:
      connect-timeout: 5000
      read-timeout: 5000
    serviceclient:
      myclient:
        base-url: https://example.com

And following config for this client:

@Configuration
@ImportHttpServices(group = "myclient", types = MyClient.class)
public class RestClientsConfig {
}

Where MyClient.java is

public interface MyClient {

    @GetExchange("/hello")
    SomeResponseDto hello();
}

Now when we try to call our client myClient.hello() we'll get

This exception

java.lang.IllegalArgumentException: URI with undefined scheme
	at java.net.http@25/jdk.internal.net.http.common.Utils.newIAE(Utils.java:394)
	at java.net.http@25/jdk.internal.net.http.HttpRequestBuilderImpl.checkURI(HttpRequestBuilderImpl.java:81)
	at java.net.http@25/jdk.internal.net.http.HttpRequestBuilderImpl.uri(HttpRequestBuilderImpl.java:73)
	at java.net.http@25/jdk.internal.net.http.HttpRequestBuilderImpl.uri(HttpRequestBuilderImpl.java:45)
	at org.springframework.http.client.JdkClientHttpRequest.buildRequest(JdkClientHttpRequest.java:167)
	at org.springframework.http.client.JdkClientHttpRequest.executeInternal(JdkClientHttpRequest.java:117)
	at org.springframework.http.client.AbstractStreamingClientHttpRequest.executeInternal(AbstractStreamingClientHttpRequest.java:87)
	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:80)
	at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:609)
	at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchange(DefaultRestClient.java:567)
	at org.springframework.web.client.RestClient$RequestHeadersSpec.exchange(RestClient.java:750)
	at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.executeAndExtract(DefaultRestClient.java:908)
	at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.body(DefaultRestClient.java:831)
	at org.springframework.web.client.support.RestClientAdapter.exchangeForBody(RestClientAdapter.java:79)
	at org.springframework.web.service.invoker.HttpServiceMethod$ExchangeResponseFunction.lambda$create$4(HttpServiceMethod.java:442)
	at org.springframework.web.service.invoker.HttpServiceMethod$ExchangeResponseFunction.execute(HttpServiceMethod.java:399)
	at org.springframework.web.service.invoker.HttpServiceMethod.invoke(HttpServiceMethod.java:134)
	at org.springframework.web.service.invoker.HttpServiceProxyFactory$HttpServiceMethodInterceptor.invoke(HttpServiceProxyFactory.java:300)

I'm using Spring Boot 4.0.3 and gradle plugin org.graalvm.buildtools.native 0.11.4. Image is built by ./gradlew bootBuildImage

There is no issue when running application in standard(non-native) mode

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions