Alexander Ageychenko Alexander Ageychenko - 1 month ago 25
Android Question

Jetty WebSockets ssl == null error

I need to close connection but I get this

2016-10-28 10:46:07.624:WARN:oeji.nio:handle failed
java.lang.NullPointerException: ssl == null
at com.android.org.conscrypt.NativeCrypto.SSL_read_BIO(Native Method)
at com.android.org.conscrypt.OpenSSLEngineImpl.unwrap(OpenSSLEngineImpl.java:477)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:1014)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:536)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:678)
at org.eclipse.jetty.websocket.WebSocketParserRFC6455.parseNext(WebSocketParserRFC6455.java:181)
at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455.handle(WebSocketConnectionRFC6455.java:225)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:833)


This is my code for sockets:

private WebSocket webSocket = new WebSocket.OnTextMessage() {
@Override
public void onMessage(String data) {
//...
}

@Override
public void onOpen(Connection connection) {
//...
}

@Override
public void onClose(int closeCode, String message) {
//...
// this is called after connection.close()
}
};

WebSocketClientFactory webSocketClientFactory = new WebSocketClientFactory();
public void start(){
webSocketClientFactory.stop();
String urlConnect = "wss://test.test.com:111111/websocket";
webSocketClientFactory.setBufferSize(100000);
webSocketClientFactory.start();
WebSocketClient webSocketClient = webSocketClientFactory.newWebSocketClient();
webSocketClient.setMaxBinaryMessageSize(100000);
webSocketClient.setMaxTextMessageSize(100000);
Future<WebSocket.Connection> connectionFuture = webSocketClient.open(URI.create(urlConnect), webSocket);
}
// .......
// after some time call this
public void stop(){
try {
connection.close(); //this is going fine, error comes after
} catch (Throwable t) {
t.printStackTrace();//this not called
}
}


I can't understand what is the reason of that error and how I can fix it? I look through jetty docs and checked some thread here, but found nothing about that specific error

Answer

You have to stop the WebSocketClient.

Try this:

public void stop(){
 try {
     webSocketClient.stop();
 } catch (Throwable t) {
     t.printStackTrace();//this not called
 }
}

or

public void stop(){
 try {
     webSocketClient.stop();
     connection.close();
 } catch (Throwable t) {
     t.printStackTrace();//this not called
 }
}

Link: where I have see it

Comments