@Override public String getThingId() { return headers.getThingId(); }
private static Adaptable jsonifiableToAdaptable(final Jsonifiable.WithPredicate<JsonObject, JsonField> jsonifiable, final TopicPath.Channel channel, final ProtocolAdapter adapter) { final Adaptable adaptable; if (jsonifiable instanceof Command) { adaptable = adapter.toAdaptable((Command) jsonifiable, channel); } else if (jsonifiable instanceof Event) { adaptable = adapter.toAdaptable((Event) jsonifiable, channel); } else if (jsonifiable instanceof CommandResponse) { adaptable = adapter.toAdaptable((CommandResponse) jsonifiable, channel); } else if (jsonifiable instanceof DittoRuntimeException) { final DittoHeaders enhancedHeaders = ((DittoRuntimeException) jsonifiable).getDittoHeaders().toBuilder() .channel(channel.getName()) .build(); ThingErrorResponse errorResponse; try { errorResponse = ThingErrorResponse.of(MessageHeaders.of(enhancedHeaders).getThingId(), (DittoRuntimeException) jsonifiable, enhancedHeaders); } catch (final IllegalStateException | IllegalArgumentException | DittoRuntimeException e) { // thrown if headers did not contain the thing ID: errorResponse = ThingErrorResponse.of((DittoRuntimeException) jsonifiable, enhancedHeaders); } adaptable = adapter.toAdaptable(errorResponse, channel); } else { throw new IllegalArgumentException("Jsonifiable was neither Command nor CommandResponse nor" + " Event nor DittoRuntimeException: " + jsonifiable.getClass().getSimpleName()); } return adaptable; }