diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/JsrAnnotatedEventDriver.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/JsrAnnotatedEventDriver.java index 316031938e5..23a1344a6b2 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/JsrAnnotatedEventDriver.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/JsrAnnotatedEventDriver.java @@ -116,7 +116,23 @@ public class JsrAnnotatedEventDriver extends AbstractEventDriver implements Even if (activeMessage == null) { LOG.debug("Binary Message InputStream"); - activeMessage = new MessageInputStream(this); + final MessageInputStream stream = new MessageInputStream(session.getConnection()); + activeMessage = stream; + dispatch(new Runnable() + { + @Override + public void run() + { + try + { + events.callBinaryStream(websocket,stream); + } + catch (DecodeException | IOException e) + { + onFatalError(e); + } + } + }); } } @@ -264,7 +280,25 @@ public class JsrAnnotatedEventDriver extends AbstractEventDriver implements Even if (activeMessage == null) { LOG.debug("Text Message Writer"); - activeMessage = new MessageReader(this); + + final MessageReader stream = new MessageReader(new MessageInputStream(session.getConnection())); + activeMessage = stream; + + dispatch(new Runnable() + { + @Override + public void run() + { + try + { + events.callTextStream(websocket,stream); + } + catch (DecodeException | IOException e) + { + onFatalError(e); + } + } + }); } } diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/JsrEndpointEventDriver.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/JsrEndpointEventDriver.java index 315e29d9d90..b252ba8ec41 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/JsrEndpointEventDriver.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/endpoints/JsrEndpointEventDriver.java @@ -29,6 +29,8 @@ import javax.websocket.CloseReason.CloseCodes; import javax.websocket.DeploymentException; import javax.websocket.Endpoint; import javax.websocket.EndpointConfig; +import javax.websocket.MessageHandler; +import javax.websocket.MessageHandler.Whole; import javax.websocket.Session; import org.eclipse.jetty.util.log.Log; @@ -40,18 +42,18 @@ import org.eclipse.jetty.websocket.common.CloseInfo; import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.events.AbstractEventDriver; import org.eclipse.jetty.websocket.common.events.EventDriver; +import org.eclipse.jetty.websocket.common.message.MessageInputStream; +import org.eclipse.jetty.websocket.common.message.MessageReader; import org.eclipse.jetty.websocket.jsr356.ContainerService; import org.eclipse.jetty.websocket.jsr356.Decoders; import org.eclipse.jetty.websocket.jsr356.JsrSession; import org.eclipse.jetty.websocket.jsr356.MessageHandlers; import org.eclipse.jetty.websocket.jsr356.MessageType; import org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialMessage; -import org.eclipse.jetty.websocket.jsr356.messages.BinaryStreamMessage; import org.eclipse.jetty.websocket.jsr356.messages.BinaryWholeMessage; import org.eclipse.jetty.websocket.jsr356.messages.MessageHandlerMetadataFactory; import org.eclipse.jetty.websocket.jsr356.messages.MessageHandlerWrapper; import org.eclipse.jetty.websocket.jsr356.messages.TextPartialMessage; -import org.eclipse.jetty.websocket.jsr356.messages.TextStreamMessage; import org.eclipse.jetty.websocket.jsr356.messages.TextWholeMessage; /** @@ -88,7 +90,7 @@ public class JsrEndpointEventDriver extends AbstractEventDriver implements Event { if (activeMessage == null) { - MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.BINARY); + final MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.BINARY); if (wrapper == null) { LOG.debug("No BINARY MessageHandler declared"); @@ -100,7 +102,18 @@ public class JsrEndpointEventDriver extends AbstractEventDriver implements Event } else if (wrapper.wantsStreams()) { - activeMessage = new BinaryStreamMessage(this,wrapper); + final MessageInputStream stream = new MessageInputStream(session.getConnection()); + activeMessage = stream; + dispatch(new Runnable() + { + @SuppressWarnings("unchecked") + @Override + public void run() + { + MessageHandler.Whole handler = (Whole)wrapper.getHandler(); + handler.onMessage(stream); + } + }); } else { @@ -181,7 +194,7 @@ public class JsrEndpointEventDriver extends AbstractEventDriver implements Event { if (activeMessage == null) { - MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.TEXT); + final MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.TEXT); if (wrapper == null) { LOG.debug("No TEXT MessageHandler declared"); @@ -193,7 +206,19 @@ public class JsrEndpointEventDriver extends AbstractEventDriver implements Event } else if (wrapper.wantsStreams()) { - activeMessage = new TextStreamMessage(this,wrapper); + final MessageReader stream = new MessageReader(new MessageInputStream(session.getConnection())); + activeMessage = stream; + + dispatch(new Runnable() + { + @SuppressWarnings("unchecked") + @Override + public void run() + { + MessageHandler.Whole handler = (Whole)wrapper.getHandler(); + handler.onMessage(stream); + } + }); } else { diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/BinaryStreamMessage.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/BinaryStreamMessage.java deleted file mode 100644 index 3ff12421560..00000000000 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/BinaryStreamMessage.java +++ /dev/null @@ -1,41 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.websocket.jsr356.messages; - -import java.io.InputStream; - -import javax.websocket.MessageHandler; -import javax.websocket.MessageHandler.Whole; - -import org.eclipse.jetty.websocket.common.events.EventDriver; -import org.eclipse.jetty.websocket.common.message.MessageInputStream; - -public class BinaryStreamMessage extends MessageInputStream -{ - private final MessageHandlerWrapper msgWrapper; - private final MessageHandler.Whole streamHandler; - - @SuppressWarnings("unchecked") - public BinaryStreamMessage(EventDriver driver, MessageHandlerWrapper wrapper) - { - super(driver); - this.msgWrapper = wrapper; - this.streamHandler = (Whole)wrapper.getHandler(); - } -} diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/TextStreamMessage.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/TextStreamMessage.java deleted file mode 100644 index 3ef34778c2f..00000000000 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/TextStreamMessage.java +++ /dev/null @@ -1,41 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.websocket.jsr356.messages; - -import java.io.Reader; - -import javax.websocket.MessageHandler; -import javax.websocket.MessageHandler.Whole; - -import org.eclipse.jetty.websocket.common.events.EventDriver; -import org.eclipse.jetty.websocket.common.message.MessageReader; - -public class TextStreamMessage extends MessageReader -{ - private final MessageHandlerWrapper msgWrapper; - private final MessageHandler.Whole streamHandler; - - @SuppressWarnings("unchecked") - public TextStreamMessage(EventDriver driver, MessageHandlerWrapper wrapper) - { - super(driver); - this.msgWrapper = wrapper; - this.streamHandler = (Whole)wrapper.getHandler(); - } -} diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java index 0848e119100..db8d38192c7 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/AbstractEventDriver.java @@ -65,6 +65,11 @@ public abstract class AbstractEventDriver implements IncomingFrames, EventDriver } } + protected void dispatch(Runnable runnable) + { + session.dispatch(runnable); + } + @Override public WebSocketPolicy getPolicy() { diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyAnnotatedEventDriver.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyAnnotatedEventDriver.java index 539e4e8bb14..5eb16c04c7d 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyAnnotatedEventDriver.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyAnnotatedEventDriver.java @@ -65,11 +65,6 @@ public class JettyAnnotatedEventDriver extends AbstractEventDriver } } - private void dispatch(Runnable runnable) - { - session.dispatch(runnable); - } - @Override public void onBinaryFrame(ByteBuffer buffer, boolean fin) throws IOException {