Skip to content

Commit

Permalink
Issue #792: fixed merging of "best effort headers" with already exist…
Browse files Browse the repository at this point in the history
…ing DittoHeaders

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Oct 22, 2020
1 parent 13c0aa9 commit 3bdcff4
Showing 1 changed file with 12 additions and 3 deletions.
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.ditto.model.base.headers.DittoHeaders;
import org.eclipse.ditto.model.base.headers.DittoHeadersBuilder;
import org.eclipse.ditto.model.base.headers.DittoHeadersSizeChecker;
import org.eclipse.ditto.model.base.headers.WithDittoHeaders;
import org.eclipse.ditto.model.connectivity.ConnectionId;
import org.eclipse.ditto.model.connectivity.ConnectionType;
import org.eclipse.ditto.model.connectivity.PayloadMappingDefinition;
Expand Down Expand Up @@ -217,16 +218,24 @@ private DittoHeaders resolveDittoHeadersBestEffort(final ExternalMessage message
}

private static DittoRuntimeException toDittoRuntimeException(final Throwable error, final MessageMapper mapper,
final DittoHeaders bestTryHeaders,
final DittoHeaders bestEffortHeaders,
final ExternalMessage message) {
final DittoRuntimeException dittoRuntimeException = DittoRuntimeException.asDittoRuntimeException(error, e ->
buildMappingFailedException("inbound",
message.findContentType().orElse(""),
mapper.getId(),
bestTryHeaders,
bestEffortHeaders,
e)
);
return dittoRuntimeException.setDittoHeaders(bestTryHeaders);

if (error instanceof WithDittoHeaders) {
final DittoHeaders existingHeaders = ((WithDittoHeaders<?>) error).getDittoHeaders();
final DittoHeaders mergedHeaders = bestEffortHeaders.toBuilder().putHeaders(existingHeaders)
.build();
return dittoRuntimeException.setDittoHeaders(mergedHeaders);
} else {
return dittoRuntimeException.setDittoHeaders(bestEffortHeaders);
}
}

private static boolean shouldMapMessageByContentType(final ExternalMessage message, final MessageMapper mapper) {
Expand Down

0 comments on commit 3bdcff4

Please sign in to comment.