You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "Achim Gmeiner (JIRA)" <ji...@apache.org> on 2010/04/06 12:53:08 UTC

[jira] Reopened: (AMQ-2684) Incorrect character encoding/decoding when using websocket/stomp transport

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

Achim Gmeiner reopened AMQ-2684:
--------------------------------


I guess character encoding should also be specified for the StompFrame.getBody() method to keep everything consistent.

 StompFrame.java
{noformat}
    public String getBody() {
        try {
            return new String(content, "UTF-8");
        } catch (Throwable e) {			
            return Arrays.toString(getContent());
        }
    }
{noformat}


> 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
>            Assignee: Dejan Bosanac
>             Fix For: 5.4.0
>
>         Attachments: StompFrame.java, StompSocket.java
>
>
> 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
> {noformat}
>   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));
>        }
>    }
> {noformat}
> and StompFrame.toString() to
> {noformat}
>   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();
>     }
> {noformat}
> 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.