Reputation: 4334
I am trying to consume a REST API using vertx and rx java, below is my code
import io.vertx.rxjava.core.buffer.Buffer;
import io.vertx.rxjava.ext.web.client.HttpResponse;
import rx.Single;
public Single<HttpResponse<Buffer>> getLanguages() {
WebClientOptions options = new WebClientOptions().setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.82 Safari/537.36");
WebClient client = WebClient.create(Vertx.vertx(), options);
Single<HttpResponse<Buffer>> single = client
.get("time.jsontest.com", "/")
.rxSend();
return single;
}
And my subscriber code in the main class is
public static void main(String[] args) {
Single<HttpResponse<Buffer>> single = new ITAPILanguagesImpl().getLanguages();
single.subscribe(response -> {
System.out.println("Received 1st response with status code" + response.statusCode());
}, error -> {
System.out.println("Something went wrong " + error.getMessage());
});
}
When I run the main method I get the following error
Jun 06, 2017 9:48:32 PM io.netty.resolver.dns.DnsNameResolver trySuccess
Something went wrong Network is unreachable: no further information: time.jsontest.com/2404:6800:4007:807:0:0:0:2013:80
WARNING: Failed to notify success (time.jsontest.com/2404:6800:4007:807:0:0:0:2013) to a promise: DefaultPromise@5dcb32d8(success: time.jsontest.com/2404:6800:4007:807:0:0:0:2013)
I checked the url and it is working fine, only when I connect to this url using vertx webclient I get this error, what am I missing? I have added the following artifacts as dependencies in the pom file.
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-rx-java</artifactId>
<version>3.4.1</version>
</dependency>
Thanks!
Upvotes: 2
Views: 1603
Reputation: 9128
It looks like a DNS problem in your environment.
Try switching to the JVM built-in resolver by adding this system property on the command line:
-Dvertx.disableDnsResolver=true
By the way, creating a Vert.x instance and a Web Client anytime you invoke your method is a bad practice. You should reuse a single instance of both.
Upvotes: 2