websocket java.net.UnknownHostException:无法在Vertx中解析

jdgnovmf  于 2022-11-11  发布在  Java
关注(0)|答案(1)|浏览(335)

I'm establishing websocket connection, when it WS connection it is establishing, if that is WSS connection getting error.

Code:

public void start() throws Exception {
  HttpClientOptions options = new HttpClientOptions();
  options.setSsl(true);
  HttpClient client = vertx.createHttpClient(options);
  MultiMap form = MultiMap.caseInsensitiveMultiMap();
  form.set("Authorization", "bearer token");
  RequestOptions options2 = new RequestOptions()
     .setHost("somehost")
     .setPort(443)
     .setSsl(true)
     .setURI("/someuri");
  client.websocket(options2, form, (ctx) ->{
    ctx.textMessageHandler( msg -> {
      System.out.println(msg);
    }).exceptionHandler((e) -> {
      e.printStackTrace();
      client.close();
    });
  }, (exec) -> {
    exec.printStackTrace();
  });
}

pom.xml:

<dependency>
  <groupId>io.vertx</groupId>
  <artifactId>vertx-core</artifactId>
  <version>3.6.3</version>
</dependency>
<dependency>
  <groupId>io.vertx</groupId>
  <artifactId>vertx-web</artifactId>
  <version>3.6.3</version>
</dependency>

Exception:
java.net.UnknownHostException: failed to resolve 'somehost'. Exceeded max queries per resolve 4
at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:845) at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:806) at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:333) at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:322) at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:779) at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:333) at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:322) at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:779) at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:333) at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:322) at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:779) at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:333) at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:322) at io.netty.resolver.dns.DnsResolveContext.access$500(DnsResolveContext.java:62) at io.netty.resolver.dns.DnsResolveContext$3.operationComplete(DnsResolveContext.java:379) at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511) at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:504) at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:483) at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424) at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:121) at io.netty.resolver.dns.DnsQueryContext.setFailure(DnsQueryContext.java:216) at io.netty.resolver.dns.DnsQueryContext.access$300(DnsQueryContext.java:43) at io.netty.resolver.dns.DnsQueryContext$4.run(DnsQueryContext.java:166) at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38) at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:127) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:462) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748)
Caused by: io.netty.resolver.dns.DnsNameResolverTimeoutException: [/xx.xxx.xxx.xxx:xx] query timed out after 5000 milliseconds (no stack trace available)
If i used System.setProperty("vertx.disableDnsResolver", "true") connection establishing but i needed with DNS.

carvr3hs

carvr3hs1#

我也遇到过类似的问题,原因是一台机器记住了它不再连接的网络的DNS详细信息,并试图使用这些服务器作为默认服务器。这是在Windows 10 / OpenJDK 11上,过时的DNS服务器隐藏在注册表中,它们没有使用ipconfig /all显示出来。
我有一个解决方法,您可以在这里看到:
顶点HttpClient getNow无法运作
我还向Netty提出了一个问题,建议在发现默认值时过滤掉无效的DNS服务器。
https://github.com/netty/netty/issues/10264

相关问题