You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/12/24 22:07:01 UTC
svn commit: r1425680 -
/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
Author: markt
Date: Mon Dec 24 21:07:01 2012
New Revision: 1425680
URL: http://svn.apache.org/viewvc?rev=1425680&view=rev
Log:
Text messages are always UTF8
(Note that even with this fix Autobahn identifies a lot of UTF-8 handling issues. The quick and dirty new String() approach needs a more robust replacement.)
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java?rev=1425680&r1=1425679&r2=1425680&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java Mon Dec 24 21:07:01 2012
@@ -18,6 +18,7 @@ package org.apache.tomcat.websocket;
import java.io.EOFException;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import javax.servlet.ServletInputStream;
@@ -282,8 +283,13 @@ public class WsFrame {
@SuppressWarnings("unchecked")
private void sendMessage(boolean last) {
if (textMessage) {
- String payload =
- new String(messageBuffer.array(), 0, messageBuffer.limit());
+ String payload = null;
+ try {
+ payload = new String(messageBuffer.array(), 0,
+ messageBuffer.limit(), "UTF8");
+ } catch (UnsupportedEncodingException e) {
+ // All JVMs must support UTF8
+ }
MessageHandler mh = wsSession.getTextMessageHandler();
if (mh != null) {
if (mh instanceof MessageHandler.Async<?>) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1425680 - /tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
Posted by Mark Thomas <ma...@apache.org>.
On 28/12/2012 00:04, Konstantin Kolinko wrote:
> Looking at the current code, "new String()" call still remains in WsFrame.java
> Starting with Line 270:
>
> if (controlBufferBinary.remaining() > 0) {
> CoderResult cr = utf8DecoderControl.decode(
> controlBufferBinary, controlBufferText, true);
> if (cr.isError()) {
> controlBufferBinary.clear();
> controlBufferText.clear();
> throw new WsIOException(new CloseReason(
> CloseCodes.PROTOCOL_ERROR,
> sm.getString("wsFrame.invalidUtf8Close")));
> }
> reason = new String(controlBufferBinary.array(),
> controlBufferBinary.arrayOffset() +
> controlBufferBinary.position(),
> controlBufferBinary.remaining(), "UTF8");
> }
>
> Why use "new String(.., UTF8)" when there is
> "utf8DecoderControl.decode(..)" call several lines above?
>
> Isn't it supposed to use controlBufferText here ?
It is. The decoder catches the encoding problems which is why the
Autobahn tests pass but I should have removed the new String() at the
same time.
I've fixed this. Thanks yet again for the review.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1425680 - /tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/12/25 <ma...@apache.org>:
> Author: markt
> Date: Mon Dec 24 21:07:01 2012
> New Revision: 1425680
>
> URL: http://svn.apache.org/viewvc?rev=1425680&view=rev
> Log:
> Text messages are always UTF8
> (Note that even with this fix Autobahn identifies a lot of UTF-8 handling issues. The quick and dirty new String() approach needs a more robust replacement.)
>
> Modified:
> tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
>
> Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java?rev=1425680&r1=1425679&r2=1425680&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java (original)
> +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java Mon Dec 24 21:07:01 2012
> @@ -18,6 +18,7 @@ package org.apache.tomcat.websocket;
>
> import java.io.EOFException;
> import java.io.IOException;
> +import java.io.UnsupportedEncodingException;
> import java.nio.ByteBuffer;
>
> import javax.servlet.ServletInputStream;
> @@ -282,8 +283,13 @@ public class WsFrame {
> @SuppressWarnings("unchecked")
> private void sendMessage(boolean last) {
> if (textMessage) {
> - String payload =
> - new String(messageBuffer.array(), 0, messageBuffer.limit());
> + String payload = null;
> + try {
> + payload = new String(messageBuffer.array(), 0,
> + messageBuffer.limit(), "UTF8");
> + } catch (UnsupportedEncodingException e) {
> + // All JVMs must support UTF8
> + }
> MessageHandler mh = wsSession.getTextMessageHandler();
> if (mh != null) {
> if (mh instanceof MessageHandler.Async<?>) {
>
Looking at the current code, "new String()" call still remains in WsFrame.java
Starting with Line 270:
if (controlBufferBinary.remaining() > 0) {
CoderResult cr = utf8DecoderControl.decode(
controlBufferBinary, controlBufferText, true);
if (cr.isError()) {
controlBufferBinary.clear();
controlBufferText.clear();
throw new WsIOException(new CloseReason(
CloseCodes.PROTOCOL_ERROR,
sm.getString("wsFrame.invalidUtf8Close")));
}
reason = new String(controlBufferBinary.array(),
controlBufferBinary.arrayOffset() +
controlBufferBinary.position(),
controlBufferBinary.remaining(), "UTF8");
}
Why use "new String(.., UTF8)" when there is
"utf8DecoderControl.decode(..)" call several lines above?
Isn't it supposed to use controlBufferText here ?
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org