use of org.eclipse.kapua.translator.exception.TranslatorException in project kapua by eclipse.
the class TranslatorResponseMqttKura method translate.
private KuraResponseChannel translate(MqttTopic mqttTopic) throws KapuaException {
String[] mqttTopicTokens = mqttTopic.getSplittedTopic();
if (!CONTROL_MESSAGE_CLASSIFIER.equals(mqttTopicTokens[0])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_CLASSIFIER, null, mqttTopicTokens[0]);
}
KuraResponseChannel kuraResponseChannel = new KuraResponseChannel(mqttTopicTokens[0], mqttTopicTokens[1], mqttTopicTokens[2]);
kuraResponseChannel.setAppId(mqttTopicTokens[3]);
kuraResponseChannel.setReplyPart(mqttTopicTokens[4]);
kuraResponseChannel.setRequestId(mqttTopicTokens[5]);
// Return Kura Channel
return kuraResponseChannel;
}
use of org.eclipse.kapua.translator.exception.TranslatorException in project kapua by eclipse.
the class TranslatorAppBundleKuraKapua method translate.
private BundleResponsePayload translate(KuraResponsePayload kuraPayload) throws KapuaException {
BundleResponsePayload bundleResponsePayload = new BundleResponsePayload();
bundleResponsePayload.setExceptionMessage((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_MESSAGE.getValue()));
bundleResponsePayload.setExceptionStack((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_STACK.getValue()));
if (kuraPayload.getBody() != null) {
DeviceManagementSetting config = DeviceManagementSetting.getInstance();
String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING);
String body = null;
try {
body = new String(kuraPayload.getBody(), charEncoding);
} catch (Exception e) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, kuraPayload.getBody());
}
KuraBundles kuraBundles = null;
try {
kuraBundles = XmlUtil.unmarshal(body, KuraBundles.class);
} catch (Exception e) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, body);
}
translate(bundleResponsePayload, charEncoding, kuraBundles);
}
// Return Kapua Payload
return bundleResponsePayload;
}
use of org.eclipse.kapua.translator.exception.TranslatorException in project kapua by eclipse.
the class TranslatorAppBundleKuraKapua method translate.
private BundleResponseChannel translate(KuraResponseChannel kuraChannel) throws KapuaException {
if (!CONTROL_MESSAGE_CLASSIFIER.equals(kuraChannel.getMessageClassification())) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_CLASSIFIER, null, kuraChannel.getMessageClassification());
}
BundleResponseChannel bundleResponseChannel = new BundleResponseChannel();
String[] appIdTokens = kuraChannel.getAppId().split("-");
if (!BundleMetrics.APP_ID.getValue().equals(appIdTokens[0])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_NAME, null, appIdTokens[0]);
}
if (!BundleMetrics.APP_VERSION.getValue().equals(appIdTokens[1])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_VERSION, null, appIdTokens[1]);
}
bundleResponseChannel.setAppName(DeviceBundleAppProperties.APP_NAME);
bundleResponseChannel.setVersion(DeviceBundleAppProperties.APP_VERSION);
// Return Kapua Channel
return bundleResponseChannel;
}
use of org.eclipse.kapua.translator.exception.TranslatorException in project kapua by eclipse.
the class TranslatorAppCommandKuraKapua method translate.
private CommandResponseChannel translate(KuraResponseChannel kuraChannel) throws KapuaException {
if (!CONTROL_MESSAGE_CLASSIFIER.equals(kuraChannel.getMessageClassification())) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_CLASSIFIER, null, kuraChannel.getMessageClassification());
}
CommandResponseChannel kapuaChannel = new CommandResponseChannel();
String[] appIdTokens = kuraChannel.getAppId().split("-");
if (!CommandMetrics.APP_ID.getValue().equals(appIdTokens[0])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_NAME, null, appIdTokens[0]);
}
if (!CommandMetrics.APP_VERSION.getValue().equals(appIdTokens[1])) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_CHANNEL_APP_VERSION, null, appIdTokens[1]);
}
kapuaChannel.setAppName(CommandAppProperties.APP_NAME);
kapuaChannel.setVersion(CommandAppProperties.APP_VERSION);
// Return Kapua Channel
return kapuaChannel;
}
use of org.eclipse.kapua.translator.exception.TranslatorException in project kapua by eclipse.
the class TranslatorAppConfigurationKuraKapua method translate.
private ConfigurationResponsePayload translate(KuraResponsePayload kuraPayload) throws KapuaException {
ConfigurationResponsePayload configurationResponsePayload = new ConfigurationResponsePayload();
configurationResponsePayload.setExceptionMessage((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_MESSAGE.getValue()));
configurationResponsePayload.setExceptionStack((String) kuraPayload.getMetrics().get(ResponseMetrics.RESP_METRIC_EXCEPTION_STACK.getValue()));
DeviceManagementSetting config = DeviceManagementSetting.getInstance();
String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING);
if (kuraPayload.getBody() != null) {
String body = null;
try {
body = new String(kuraPayload.getBody(), charEncoding);
} catch (Exception e) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, configurationResponsePayload.getBody());
}
KuraDeviceConfiguration kuraDeviceConfiguration = null;
try {
kuraDeviceConfiguration = XmlUtil.unmarshal(body, KuraDeviceConfiguration.class);
} catch (Exception e) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, body);
}
translateBody(configurationResponsePayload, charEncoding, kuraDeviceConfiguration);
}
// Return Kapua Payload
return configurationResponsePayload;
}
Aggregations