Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to byte array for non-Kura body payload #2745

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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