I started my test project a few weeks ago and it is coming along nicely. Today however I read something in the documentation that made me go Duh! and made me realize it is something I should have picked up from the get go.
Currently I am responding to all incoming messages on the server by using the ServerWebSocket instance directly (keeping all stored in a map for reference later by textHandlerId) and using websocket.writeFinalBinaryFrame or any other of the write methods. This works but as I now read that I can just use the eventBus for this by doing EventBus(serverWebsocket.textHandlerId,buffer)... it seems I am doing it the wrong way. Well maybe not the wrong way, but not the most efficient one.
So I tried to do exactly that and use the EventBus. Here is where I am running into an error though. For some reason incoming data, in a valid Buffer object, that I try to send out again doesn't make it past the EventBus.send validation and a ClassCastException is thrown. I also tried many different ways to actually de-serialize the incoming message, re-serialize it again and create a new Buffer.buffer(byte[]) but same result. Any ideas what might be causing this or maybe something I need to be careful for? I also tried to replace the input and just sending an empty string and that works perfectly. So its purely a casting Buffer error. What I am sending is a binary message (coming from c# client, messagePack format). But I would assume if the data passes the incoming validation, it should not have any problem making its way out again.
This is what I am left with as absolute basic test code,
Server = vertx.createHttpServer();
Server.websocketHandler(websocket -> {
websocket.handler(input -> {
vertx.eventBus().send(websocket.textHandlerID(),input);
});
});
and the error
7 24, 2015 11:43:24 午前 io.vertx.core.impl.ContextImpl
重大: Unhandled exception
java.lang.ClassCastException: io.vertx.core.buffer.impl.BufferImpl cannot be cast to java.lang.String
at io.vertx.core.http.impl.WebSocketImplBase.lambda$new$61(WebSocketImplBase.java:68)
at io.vertx.core.http.impl.WebSocketImplBase$$Lambda$31/1147788506.handle(Unknown Source)
at io.vertx.core.eventbus.impl.EventBusImpl$HandlerRegistration.handle(EventBusImpl.java:1108)
at io.vertx.core.eventbus.impl.EventBusImpl.lambda$doReceive$189(EventBusImpl.java:755)
at io.vertx.core.eventbus.impl.EventBusImpl$$Lambda$36/1112301788.handle(Unknown Source)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$15(ContextImpl.java:314)
at io.vertx.core.impl.ContextImpl$$Lambda$4/482082765.run(Unknown Source)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:357)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at java.lang.Thread.run(Thread.java:745)
Any help welcomed.