466618 - Partial WebSocket Text delivery does not like incomplete UTF8 sequences

+ Adding implementation of Utf8PartialBuilder to JSR356 Endpoints
This commit is contained in:
Joakim Erdfelt 2015-05-06 10:22:41 -07:00
parent 744b9e4c62
commit 8e7f05190d
2 changed files with 11 additions and 12 deletions

View File

@ -24,8 +24,8 @@ import java.nio.ByteBuffer;
import javax.websocket.MessageHandler;
import javax.websocket.MessageHandler.Partial;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.common.message.MessageAppender;
import org.eclipse.jetty.websocket.common.util.Utf8PartialBuilder;
import org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper;
/**
@ -36,19 +36,22 @@ public class TextPartialMessage implements MessageAppender
@SuppressWarnings("unused")
private final MessageHandlerWrapper msgWrapper;
private final MessageHandler.Partial<String> partialHandler;
private final Utf8PartialBuilder utf8Partial;
@SuppressWarnings("unchecked")
public TextPartialMessage(MessageHandlerWrapper wrapper)
{
this.msgWrapper = wrapper;
this.partialHandler = (Partial<String>)wrapper.getHandler();
this.utf8Partial = new Utf8PartialBuilder();
}
@Override
public void appendFrame(ByteBuffer payload, boolean isLast) throws IOException
{
String partialText = utf8Partial.toPartialString(payload);
// No decoders for Partial messages per JSR-356 (PFD1 spec)
partialHandler.onMessage(BufferUtil.toUTF8String(payload.slice()),isLast);
partialHandler.onMessage(partialText,isLast);
}
@Override

View File

@ -23,8 +23,8 @@ import java.nio.ByteBuffer;
import javax.websocket.OnMessage;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.common.message.MessageAppender;
import org.eclipse.jetty.websocket.common.util.Utf8PartialBuilder;
import org.eclipse.jetty.websocket.jsr356.endpoints.JsrAnnotatedEventDriver;
/**
@ -33,12 +33,14 @@ import org.eclipse.jetty.websocket.jsr356.endpoints.JsrAnnotatedEventDriver;
public class TextPartialOnMessage implements MessageAppender
{
private final JsrAnnotatedEventDriver driver;
private final Utf8PartialBuilder utf8Partial;
private boolean finished;
public TextPartialOnMessage(JsrAnnotatedEventDriver driver)
{
this.driver = driver;
this.finished = false;
this.utf8Partial = new Utf8PartialBuilder();
}
@Override
@ -48,15 +50,9 @@ public class TextPartialOnMessage implements MessageAppender
{
throw new IOException("Cannot append to finished buffer");
}
if (payload == null)
{
driver.onPartialTextMessage("",isLast);
}
else
{
String text = BufferUtil.toUTF8String(payload);
driver.onPartialTextMessage(text,isLast);
}
String text = utf8Partial.toPartialString(payload);
driver.onPartialTextMessage(text,isLast);
}
@Override