Skip to content

Commit

Permalink
Fallback to byte array for non-Kura body payload
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Mezzasalma <claudio.mezzasalma@eurotech.com>
  • Loading branch information
Claudio Mezzasalma authored and Coduz committed Oct 25, 2019
1 parent c6353a0 commit 3011e46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.message.internal.MessageException;
import org.eclipse.kapua.service.device.call.message.kura.data.KuraDataChannel;
import org.eclipse.kapua.service.device.call.message.kura.data.KuraDataMessage;
import org.eclipse.kapua.service.device.call.message.kura.data.KuraDataPayload;
Expand All @@ -26,7 +27,7 @@

/**
* Messages translator implementation from {@link org.eclipse.kapua.transport.message.jms.JmsMessage} to {@link org.eclipse.kapua.service.device.call.message.kura.data.KuraDataMessage}
*
*
* @since 1.0
*/
public class TranslatorDataJmsKura extends Translator<JmsMessage, KuraDataMessage> {
Expand Down Expand Up @@ -61,7 +62,11 @@ private KuraDataPayload translate(JmsPayload jmsPayload)
KuraDataPayload kuraPayload = null;
if (jmsPayload.getBody() != null) {
kuraPayload = new KuraDataPayload();
kuraPayload.readFromByteArray(jmsPayload.getBody());
try {
kuraPayload.readFromByteArray(jmsPayload.getBody());
} catch (MessageException ex) {
kuraPayload.setBody(jmsPayload.getBody());
}
}
return kuraPayload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.kapua.translator.mqtt.kura;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.message.internal.MessageException;
import org.eclipse.kapua.service.device.call.message.kura.data.KuraDataChannel;
import org.eclipse.kapua.service.device.call.message.kura.data.KuraDataMessage;
import org.eclipse.kapua.service.device.call.message.kura.data.KuraDataPayload;
Expand Down Expand Up @@ -56,10 +57,14 @@ private KuraDataChannel translate(MqttTopic mqttTopic)

private KuraDataPayload translate(MqttPayload mqttPayload)
throws KapuaException {
byte[] jmsBody = mqttPayload.getBody();
byte[] mqttBody = mqttPayload.getBody();

KuraDataPayload kuraPayload = new KuraDataPayload();
kuraPayload.readFromByteArray(jmsBody);
try {
kuraPayload.readFromByteArray(mqttBody);
} catch (MessageException ex) {
kuraPayload.setBody(mqttBody);
}

//
// Return Kura Payload
Expand Down

0 comments on commit 3011e46

Please sign in to comment.