SockJS Java Client

662 views
Skip to first unread message

Johannes Schüth

unread,
Feb 15, 2016, 4:24:51 AM2/15/16
to vert.x
Hi,

i added a SockJS eventbus bridge route to my verticle according to:


The JavaScript Client example works just fine but i want to write java unit tests in order to test my implementation. Is there a way to connect to the SockJS eventbus websocket via java?

I tried to use the vertx http client:

 HttpClient client = vertx.createHttpClient();
 client
.websocket(8080, "localhost", "/eventbus/382/149qpk4q/websocket", websocket -> {
 websocket
.handler(data -> {
 
System.out.println("Received data " + data.toString("ISO-8859-1"));
 client
.close();
 
});
 
});

But all i get is:

Received data o
10:23:11.324 [Astonished Arcanine] DEBUG [vert.x-eventloop-thread-0] [Slf4JLogger.java:71] - Encoding WebSocket Frame opCode=8 length=2
10:23:11.324 [Astonished Arcanine] DEBUG [vert.x-eventloop-thread-0] [Slf4JLogger.java:71] - Encoding WebSocket Frame opCode=8 length=2
io.netty.handler.codec.DecoderException: io.netty.util.IllegalReferenceCountException: refCnt: 0 

I assume the sockjs vertx eventbus messages are encoded in a special way? Any ideas?

- Johannes

Tim Fox

unread,
Feb 15, 2016, 4:31:05 AM2/15/16
to ve...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/ba7c8251-8049-4d89-b80e-487a33370bc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johannes Schüth

unread,
Feb 15, 2016, 4:46:42 AM2/15/16
to vert.x
Thanks!

It is now working. 

Vertx vertx = Vertx.vertx();
 
HttpClient client = vertx.createHttpClient();
 client
.websocket(8080, "localhost", "/eventbus/websocket", ws -> {


 
// Register
 
JsonObject msg = new JsonObject().put("type", "register").put("address", "some-address");
 ws
.writeFrame(io.vertx.core.http.WebSocketFrame.textFrame(msg.encode(), true));


 ws
.handler(buff -> {
 
 String str = buff.toString();
   
JsonObject received = new JsonObject(str);
   
Object rec = received.getValue("body");
   
System.out.println("Handler:" + rec.toString());
   
});
 
});
Reply all
Reply to author
Forward
0 new messages