From 8be61d596dfc337993770fd2212a328f4e0fec3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20J=C3=A4ckle?= Date: Fri, 3 Nov 2023 19:31:29 +0100 Subject: [PATCH] fix preserving DittoHeaders when encountering a JsonParseException * e.g. containing correlation-id, trace-context, etc. --- .../signals/commands/DevOpsErrorResponse.java | 15 +++--- .../commands/ConnectivityErrorResponse.java | 15 +++--- .../query/RetrieveConnectionsResponse.java | 3 +- .../service/mapping/CloudEventsMapper.java | 8 +-- .../service/mapping/DittoMessageMapper.java | 8 +-- ...dateTwinWithLiveResponseMessageMapper.java | 8 +-- .../javascript/DefaultIncomingMapping.java | 14 +++--- .../endpoints/routes/devops/DevOpsRoute.java | 16 +++--- .../routes/things/FeaturesRoute.java | 36 +++++++++----- .../endpoints/routes/things/ThingsRoute.java | 49 +++++++++++-------- .../signals/commands/PolicyErrorResponse.java | 3 +- .../protocol/adapter/AbstractAdapter.java | 3 +- .../adapter/DittoProtocolAdapter.java | 4 +- .../sudo/SudoRetrieveThingResponse.java | 3 +- .../sudo/SudoRetrieveThingsResponse.java | 3 +- .../signals/commands/ThingErrorResponse.java | 3 +- .../query/RetrieveThingsResponse.java | 3 +- .../signals/commands/SearchErrorResponse.java | 15 +++--- 18 files changed, 121 insertions(+), 88 deletions(-) diff --git a/base/api/src/main/java/org/eclipse/ditto/base/api/devops/signals/commands/DevOpsErrorResponse.java b/base/api/src/main/java/org/eclipse/ditto/base/api/devops/signals/commands/DevOpsErrorResponse.java index 2b09d5c79f..fda1716327 100644 --- a/base/api/src/main/java/org/eclipse/ditto/base/api/devops/signals/commands/DevOpsErrorResponse.java +++ b/base/api/src/main/java/org/eclipse/ditto/base/api/devops/signals/commands/DevOpsErrorResponse.java @@ -21,12 +21,6 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.base.model.common.HttpStatus; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException; @@ -36,6 +30,12 @@ import org.eclipse.ditto.base.model.signals.commands.AbstractCommandResponse; import org.eclipse.ditto.base.model.signals.commands.CommandResponse; import org.eclipse.ditto.base.model.signals.commands.WithEntity; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link DevOpsCommand} which wraps the exception thrown while processing the command. @@ -97,7 +97,8 @@ public static DevOpsErrorResponse of(@Nullable final String serviceName, */ public static DevOpsErrorResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { final JsonObject jsonObject = - DittoJsonException.wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); + DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (object, headers) -> JsonFactory.newObject(object)); return fromJson(jsonObject, dittoHeaders); } diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/ConnectivityErrorResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/ConnectivityErrorResponse.java index 8dfcea7111..a52549e3a2 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/ConnectivityErrorResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/ConnectivityErrorResponse.java @@ -20,12 +20,6 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonMissingFieldException; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException; import org.eclipse.ditto.base.model.headers.DittoHeaders; @@ -34,6 +28,12 @@ import org.eclipse.ditto.base.model.signals.GlobalErrorRegistry; import org.eclipse.ditto.base.model.signals.commands.AbstractErrorResponse; import org.eclipse.ditto.base.model.signals.commands.CommandResponse; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonMissingFieldException; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link ConnectivityCommand} which wraps the exception thrown when processing the command. @@ -94,7 +94,8 @@ public static ConnectivityErrorResponse of(final DittoRuntimeException dittoRunt */ public static ConnectivityErrorResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { final JsonObject jsonObject = - DittoJsonException.wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); + DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (object, headers) -> JsonFactory.newObject(object)); return fromJson(jsonObject, dittoHeaders); } diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/query/RetrieveConnectionsResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/query/RetrieveConnectionsResponse.java index 18b24f31bc..48bf2ea99f 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/query/RetrieveConnectionsResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/query/RetrieveConnectionsResponse.java @@ -172,7 +172,8 @@ public static RetrieveConnectionsResponse of(final List connections, * format. */ public static RetrieveConnectionsResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { - final JsonObject jsonObject = DittoJsonException.wrapJsonRuntimeException(() -> JsonObject.of(jsonString)); + final JsonObject jsonObject = DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (object, headers) -> JsonObject.of(object)); return fromJson(jsonObject, dittoHeaders); } diff --git a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/CloudEventsMapper.java b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/CloudEventsMapper.java index a84fecc7e4..7e72cc8e9e 100644 --- a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/CloudEventsMapper.java +++ b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/CloudEventsMapper.java @@ -23,6 +23,7 @@ import java.util.Optional; import java.util.UUID; +import org.apache.pekko.actor.ActorSystem; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.connectivity.api.ExternalMessage; @@ -37,8 +38,6 @@ import com.typesafe.config.Config; -import org.apache.pekko.actor.ActorSystem; - /** * A message mapper implementation for the Mapping incoming CloudEvents to Ditto Protocol. */ @@ -101,8 +100,9 @@ public List map(final ExternalMessage message) { final String contentType = message.findContentType().orElse(""); if (contentType.equals(DITTO_PROTOCOL_CONTENT_TYPE)) { if (isBinaryCloudEvent(message)) { - final JsonifiableAdaptable binaryAdaptable = DittoJsonException.wrapJsonRuntimeException( - () -> ProtocolFactory.jsonifiableAdaptableFromJson(newObject(payload))); + final JsonifiableAdaptable binaryAdaptable = DittoJsonException.wrapJsonRuntimeException(payload, + message.getInternalHeaders(), (thePayload, headers) -> + ProtocolFactory.jsonifiableAdaptableFromJson(newObject(thePayload))); final DittoHeaders headers = binaryAdaptable.getDittoHeaders() .toBuilder() .correlationId(message.getHeaders().get(CE_ID)) diff --git a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/DittoMessageMapper.java b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/DittoMessageMapper.java index e9edfeb3c6..6f35cf1235 100644 --- a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/DittoMessageMapper.java +++ b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/DittoMessageMapper.java @@ -16,6 +16,7 @@ import java.util.List; +import org.apache.pekko.actor.ActorSystem; import org.eclipse.ditto.base.model.common.DittoConstants; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.headers.DittoHeaders; @@ -31,8 +32,6 @@ import com.typesafe.config.Config; -import org.apache.pekko.actor.ActorSystem; - /** * A message mapper implementation for the Ditto Protocol. * Expect messages to contain a JSON serialized Ditto Protocol message. @@ -93,8 +92,9 @@ public MessageMapper createNewMapperInstance() { @Override public List map(final ExternalMessage message) { final String payload = extractPayloadAsString(message); - final JsonifiableAdaptable jsonifiableAdaptable = DittoJsonException.wrapJsonRuntimeException(() -> - ProtocolFactory.jsonifiableAdaptableFromJson(JsonFactory.newObject(payload)) + final JsonifiableAdaptable jsonifiableAdaptable = DittoJsonException.wrapJsonRuntimeException(payload, + message.getInternalHeaders(), (thePayload, headers) -> + ProtocolFactory.jsonifiableAdaptableFromJson(JsonFactory.newObject(thePayload)) ); final DittoHeaders mergedHeaders = jsonifiableAdaptable.getDittoHeaders(); diff --git a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/UpdateTwinWithLiveResponseMessageMapper.java b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/UpdateTwinWithLiveResponseMessageMapper.java index 1e07206be9..a4715f9646 100644 --- a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/UpdateTwinWithLiveResponseMessageMapper.java +++ b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/UpdateTwinWithLiveResponseMessageMapper.java @@ -22,6 +22,7 @@ import javax.annotation.Nullable; +import org.apache.pekko.actor.ActorSystem; import org.eclipse.ditto.base.model.auth.AuthorizationContext; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException; @@ -57,8 +58,6 @@ import com.typesafe.config.Config; -import org.apache.pekko.actor.ActorSystem; - /** * This mapper creates a {@link MergeThing} command when a {@link ThingQueryCommandResponse} was received via the * {@link TopicPath.Channel#LIVE live channel} patching exactly the retrieved "live" data into the twin. @@ -142,8 +141,9 @@ public List map(final ExternalMessage message) { final JsonifiableAdaptable adaptable; try { final String payload = extractPayloadAsString(message); - adaptable = DittoJsonException.wrapJsonRuntimeException(() -> - ProtocolFactory.jsonifiableAdaptableFromJson(JsonFactory.newObject(payload)) + adaptable = DittoJsonException.wrapJsonRuntimeException(payload, + message.getInternalHeaders(), (thePayload, headers) -> + ProtocolFactory.jsonifiableAdaptableFromJson(JsonFactory.newObject(thePayload)) ); } catch (final DittoRuntimeException e) { LOGGER.withCorrelationId(message.getInternalHeaders()) diff --git a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/javascript/DefaultIncomingMapping.java b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/javascript/DefaultIncomingMapping.java index 222dd3b4b7..2ed9a0d64c 100644 --- a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/javascript/DefaultIncomingMapping.java +++ b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/mapping/javascript/DefaultIncomingMapping.java @@ -17,12 +17,12 @@ import java.util.List; import java.util.Optional; +import org.eclipse.ditto.base.model.exceptions.DittoJsonException; +import org.eclipse.ditto.connectivity.api.ExternalMessage; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.protocol.Adaptable; import org.eclipse.ditto.protocol.ProtocolFactory; -import org.eclipse.ditto.connectivity.api.ExternalMessage; /** * The default mapping for incoming messages that maps messages from Ditto protocol format. @@ -40,10 +40,12 @@ static DefaultIncomingMapping get() { @Override public List apply(final ExternalMessage message) { - return DittoJsonException.wrapJsonRuntimeException(() -> getPlainStringPayload(message) - .map(JsonFactory::readFrom) - .map(JsonValue::asObject) - .map(ProtocolFactory::jsonifiableAdaptableFromJson)) + return DittoJsonException.wrapJsonRuntimeException(message, message.getInternalHeaders(), (msg, headers) -> + getPlainStringPayload(msg) + .map(JsonFactory::readFrom) + .map(JsonValue::asObject) + .map(ProtocolFactory::jsonifiableAdaptableFromJson) + ) .map(Adaptable.class::cast) .map(Collections::singletonList) .orElse(Collections.emptyList()); diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/devops/DevOpsRoute.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/devops/DevOpsRoute.java index 10588fc6a4..9cad175905 100644 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/devops/DevOpsRoute.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/devops/DevOpsRoute.java @@ -19,6 +19,11 @@ import javax.annotation.Nullable; +import org.apache.pekko.http.javadsl.model.ContentTypes; +import org.apache.pekko.http.javadsl.model.HttpResponse; +import org.apache.pekko.http.javadsl.server.PathMatchers; +import org.apache.pekko.http.javadsl.server.RequestContext; +import org.apache.pekko.http.javadsl.server.Route; import org.eclipse.ditto.base.api.common.RetrieveConfig; import org.eclipse.ditto.base.api.devops.ImmutableLoggerConfig; import org.eclipse.ditto.base.api.devops.signals.commands.ChangeLogLevel; @@ -41,12 +46,6 @@ import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.apache.pekko.http.javadsl.model.ContentTypes; -import org.apache.pekko.http.javadsl.model.HttpResponse; -import org.apache.pekko.http.javadsl.server.PathMatchers; -import org.apache.pekko.http.javadsl.server.RequestContext; -import org.apache.pekko.http.javadsl.server.Route; - /** * Builder for creating Pekko HTTP routes for {@code /devops}. */ @@ -222,8 +221,9 @@ private Route routePiggyback(final RequestContext ctx, extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, piggybackCommandJson -> { - JsonObject parsedJson = DittoJsonException.wrapJsonRuntimeException(() -> - JsonFactory.readFrom(piggybackCommandJson).asObject()); + JsonObject parsedJson = DittoJsonException.wrapJsonRuntimeException( + piggybackCommandJson, dittoHeaders, (json, headers) -> + JsonFactory.readFrom(json).asObject()); parsedJson = parsedJson.set(Command.JsonFields.TYPE, ExecutePiggybackCommand.TYPE); // serviceName and instance from URL are preferred diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/things/FeaturesRoute.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/things/FeaturesRoute.java index e0e99af972..6e62cbe65d 100755 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/things/FeaturesRoute.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/things/FeaturesRoute.java @@ -12,6 +12,9 @@ */ package org.eclipse.ditto.gateway.service.endpoints.routes.things; +import org.apache.pekko.http.javadsl.server.PathMatchers; +import org.apache.pekko.http.javadsl.server.RequestContext; +import org.apache.pekko.http.javadsl.server.Route; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.service.UriEncoding; @@ -44,10 +47,6 @@ import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatureProperty; import org.eclipse.ditto.things.model.signals.commands.query.RetrieveFeatures; -import org.apache.pekko.http.javadsl.server.PathMatchers; -import org.apache.pekko.http.javadsl.server.RequestContext; -import org.apache.pekko.http.javadsl.server.Route; - /** * Builder for creating Pekko HTTP routes for {@code /features}. */ @@ -295,10 +294,14 @@ private Route featuresEntryPropertiesEntry(final RequestContext ctx, final Ditto put(() -> ensureMediaTypeJsonWithFallbacksThenExtractDataBytes(ctx, dittoHeaders, payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, - propertyJson -> ModifyFeatureProperty.of(thingId, featureId, + propertyJson -> ModifyFeatureProperty.of(thingId, + featureId, JsonFactory.newPointer(jsonPointerString), DittoJsonException.wrapJsonRuntimeException( - () -> JsonFactory.readFrom(propertyJson)), + propertyJson, + dittoHeaders, + (json, headers) -> JsonFactory.readFrom(json) + ), dittoHeaders)) ) ), @@ -307,9 +310,13 @@ private Route featuresEntryPropertiesEntry(final RequestContext ctx, final Ditto dittoHeaders, payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, propertyJson -> MergeThing.withFeatureProperty(thingId, - featureId, JsonFactory.newPointer(jsonPointerString), + featureId, + JsonFactory.newPointer(jsonPointerString), DittoJsonException.wrapJsonRuntimeException( - () -> JsonFactory.readFrom(propertyJson)), + propertyJson, + dittoHeaders, + (json, headers) -> JsonFactory.readFrom(json) + ), dittoHeaders)) ) ), @@ -402,7 +409,10 @@ private Route featuresEntryDesiredPropertiesEntry(final RequestContext ctx, fina featureId, JsonFactory.newPointer(jsonPointerString), DittoJsonException.wrapJsonRuntimeException( - () -> JsonFactory.readFrom(propertyJson)), + propertyJson, + dittoHeaders, + (json, headers) -> JsonFactory.readFrom(json) + ), dittoHeaders)) ) ), @@ -411,9 +421,13 @@ private Route featuresEntryDesiredPropertiesEntry(final RequestContext ctx, fina dittoHeaders, payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, propertyJson -> MergeThing.withFeatureDesiredProperty(thingId, - featureId, JsonFactory.newPointer(jsonPointerString), + featureId, + JsonFactory.newPointer(jsonPointerString), DittoJsonException.wrapJsonRuntimeException( - () -> JsonFactory.readFrom(propertyJson)), + propertyJson, + dittoHeaders, + (json, headers) -> JsonFactory.readFrom(json) + ), dittoHeaders)) ) ), diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/things/ThingsRoute.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/things/ThingsRoute.java index fbec9ccca4..e40d2eeb59 100755 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/things/ThingsRoute.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/things/ThingsRoute.java @@ -23,6 +23,17 @@ import javax.annotation.Nullable; +import org.apache.pekko.http.javadsl.model.ContentTypes; +import org.apache.pekko.http.javadsl.model.HttpCharsets; +import org.apache.pekko.http.javadsl.model.HttpResponse; +import org.apache.pekko.http.javadsl.model.MediaTypes; +import org.apache.pekko.http.javadsl.model.headers.Accept; +import org.apache.pekko.http.javadsl.model.headers.Link; +import org.apache.pekko.http.javadsl.model.headers.LinkParams; +import org.apache.pekko.http.javadsl.model.headers.LinkValue; +import org.apache.pekko.http.javadsl.server.PathMatchers; +import org.apache.pekko.http.javadsl.server.RequestContext; +import org.apache.pekko.http.javadsl.server.Route; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition; import org.eclipse.ditto.base.model.headers.DittoHeaders; @@ -69,18 +80,6 @@ import org.eclipse.ditto.thingsearch.model.SearchResult; import org.eclipse.ditto.thingsearch.model.signals.commands.query.QueryThings; -import org.apache.pekko.http.javadsl.model.ContentTypes; -import org.apache.pekko.http.javadsl.model.HttpCharsets; -import org.apache.pekko.http.javadsl.model.HttpResponse; -import org.apache.pekko.http.javadsl.model.MediaTypes; -import org.apache.pekko.http.javadsl.model.headers.Accept; -import org.apache.pekko.http.javadsl.model.headers.Link; -import org.apache.pekko.http.javadsl.model.headers.LinkParams; -import org.apache.pekko.http.javadsl.model.headers.LinkValue; -import org.apache.pekko.http.javadsl.server.PathMatchers; -import org.apache.pekko.http.javadsl.server.RequestContext; -import org.apache.pekko.http.javadsl.server.Route; - /** * Builder for creating Pekko HTTP routes for {@code /things}. */ @@ -503,8 +502,11 @@ private Route thingsEntryAttributesEntry(final RequestContext ctx, final DittoHe handlePerRequest(ctx, dittoHeaders, payloadSource, attributeValueJson -> ModifyAttribute.of(thingId, JsonFactory.newPointer(jsonPointerString), - DittoJsonException.wrapJsonRuntimeException(() -> - JsonFactory.readFrom(attributeValueJson)), + DittoJsonException.wrapJsonRuntimeException( + attributeValueJson, + dittoHeaders, + (json, headers) -> JsonFactory.readFrom(json) + ), dittoHeaders)) ) ), @@ -514,8 +516,11 @@ private Route thingsEntryAttributesEntry(final RequestContext ctx, final DittoHe handlePerRequest(ctx, dittoHeaders, payloadSource, attributeValueJson -> MergeThing.withAttribute(thingId, JsonFactory.newPointer(jsonPointerString), - DittoJsonException.wrapJsonRuntimeException(() -> - JsonFactory.readFrom(attributeValueJson)), + DittoJsonException.wrapJsonRuntimeException( + attributeValueJson, + dittoHeaders, + (json, headers) -> JsonFactory.readFrom(json) + ), dittoHeaders) ) ) @@ -547,7 +552,8 @@ private Route thingsEntryDefinition(final RequestContext ctx, final DittoHeaders payloadSource -> pathEnd(() -> handlePerRequest(ctx, dittoHeaders, payloadSource, definitionJson -> ModifyThingDefinition.of(thingId, - getDefinitionFromJson(definitionJson), + getDefinitionFromJson(definitionJson, + dittoHeaders), dittoHeaders)) ) ) @@ -557,7 +563,8 @@ private Route thingsEntryDefinition(final RequestContext ctx, final DittoHeaders payloadSource -> pathEnd(() -> handlePerRequest(ctx, dittoHeaders, payloadSource, definitionJson -> MergeThing.withThingDefinition(thingId, - getDefinitionFromJson(definitionJson), dittoHeaders)) + getDefinitionFromJson(definitionJson, dittoHeaders), + dittoHeaders)) ) ) ), @@ -568,10 +575,10 @@ private Route thingsEntryDefinition(final RequestContext ctx, final DittoHeaders ); } - private ThingDefinition getDefinitionFromJson(final String definitionJson) { - return DittoJsonException.wrapJsonRuntimeException(() -> { + private ThingDefinition getDefinitionFromJson(final String definitionJson, final DittoHeaders dittoHeaders) { + return DittoJsonException.wrapJsonRuntimeException(definitionJson, dittoHeaders, (json, headers) -> { final ThingDefinition result; - final JsonValue jsonValue = JsonFactory.readFrom(definitionJson); + final JsonValue jsonValue = JsonFactory.readFrom(json); if (jsonValue.isNull()) { result = ThingsModelFactory.nullDefinition(); } else { diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/PolicyErrorResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/PolicyErrorResponse.java index 1dc06255b2..2401926111 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/PolicyErrorResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/PolicyErrorResponse.java @@ -125,7 +125,8 @@ public static PolicyErrorResponse of(final PolicyId policyId, final DittoRuntime public static PolicyErrorResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { final JsonObject jsonObject = - DittoJsonException.wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); + DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (object, headers) -> JsonFactory.newObject(object)); return fromJson(jsonObject, dittoHeaders); } diff --git a/protocol/src/main/java/org/eclipse/ditto/protocol/adapter/AbstractAdapter.java b/protocol/src/main/java/org/eclipse/ditto/protocol/adapter/AbstractAdapter.java index 34687f89b2..c5c662a3f1 100755 --- a/protocol/src/main/java/org/eclipse/ditto/protocol/adapter/AbstractAdapter.java +++ b/protocol/src/main/java/org/eclipse/ditto/protocol/adapter/AbstractAdapter.java @@ -72,7 +72,8 @@ public final T fromAdaptable(final Adaptable externalAdaptable) { final DittoHeaders filteredHeaders = filterHeadersAndAddExtraHeadersFromTopicPath(externalAdaptable); final JsonifiableMapper mapper = getJsonifiableMapperOrThrow(type, externalAdaptable, filteredHeaders); final Adaptable adaptable = externalAdaptable.setDittoHeaders(filteredHeaders); - return DittoJsonException.wrapJsonRuntimeException(() -> mapper.map(adaptable)); + return DittoJsonException.wrapJsonRuntimeException(adaptable, filteredHeaders, + (theAdaptable, headers) -> mapper.map(theAdaptable)); } /** diff --git a/protocol/src/main/java/org/eclipse/ditto/protocol/adapter/DittoProtocolAdapter.java b/protocol/src/main/java/org/eclipse/ditto/protocol/adapter/DittoProtocolAdapter.java index 4f2fa4993b..1191832c0b 100644 --- a/protocol/src/main/java/org/eclipse/ditto/protocol/adapter/DittoProtocolAdapter.java +++ b/protocol/src/main/java/org/eclipse/ditto/protocol/adapter/DittoProtocolAdapter.java @@ -139,8 +139,8 @@ static DittoProtocolAdapter newInstance(final HeaderTranslator headerTranslator, @Override public Signal fromAdaptable(final Adaptable adaptable) { final Adapter> adapter = adapterResolver.getAdapter(adaptable); - return DittoJsonException.wrapJsonRuntimeException(() -> - adapter.fromAdaptable(adapter.validateAndPreprocess(adaptable))); + return DittoJsonException.wrapJsonRuntimeException(adaptable, adaptable.getDittoHeaders(), + (theAdaptable, headers) -> adapter.fromAdaptable(adapter.validateAndPreprocess(theAdaptable))); } @Override diff --git a/things/api/src/main/java/org/eclipse/ditto/things/api/commands/sudo/SudoRetrieveThingResponse.java b/things/api/src/main/java/org/eclipse/ditto/things/api/commands/sudo/SudoRetrieveThingResponse.java index c2bc71b1b9..f65261f8a0 100755 --- a/things/api/src/main/java/org/eclipse/ditto/things/api/commands/sudo/SudoRetrieveThingResponse.java +++ b/things/api/src/main/java/org/eclipse/ditto/things/api/commands/sudo/SudoRetrieveThingResponse.java @@ -107,7 +107,8 @@ public static SudoRetrieveThingResponse of(final JsonObject thing, final DittoHe * 'SudoRetrieveThingResponse' format. */ public static SudoRetrieveThingResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { - final var jsonObject = DittoJsonException.wrapJsonRuntimeException(() -> JsonObject.of(jsonString)); + final var jsonObject = DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (string, headers) -> JsonObject.of(string)); return fromJson(jsonObject, dittoHeaders); } diff --git a/things/api/src/main/java/org/eclipse/ditto/things/api/commands/sudo/SudoRetrieveThingsResponse.java b/things/api/src/main/java/org/eclipse/ditto/things/api/commands/sudo/SudoRetrieveThingsResponse.java index 3b406a292e..0c9d688c71 100755 --- a/things/api/src/main/java/org/eclipse/ditto/things/api/commands/sudo/SudoRetrieveThingsResponse.java +++ b/things/api/src/main/java/org/eclipse/ditto/things/api/commands/sudo/SudoRetrieveThingsResponse.java @@ -199,7 +199,8 @@ public static SudoRetrieveThingsResponse of(final List things, * 'SudoRetrieveThingsResponse' format. */ public static SudoRetrieveThingsResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { - final var jsonObject = DittoJsonException.wrapJsonRuntimeException(() -> JsonObject.of(jsonString)); + final var jsonObject = DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (string, headers) -> JsonObject.of(string)); return fromJson(jsonObject, dittoHeaders); } diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/ThingErrorResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/ThingErrorResponse.java index 2c71b2f13e..510b9126b8 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/ThingErrorResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/ThingErrorResponse.java @@ -132,7 +132,8 @@ public static ThingErrorResponse of(final ThingId thingId, final DittoRuntimeExc */ public static ThingErrorResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { final JsonObject jsonObject = - DittoJsonException.wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); + DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (object, headers) -> JsonFactory.newObject(object)); return fromJson(jsonObject, dittoHeaders); } diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/query/RetrieveThingsResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/query/RetrieveThingsResponse.java index deb1667efc..00bda15f88 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/query/RetrieveThingsResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/query/RetrieveThingsResponse.java @@ -261,7 +261,8 @@ public static RetrieveThingsResponse newInstance(@Nullable final JsonArray thing * format. */ public static RetrieveThingsResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { - final JsonObject jsonObject = DittoJsonException.wrapJsonRuntimeException(() -> JsonObject.of(jsonString)); + final JsonObject jsonObject = DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (string, headers) -> JsonObject.of(string)); return fromJson(jsonObject, dittoHeaders); } diff --git a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/commands/SearchErrorResponse.java b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/commands/SearchErrorResponse.java index c53c6efbca..5b94c1f4ec 100755 --- a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/commands/SearchErrorResponse.java +++ b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/commands/SearchErrorResponse.java @@ -20,12 +20,6 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonMissingFieldException; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException; import org.eclipse.ditto.base.model.headers.DittoHeaders; @@ -33,6 +27,12 @@ import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.base.model.signals.GlobalErrorRegistry; import org.eclipse.ditto.base.model.signals.commands.AbstractErrorResponse; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonMissingFieldException; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link ThingSearchCommand} which wraps the exception thrown by SearchService when processing the @@ -81,7 +81,8 @@ public static SearchErrorResponse of(final DittoRuntimeException dittoRuntimeExc */ public static SearchErrorResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { final JsonObject jsonObject = - DittoJsonException.wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); + DittoJsonException.wrapJsonRuntimeException(jsonString, dittoHeaders, + (object, headers) -> JsonFactory.newObject(object)); return fromJson(jsonObject, dittoHeaders); }