[ 
https://issues.apache.org/activemq/browse/AMQ-2684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Achim Gmeiner updated AMQ-2684:
-------------------------------

    Description: 
Non ANSI-characters sent over the websocket/stomp transport are not 
encoded/decoded correctly. In my case client and server are using UTF-8 for 
character encoding. 

Changing StompSocket.onMessage(byte frame, String data) to

  public void onMessage(byte frame, String data) {
       try {
            
protocolConverter.onStompCommand((StompFrame)wireFormat.unmarshal(new 
ByteSequence(data.getBytes("UTF-8"))));
       } catch (Exception e) {
            onException(IOExceptionSupport.create(e));
       }
   }

and StompFrame.toString() to

  public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(getAction());
        buffer.append("\n");
        Map headers = getHeaders();
        for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry)iter.next();
            buffer.append(entry.getKey());
            buffer.append(":");
            buffer.append(entry.getValue());
            buffer.append("\n");
        }
        buffer.append("\n");
        if (getContent() != null) {
            try {
                buffer.append(new String(getContent(), "UTF-8"));
            } catch (Throwable e) {
                buffer.append(Arrays.toString(getContent()));
            }
        }
        return buffer.toString();
    }

solved the problem for me. The changes are minor, I only specified the encoding 
when reading bytes arrays. 
Maybe there should be a way to configure the encoding to be used...

  was:
Non ANSI-characters sent over the websocket/stomp transport are not 
encoded/decoded correctly. In my case client and server are using UTF-8 for 
character encoding. 

Changing StompSocket.onMessage(byte frame, String data) to

  public void onMessage(byte frame, String data) {
        try {
                
protocolConverter.onStompCommand((StompFrame)wireFormat.unmarshal(new 
ByteSequence(data.getBytes("UTF-8"))));
        } catch (Exception e) {
            onException(IOExceptionSupport.create(e));
        }
    }

and StompFrame.toString() to

  public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(getAction());
        buffer.append("\n");
        Map headers = getHeaders();
        for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry)iter.next();
            buffer.append(entry.getKey());
            buffer.append(":");
            buffer.append(entry.getValue());
            buffer.append("\n");
        }
        buffer.append("\n");
        if (getContent() != null) {
            try {
                buffer.append(new String(getContent(), "UTF-8"));
            } catch (Throwable e) {
                buffer.append(Arrays.toString(getContent()));
            }
        }
        return buffer.toString();
    }

solved the problem for me. The changes are minor, I only specified the encoding 
when reading bytes arrays. 
Maybe there should be a way to configure the encoding to be used...


> Incorrect character encoding/decoding when using websocket/stomp transport
> --------------------------------------------------------------------------
>
>                 Key: AMQ-2684
>                 URL: https://issues.apache.org/activemq/browse/AMQ-2684
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 5.4.0
>         Environment: Windows 7 64bit
> Java 1.6.0_18
>            Reporter: Achim Gmeiner
>             Fix For: 5.4.0
>
>
> Non ANSI-characters sent over the websocket/stomp transport are not 
> encoded/decoded correctly. In my case client and server are using UTF-8 for 
> character encoding. 
> Changing StompSocket.onMessage(byte frame, String data) to
>   public void onMessage(byte frame, String data) {
>        try {
>             
> protocolConverter.onStompCommand((StompFrame)wireFormat.unmarshal(new 
> ByteSequence(data.getBytes("UTF-8"))));
>        } catch (Exception e) {
>             onException(IOExceptionSupport.create(e));
>        }
>    }
> and StompFrame.toString() to
>   public String toString() {
>         StringBuffer buffer = new StringBuffer();
>         buffer.append(getAction());
>         buffer.append("\n");
>         Map headers = getHeaders();
>         for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
>             Map.Entry entry = (Map.Entry)iter.next();
>             buffer.append(entry.getKey());
>             buffer.append(":");
>             buffer.append(entry.getValue());
>             buffer.append("\n");
>         }
>         buffer.append("\n");
>         if (getContent() != null) {
>             try {
>                 buffer.append(new String(getContent(), "UTF-8"));
>             } catch (Throwable e) {
>                 buffer.append(Arrays.toString(getContent()));
>             }
>         }
>         return buffer.toString();
>     }
> solved the problem for me. The changes are minor, I only specified the 
> encoding when reading bytes arrays. 
> Maybe there should be a way to configure the encoding to be used...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to