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

$ expression in @Client annotation is not resolved when injecting low level http client. #1144

Closed
KrzysztofKowalczyk opened this issue Jan 20, 2019 · 0 comments
Assignees
Labels
status: pr submitted A pull request has been submitted for the issue type: bug Something isn't working
Milestone

Comments

@KrzysztofKowalczyk
Copy link
Contributor

KrzysztofKowalczyk commented Jan 20, 2019

Expression in Client annotation is not resolved and instead treated in whole as a service id.

Steps to Reproduce

Create a bean and inject http client using an expression in Client annotation. Example:

public class LowLevelClient {

    @Inject @Client("${foo.bar}") // <-- this cause problem during injection
    RxHttpClient client;

    public String hello() {
        HttpRequest<?> req = HttpRequest.GET("/");
        return client.exchange(req, String.class).blockingFirst().body();
    }
}

Expected Behaviour

Expression should be resolved and the resolved value should be used as an URI.
Declarative client like the one below works fine.

@Client("${foo.bar}")
public interface DeclarativeClient {

  @Get
  String hello();
}

Actual Behaviour

Expression is not resolved and it is used as service id instead. This is shown by exception:

No available services for ID: ${foo.bar}
io.micronaut.discovery.exceptions.NoAvailableServiceException: No available services for ID: ${foo.bar}
	at io.micronaut.http.client.loadbalance.AbstractRoundRobinLoadBalancer.getNextAvailable(AbstractRoundRobinLoadBalancer.java:51)
	at io.micronaut.core.async.publisher.Publishers$1.doOnNext(Publishers.java:139)
[...]

Environment Information

  • Micronaut 1.0.3

Example Application

https://github.com/KrzysztofKowalczyk/micronaut-problems

Test case:
https://github.com/KrzysztofKowalczyk/micronaut-problems/blob/master/src/test/groovy/micronaut/problems/ClientSpec.groovy

Second test is failing

Workaround

  1. Use declarative Client
  2. Use service id and configure url there
micronaut:
    http:
        services:
            foobar:
                url: 'http://localhost:8080’
  1. Setup client manually
public class LowLevelClient {
    RxHttpClient client;

    @PostConstruct
    void initialize() {
        Optional<String> value = applicationContext.getProperty("foo.bar", String.class);
        if (value.isEmpty()) {
            throw new ConfigurationException("foo.bar is not configured");
        }
        try {
            client = RxHttpClient.create(new URL(value.get()));
        } catch (MalformedURLException e) {
            throw new ConfigurationException("Http client could not be created");
        }
    }
[...]
@graemerocher graemerocher added the type: bug Something isn't working label Jan 21, 2019
@jameskleeh jameskleeh self-assigned this Jan 22, 2019
jameskleeh added a commit that referenced this issue Jan 23, 2019
…resolution for fields and method arguments. Fixes #1144
@jameskleeh jameskleeh added the status: pr submitted A pull request has been submitted for the issue label Jan 23, 2019
graemerocher pushed a commit that referenced this issue Jan 23, 2019
…resolution for fields and method arguments. Fixes #1144 (#1158)
@graemerocher graemerocher added this to the 1.0.4 milestone Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pr submitted A pull request has been submitted for the issue type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants