Search in sources :

Example 1 with KuraBundles

use of org.eclipse.kapua.service.device.call.kura.model.bundle.KuraBundles 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;
}
Also used : KuraBundles(org.eclipse.kapua.service.device.call.kura.model.bundle.KuraBundles) BundleResponsePayload(org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponsePayload) DeviceManagementSetting(org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

KapuaException (org.eclipse.kapua.KapuaException)1 KuraBundles (org.eclipse.kapua.service.device.call.kura.model.bundle.KuraBundles)1 BundleResponsePayload (org.eclipse.kapua.service.device.management.bundle.message.internal.BundleResponsePayload)1 DeviceManagementSetting (org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1