You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/05/25 19:37:30 UTC
[3/3] activemq-artemis git commit: ARTEMIS-233 Convert TextMessage to
UTF8 in MQTT
ARTEMIS-233 Convert TextMessage to UTF8 in MQTT
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/e453aae5
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/e453aae5
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/e453aae5
Branch: refs/heads/master
Commit: e453aae5c951428c3a89b6442345d864dad5aaa0
Parents: 385bd04
Author: Martyn Taylor <mt...@redhat.com>
Authored: Wed May 25 20:31:13 2016 +0100
Committer: Clebert Suconic <cl...@apache.org>
Committed: Wed May 25 15:37:20 2016 -0400
----------------------------------------------------------------------
.../core/protocol/mqtt/MQTTPublishManager.java | 24 ++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e453aae5/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTPublishManager.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTPublishManager.java b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTPublishManager.java
index 93d0bd2..fc61dd9 100644
--- a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTPublishManager.java
+++ b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTPublishManager.java
@@ -17,9 +17,13 @@
package org.apache.activemq.artemis.core.protocol.mqtt;
+import java.io.UnsupportedEncodingException;
+
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.EmptyByteBuf;
import io.netty.handler.codec.mqtt.MqttMessageType;
+import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.api.core.Pair;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.core.io.IOCallback;
@@ -216,8 +220,24 @@ public class MQTTPublishManager {
private void sendServerMessage(int messageId, ServerMessageImpl message, int deliveryCount, int qos) {
String address = MQTTUtil.convertCoreAddressFilterToMQTT(message.getAddress().toString());
- ByteBuf payload = message.getBodyBufferDuplicate().byteBuf();
-
+ ByteBuf payload;
+ switch (message.getType()) {
+ case Message.TEXT_TYPE:
+ try {
+ SimpleString text = message.getBodyBuffer().readNullableSimpleString();
+ byte[] stringPayload = text.toString().getBytes("UTF-8");
+ payload = ByteBufAllocator.DEFAULT.buffer(stringPayload.length);
+ payload.writeBytes(stringPayload);
+ break;
+ }
+ catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ // Do nothing default to sending raw bytes.
+ }
+ default:
+ payload = message.getBodyBufferDuplicate().byteBuf();
+ break;
+ }
session.getProtocolHandler().send(messageId, address, qos, payload, deliveryCount);
}