JS httpclient with java.net.ConnectException

200 views
Skip to first unread message

Seb Heymann

unread,
Oct 30, 2013, 7:33:22 AM10/30/13
to ve...@googlegroups.com
Hello,

I'm using the JS httpclient but I get a Java exception when connecting on a false address. Why don't I have a JS exception? How to catch such exception? The following code doesn't work:

var client = vertx.createHttpClient(),
client.host("localhost");
try {
        client.getNow("/", function(response) {
            console.log('Response: ' + response.statusCode());
        });
} catch(e) {
        logger.err(e);
}

I try to migrate from Node.js to Vert.x but I've found the client harder to use compared to request. Anyway Vert.x is really promising so I hope that it will continue to evolve!

Seb Heymann

unread,
Oct 30, 2013, 8:09:23 AM10/30/13
to ve...@googlegroups.com
Here is the exception raised by this code:

java.net.ConnectException: Connection refused: no further information: localhost
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
        at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocke
tChannel.java:191)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConne
ct(AbstractNioChannel.java:228)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.jav
a:497)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEve
ntLoop.java:447)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:341)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThread
EventExecutor.java:101)
        at java.lang.Thread.run(Unknown Source)
Reply all
Reply to author
Forward
0 new messages