Search code examples
javaappletwebsocketning

Websocket client doesn't work from applet


I'm using Ning http library to connect to websocket server(Weblogic 12.1.2) using this code:

WebSocket ws = new AsyncHttpClient().prepareGet(uri.toASCIIString()).execute(new WebSocketUpgradeHandler.Builder().build()).get();
ws.addWebSocketListener(this);
ws.sendTextMessage(message);

It works fine when running in the JUnit test. But when I run exactly the same code from the applet(on same PC), I get this exception:

java.util.concurrent.ExecutionException: java.io.IOException: Invalid handshake response
at com.ning.http.client.providers.netty.NettyResponseFuture.abort(NettyResponseFuture.java:324)
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.abort(NettyAsyncHttpProvider.java:1320)
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.access$800(NettyAsyncHttpProvider.java:155)
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider$WebSocketProtocol.handle(NettyAsyncHttpProvider.java:2312)
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.messageReceived(NettyAsyncHttpProvider.java:1142)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)

What can be the cause? From the wireshark I see the WebSocket version is 13 in both cases. I don't use secured ws.


Solution

  • I was running exactly the same code, but the URI was different so it didn't match the pattern on the server :( Everything works fine.