diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/EventMethod.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/EventMethod.java index 0e14c6b2976..a43bf1aff11 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/EventMethod.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/EventMethod.java @@ -113,4 +113,16 @@ public class EventMethod { return this.paramTypes; } + + public boolean isParameterPresent(Class type) + { + for (Class param : paramTypes) + { + if (param.equals(type)) + { + return true; + } + } + return false; + } } \ No newline at end of file diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/WebSocketEventDriver.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/WebSocketEventDriver.java index dc3185082f8..b7d6e57c380 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/WebSocketEventDriver.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/api/WebSocketEventDriver.java @@ -1,5 +1,8 @@ package org.eclipse.jetty.websocket.api; +import java.nio.ByteBuffer; + +import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.websocket.annotations.WebSocket; import org.eclipse.jetty.websocket.frames.BaseFrame; import org.eclipse.jetty.websocket.frames.BinaryFrame; @@ -97,7 +100,19 @@ public class WebSocketEventDriver implements Parser.Listener if ((frame instanceof BinaryFrame) && (events.onBinary != null)) { BinaryFrame bin = (BinaryFrame)frame; - events.onBinary.call(websocket,connection,bin.getPayload()); + + if (events.onBinary.isParameterPresent(ByteBuffer.class)) + { + // Byte buffer approach + events.onBinary.call(websocket,connection,bin.getPayload()); + } + else + { + // Byte array approach + byte buf[] = BufferUtil.toArray(bin.getPayload()); + events.onBinary.call(websocket,connection,buf,0,buf.length); + } + return; }