mirror of
https://github.com/jetty/jetty.project.git
synced 2025-02-28 19:09:10 +00:00
Issue #3389 - missing willDecode calls in javax.websocket
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
82cd23f4f0
commit
3bc3d7514d
@ -20,10 +20,8 @@ package org.eclipse.jetty.websocket.jsr356.annotations;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import javax.websocket.DecodeException;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.OnMessage;
|
||||
|
||||
import org.eclipse.jetty.websocket.jsr356.JsrSession;
|
||||
import org.eclipse.jetty.websocket.jsr356.annotations.Param.Role;
|
||||
@ -55,12 +53,20 @@ public class OnMessageBinaryCallable extends OnMessageCallable
|
||||
|
||||
public Object call(Object endpoint, ByteBuffer buf, boolean partialFlag) throws DecodeException
|
||||
{
|
||||
super.args[idxMessageObject] = binaryDecoder.decode(buf);
|
||||
if (idxPartialMessageFlag >= 0)
|
||||
if (binaryDecoder.willDecode(buf.slice()))
|
||||
{
|
||||
super.args[idxPartialMessageFlag] = partialFlag;
|
||||
super.args[idxMessageObject] = binaryDecoder.decode(buf);
|
||||
if (idxPartialMessageFlag >= 0)
|
||||
{
|
||||
super.args[idxPartialMessageFlag] = partialFlag;
|
||||
}
|
||||
return super.call(endpoint, super.args);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Per JSR356, if you cannot decode, discard the message.
|
||||
return null;
|
||||
}
|
||||
return super.call(endpoint,super.args);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,12 +18,9 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.jsr356.annotations;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.websocket.DecodeException;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.OnMessage;
|
||||
|
||||
import org.eclipse.jetty.websocket.jsr356.JsrSession;
|
||||
import org.eclipse.jetty.websocket.jsr356.annotations.Param.Role;
|
||||
@ -55,12 +52,20 @@ public class OnMessageTextCallable extends OnMessageCallable
|
||||
|
||||
public Object call(Object endpoint, String str, boolean partialFlag) throws DecodeException
|
||||
{
|
||||
super.args[idxMessageObject] = textDecoder.decode(str);
|
||||
if (idxPartialMessageFlag >= 0)
|
||||
if (textDecoder.willDecode(str))
|
||||
{
|
||||
super.args[idxPartialMessageFlag] = partialFlag;
|
||||
super.args[idxMessageObject] = textDecoder.decode(str);
|
||||
if (idxPartialMessageFlag >= 0)
|
||||
{
|
||||
super.args[idxPartialMessageFlag] = partialFlag;
|
||||
}
|
||||
return super.call(endpoint, super.args);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Per JSR356, if you cannot decode, discard the message.
|
||||
return null;
|
||||
}
|
||||
return super.call(endpoint,super.args);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.jsr356.messages;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import javax.websocket.DecodeException;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.Decoder.Binary;
|
||||
@ -54,14 +55,19 @@ public class BinaryWholeMessage extends SimpleBinaryMessage
|
||||
|
||||
DecoderFactory.Wrapper decoder = msgWrapper.getDecoder();
|
||||
Decoder.Binary<Object> binaryDecoder = (Binary<Object>)decoder.getDecoder();
|
||||
try
|
||||
ByteBuffer msg = BufferUtil.toBuffer(data);
|
||||
|
||||
if (binaryDecoder.willDecode(msg.slice()))
|
||||
{
|
||||
Object obj = binaryDecoder.decode(BufferUtil.toBuffer(data));
|
||||
wholeHandler.onMessage(obj);
|
||||
}
|
||||
catch (DecodeException e)
|
||||
{
|
||||
throw new WebSocketException("Unable to decode binary data",e);
|
||||
try
|
||||
{
|
||||
Object obj = binaryDecoder.decode(msg);
|
||||
wholeHandler.onMessage(obj);
|
||||
}
|
||||
catch (DecodeException e)
|
||||
{
|
||||
throw new WebSocketException("Unable to decode binary data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,14 +50,18 @@ public class TextWholeMessage extends SimpleTextMessage
|
||||
|
||||
DecoderFactory.Wrapper decoder = msgWrapper.getDecoder();
|
||||
Decoder.Text<Object> textDecoder = (Decoder.Text<Object>)decoder.getDecoder();
|
||||
try
|
||||
String msg = utf.toString();
|
||||
if (textDecoder.willDecode(msg))
|
||||
{
|
||||
Object obj = textDecoder.decode(utf.toString());
|
||||
wholeHandler.onMessage(obj);
|
||||
}
|
||||
catch (DecodeException e)
|
||||
{
|
||||
throw new WebSocketException("Unable to decode text data",e);
|
||||
try
|
||||
{
|
||||
Object obj = textDecoder.decode(msg);
|
||||
wholeHandler.onMessage(obj);
|
||||
}
|
||||
catch (DecodeException e)
|
||||
{
|
||||
throw new WebSocketException("Unable to decode text data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user