dtracers
dtracers

Reputation: 1648

Jetty WebSocketException can not call method

I am trying to use websockets in java and I am coming across this issue:

Cannot call method public final void package.ClientWebSocket#jettyOnMessage(byte[], int, int) with args: [[B, java.lang.Integer, java.lang.Integer]

Here is the code snippet that is actually being called

 @OnWebSocketMessage
 public final void jettyOnMessage(final byte[] data, final int offset, final int length) {
     onMessage(ByteBuffer.wrap(data, offset, length));
 }

Here is there documentation that describes what the method signature should be:

 * <u>Binary Message Versions</u>
 * <ol>
 * <li><code>public void methodName(byte buf[], int offset, int length)</code></li>
 * <li><code>public void methodName({@link Session} session, byte buf[], int offset, int length)</code></li>
 * <li><code>public void methodName(InputStream stream)</code></li>
 * <li><code>public void methodName({@link Session} session, InputStream stream)</code></li>
 * </ol>
 */

As you can tell I am using the first version of the call. What am I doing wrong?

Edit1:

I made the method non final and that did not change anything.

Upvotes: 3

Views: 1392

Answers (1)

dtracers
dtracers

Reputation: 1648

I figured out the issue if anyone gets a similar exception.

The issue is that internally one of my methods throw an uncaught exception.

If you wrap your entire code in a try you can avoid this exception completely and find the real reason it is getting thrown.

Code that fixed issue:

@OnWebSocketMessage
public final void jettyOnMessage(final byte[] data, final int offset, final int length) {
    try {
        onMessage(ByteBuffer.wrap(data, offset, length));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Where the onMessage can possibly throw an exception

Im my case it ended up being an ArrayOutOfBoundsException because I was stupidly doing list.get(list.size());

Its the little things that get you.

Upvotes: 4

Related Questions