From 1d15334de466fd7e3d89563edc046730334074fd Mon Sep 17 00:00:00 2001 From: Enrico Risa Date: Mon, 20 Jan 2025 13:49:40 +0100 Subject: [PATCH] fix: add lazy fetch for JSON-LD ObjectMapper --- .../edc/jsonld/util/JacksonJsonLd.java | 1 + ...bjectFromDataAddressDspaceTransformer.java | 13 +- ...tFromDataAddressDspace2024Transformer.java | 13 +- .../JsonObjectFromCriterionTransformer.java | 10 +- ...bjectFromDataPlaneInstanceTransformer.java | 9 +- ...ectFromDataPlaneInstanceV3Transformer.java | 9 +- .../to/JsonValueToGenericTypeTransformer.java | 10 +- ...tFromDataAddressDspaceTransformerTest.java | 2 +- ...mDataAddressDspace2024TransformerTest.java | 2 +- ...sonObjectFromCriterionTransformerTest.java | 2 +- ...tFromDataPlaneInstanceTransformerTest.java | 4 +- ...romDataPlaneInstanceV3TransformerTest.java | 4 +- .../JsonObjectToCriterionTransformerTest.java | 4 +- ...sonObjectToDataAddressTransformerTest.java | 4 +- ...ValueToGenericPropertyTransformerTest.java | 2 +- .../from/JsonObjectFromAssetTransformer.java | 12 +- .../JsonObjectFromAssetTransformerTest.java | 4 +- .../to/JsonObjectToAssetTransformerTest.java | 5 +- .../http/api/DspCatalogApiExtension.java | 9 +- .../DspCatalogTransformExtension.java | 25 ++-- .../Base64ContinuationTokenSerDesTest.java | 4 +- .../JsonObjectFromCatalogTransformer.java | 15 +-- .../JsonObjectFromDatasetTransformer.java | 10 +- ...JsonObjectFromCatalogV2024Transformer.java | 15 +-- .../JsonObjectFromCatalogTransformerTest.java | 2 +- .../JsonObjectFromDatasetTransformerTest.java | 2 +- ...ObjectFromCatalogV2024TransformerTest.java | 2 +- .../DspApiConfigurationExtension.java | 35 +++--- .../dsp/http/DspHttpCoreExtension.java | 2 +- .../JsonLdRemoteMessageSerializerImpl.java | 10 +- .../JsonLdResponseBodyDeserializer.java | 9 +- ...JsonLdRemoteMessageSerializerImplTest.java | 2 +- .../JsonLdResponseBodyDeserializerTest.java | 2 +- .../http/api/DspNegotiationApiExtension.java | 9 +- ...DspNegotiationHttpDispatcherExtension.java | 2 +- .../api/DspTransferProcessApiExtension.java | 9 +- ...DspTransferProcessDispatcherExtension.java | 2 +- .../DspTransferProcessTransformExtension.java | 11 +- ...oTransferSuspensionMessageTransformer.java | 13 +- ...nsferSuspensionMessageTransformerTest.java | 2 +- .../edc/api/model/ApiCoreSchemaTest.java | 2 +- ...bjectToCallbackAddressTransformerTest.java | 4 +- .../ControlApiConfigurationExtension.java | 10 +- .../schema/ManagementApiSchemaTest.java | 2 +- .../ManagementApiConfigurationExtension.java | 14 ++- .../jwt/JwtPresentationVerifier.java | 9 +- .../jwt/JwtPresentationVerifierTest.java | 2 +- .../linkeddata/LdpVerifier.java | 13 +- .../linkeddata/LdpVerifierTest.java | 2 +- .../edc/web/jersey/JerseyRestService.java | 2 +- .../testfixtures/RestControllerTestBase.java | 2 +- .../jsonld/JerseyJsonLdInterceptor.java | 11 +- .../jsonld/ObjectMapperProvider.java | 10 +- .../jsonld/JerseyJsonLdInterceptorTest.java | 2 +- .../core/IdentityAndTrustExtension.java | 30 ++--- .../core/IdentityTrustTransformExtension.java | 9 +- .../DefaultCredentialServiceClient.java | 14 +-- .../DefaultCredentialServiceClientTest.java | 115 +++++++++--------- .../MultiFormatPresentationVerifierTest.java | 4 +- ...nObjectToPresentationQueryTransformer.java | 9 +- ...resentationResponseMessageTransformer.java | 12 +- ...wtToVerifiablePresentationTransformer.java | 11 +- .../PresentationResponseMessageSerdeTest.java | 4 +- ...esentationQueryMessageTransformerTest.java | 4 +- ...ntationResponseMessageTransformerTest.java | 4 +- ...ToVerifiableCredentialTransformerTest.java | 2 +- ...VerifiablePresentationTransformerTest.java | 2 +- ...VerifiablePresentationTransformerTest.java | 2 +- .../api/management/asset/v3/AssetApiTest.java | 2 +- .../ContractDefinitionApiExtension.java | 3 +- ...jectFromContractDefinitionTransformer.java | 10 +- ...FromContractDefinitionTransformerTest.java | 4 +- .../policy/PolicyDefinitionApiExtension.java | 3 +- ...ObjectFromPolicyDefinitionTransformer.java | 10 +- ...ctFromPolicyDefinitionTransformerTest.java | 4 +- .../api/management/secret/SecretsApiTest.java | 2 +- .../TransferProcessApiTest.java | 2 +- .../DataPlaneSelectorApiExtension.java | 7 +- .../api/v3/DataPlaneApiSelectorV3Test.java | 2 +- .../api/v4/DataPlaneApiSelectorV4Test.java | 2 +- .../DataPlaneSelectorClientExtension.java | 11 +- .../RemoteDataPlaneSelectorService.java | 11 +- .../DataplaneSelectorControlApiExtension.java | 8 +- .../api/DataPlaneSignalingApiExtension.java | 6 +- .../client/DataPlaneSignalingClient.java | 11 +- .../DataPlaneSignalingClientExtension.java | 3 +- ...laneSignalingClientTransformExtension.java | 8 +- .../client/DataPlaneSignalingClientTest.java | 12 +- ...ctFromDataFlowStartMessageTransformer.java | 10 +- ...omDataFlowStartMessageTransformerTest.java | 4 +- .../DataPlaneSignalingApiEndToEndTest.java | 4 +- 91 files changed, 406 insertions(+), 342 deletions(-) diff --git a/core/common/lib/json-ld-lib/src/main/java/org/eclipse/edc/jsonld/util/JacksonJsonLd.java b/core/common/lib/json-ld-lib/src/main/java/org/eclipse/edc/jsonld/util/JacksonJsonLd.java index fd5a66aa8be..387d9c636e7 100644 --- a/core/common/lib/json-ld-lib/src/main/java/org/eclipse/edc/jsonld/util/JacksonJsonLd.java +++ b/core/common/lib/json-ld-lib/src/main/java/org/eclipse/edc/jsonld/util/JacksonJsonLd.java @@ -36,6 +36,7 @@ public void setupModule(SetupContext context) { } }; mapper.registerModule(module); + mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); return mapper; } } diff --git a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/dspace/from/JsonObjectFromDataAddressDspaceTransformer.java b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/dspace/from/JsonObjectFromDataAddressDspaceTransformer.java index fea00c3fdd8..09bca17822e 100644 --- a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/dspace/from/JsonObjectFromDataAddressDspaceTransformer.java +++ b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/dspace/from/JsonObjectFromDataAddressDspaceTransformer.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Set; +import java.util.function.Supplier; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA; @@ -41,16 +42,16 @@ public class JsonObjectFromDataAddressDspaceTransformer extends AbstractNamespac private static final Set EXCLUDED_PROPERTIES = Set.of(EDC_DATA_ADDRESS_TYPE_PROPERTY); private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonObjectFromDataAddressDspaceTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { - this(jsonFactory, mapper, new JsonLdNamespace(DSPACE_SCHEMA)); + public JsonObjectFromDataAddressDspaceTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { + this(jsonFactory, objectMapperSupplier, new JsonLdNamespace(DSPACE_SCHEMA)); } - public JsonObjectFromDataAddressDspaceTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, JsonLdNamespace namespace) { + public JsonObjectFromDataAddressDspaceTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier, JsonLdNamespace namespace) { super(DataAddress.class, JsonObject.class, namespace); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -75,7 +76,7 @@ private JsonObject endpointProperty(String key, Object value) { if (value instanceof String stringVal) { builder.add(forNamespace(ENDPOINT_PROPERTY_VALUE_PROPERTY_TERM), stringVal); } else { - builder.add(forNamespace(ENDPOINT_PROPERTY_VALUE_PROPERTY_TERM), mapper.convertValue(value, JsonObject.class)); + builder.add(forNamespace(ENDPOINT_PROPERTY_VALUE_PROPERTY_TERM), objectMapperSupplier.get().convertValue(value, JsonObject.class)); } return builder.build(); diff --git a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/dspace/v2024/from/JsonObjectFromDataAddressDspace2024Transformer.java b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/dspace/v2024/from/JsonObjectFromDataAddressDspace2024Transformer.java index f96849507df..1fcf1c5cbe2 100644 --- a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/dspace/v2024/from/JsonObjectFromDataAddressDspace2024Transformer.java +++ b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/dspace/v2024/from/JsonObjectFromDataAddressDspace2024Transformer.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Set; +import java.util.function.Supplier; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA_2024_1; @@ -41,16 +42,16 @@ public class JsonObjectFromDataAddressDspace2024Transformer extends AbstractName private static final Set EXCLUDED_PROPERTIES = Set.of(EDC_DATA_ADDRESS_TYPE_PROPERTY); private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonObjectFromDataAddressDspace2024Transformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { - this(jsonFactory, mapper, new JsonLdNamespace(DSPACE_SCHEMA_2024_1)); + public JsonObjectFromDataAddressDspace2024Transformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { + this(jsonFactory, objectMapperSupplier, new JsonLdNamespace(DSPACE_SCHEMA_2024_1)); } - public JsonObjectFromDataAddressDspace2024Transformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, JsonLdNamespace namespace) { + public JsonObjectFromDataAddressDspace2024Transformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier, JsonLdNamespace namespace) { super(DataAddress.class, JsonObject.class, namespace); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -75,7 +76,7 @@ private JsonObject endpointProperty(String key, Object value) { if (value instanceof String stringVal) { builder.add(forNamespace(ENDPOINT_PROPERTY_VALUE_PROPERTY_TERM), stringVal); } else { - builder.add(forNamespace(ENDPOINT_PROPERTY_VALUE_PROPERTY_TERM), mapper.convertValue(value, JsonObject.class)); + builder.add(forNamespace(ENDPOINT_PROPERTY_VALUE_PROPERTY_TERM), objectMapperSupplier.get().convertValue(value, JsonObject.class)); } return builder.build(); diff --git a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromCriterionTransformer.java b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromCriterionTransformer.java index 45d0ba54037..4e001e41e38 100644 --- a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromCriterionTransformer.java +++ b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromCriterionTransformer.java @@ -25,17 +25,19 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Supplier; + import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; public class JsonObjectFromCriterionTransformer extends AbstractJsonLdTransformer { private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonObjectFromCriterionTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { + public JsonObjectFromCriterionTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { super(Criterion.class, JsonObject.class); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -56,7 +58,7 @@ public JsonObjectFromCriterionTransformer(JsonBuilderFactory jsonFactory, Object private void addValue(JsonObjectBuilder builder, String field, Object value, TransformerContext context) { try { - builder.add(field, mapper.convertValue(value, JsonValue.class)); + builder.add(field, objectMapperSupplier.get().convertValue(value, JsonValue.class)); } catch (IllegalArgumentException e) { context.problem() .invalidProperty() diff --git a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformer.java b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformer.java index 27dc78aa8ef..2514c16fdab 100644 --- a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformer.java +++ b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformer.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Optional; +import java.util.function.Supplier; import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES; import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES; @@ -38,12 +39,12 @@ public class JsonObjectFromDataPlaneInstanceTransformer extends AbstractJsonLdTransformer { private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonObjectFromDataPlaneInstanceTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { + public JsonObjectFromDataPlaneInstanceTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { super(DataPlaneInstance.class, JsonObject.class); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -56,7 +57,7 @@ public JsonObjectFromDataPlaneInstanceTransformer(JsonBuilderFactory jsonFactory if (dataPlaneInstance.getProperties() != null && !dataPlaneInstance.getProperties().isEmpty()) { var propBuilder = jsonFactory.createObjectBuilder(); - transformProperties(dataPlaneInstance.getProperties(), propBuilder, mapper, context); + transformProperties(dataPlaneInstance.getProperties(), propBuilder, objectMapperSupplier.get(), context); builder.add(PROPERTIES, propBuilder); } diff --git a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3Transformer.java b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3Transformer.java index 57decebe80b..925e42e4c85 100644 --- a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3Transformer.java +++ b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3Transformer.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Optional; +import java.util.function.Supplier; import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES; import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES; @@ -40,12 +41,12 @@ public class JsonObjectFromDataPlaneInstanceV3Transformer extends AbstractJsonLdTransformer { private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonObjectFromDataPlaneInstanceV3Transformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { + public JsonObjectFromDataPlaneInstanceV3Transformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { super(DataPlaneInstance.class, JsonObject.class); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -59,7 +60,7 @@ public JsonObjectFromDataPlaneInstanceV3Transformer(JsonBuilderFactory jsonFacto if (dataPlaneInstance.getProperties() != null && !dataPlaneInstance.getProperties().isEmpty()) { var propBuilder = jsonFactory.createObjectBuilder(); - transformProperties(dataPlaneInstance.getProperties(), propBuilder, mapper, context); + transformProperties(dataPlaneInstance.getProperties(), propBuilder, objectMapperSupplier.get(), context); builder.add(PROPERTIES, propBuilder); } diff --git a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/to/JsonValueToGenericTypeTransformer.java b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/to/JsonValueToGenericTypeTransformer.java index 13ddc04061b..d4024eabf1d 100644 --- a/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/to/JsonValueToGenericTypeTransformer.java +++ b/core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/to/JsonValueToGenericTypeTransformer.java @@ -25,6 +25,8 @@ import org.eclipse.edc.transform.spi.TransformerContext; import org.jetbrains.annotations.NotNull; +import java.util.function.Supplier; + import static java.lang.String.format; import static java.util.stream.Collectors.toList; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; @@ -33,11 +35,11 @@ * Converts from a generic property as a {@link JsonObject} in JSON-LD expanded form to a Java Object. */ public class JsonValueToGenericTypeTransformer extends AbstractJsonLdTransformer { - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonValueToGenericTypeTransformer(ObjectMapper mapper) { + public JsonValueToGenericTypeTransformer(Supplier objectMapperSupplier) { super(JsonValue.class, Object.class); - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -65,7 +67,7 @@ public Object transform(@NotNull JsonValue value, @NotNull TransformerContext co private Object toJavaType(JsonObject object, TransformerContext context) { try { - return mapper.readValue(object.toString(), Object.class); + return objectMapperSupplier.get().readValue(object.toString(), Object.class); } catch (JsonProcessingException e) { context.reportProblem(format("Failed to read value: %s", e.getMessage())); return null; diff --git a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/dspace/from/JsonObjectFromDataAddressDspaceTransformerTest.java b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/dspace/from/JsonObjectFromDataAddressDspaceTransformerTest.java index 77a4f387d70..e04656e0401 100644 --- a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/dspace/from/JsonObjectFromDataAddressDspaceTransformerTest.java +++ b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/dspace/from/JsonObjectFromDataAddressDspaceTransformerTest.java @@ -33,7 +33,7 @@ class JsonObjectFromDataAddressDspaceTransformerTest { private final JsonObjectFromDataAddressDspaceTransformer transformer = new JsonObjectFromDataAddressDspaceTransformer( - Json.createBuilderFactory(Map.of()), JacksonJsonLd.createObjectMapper()); + Json.createBuilderFactory(Map.of()), JacksonJsonLd::createObjectMapper); private final TransformerContext context = mock(); @Test diff --git a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/dspace/v2024/from/JsonObjectFromDataAddressDspace2024TransformerTest.java b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/dspace/v2024/from/JsonObjectFromDataAddressDspace2024TransformerTest.java index 718920ac5a5..41badbc5b33 100644 --- a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/dspace/v2024/from/JsonObjectFromDataAddressDspace2024TransformerTest.java +++ b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/dspace/v2024/from/JsonObjectFromDataAddressDspace2024TransformerTest.java @@ -36,7 +36,7 @@ class JsonObjectFromDataAddressDspace2024TransformerTest { private final JsonObjectFromDataAddressDspace2024Transformer transformer = new JsonObjectFromDataAddressDspace2024Transformer( - Json.createBuilderFactory(Map.of()), JacksonJsonLd.createObjectMapper()); + Json.createBuilderFactory(Map.of()), JacksonJsonLd::createObjectMapper); private final TransformerContext context = mock(); diff --git a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromCriterionTransformerTest.java b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromCriterionTransformerTest.java index bb527d95e05..b7e8ba2fe2d 100644 --- a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromCriterionTransformerTest.java +++ b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromCriterionTransformerTest.java @@ -41,7 +41,7 @@ class JsonObjectFromCriterionTransformerTest { @BeforeEach void setUp() { - transformer = new JsonObjectFromCriterionTransformer(Json.createBuilderFactory(Map.of()), mapper); + transformer = new JsonObjectFromCriterionTransformer(Json.createBuilderFactory(Map.of()), () -> mapper); } @Test diff --git a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformerTest.java b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformerTest.java index 024df40d781..d072440b9d0 100644 --- a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformerTest.java +++ b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformerTest.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import jakarta.json.JsonString; import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,7 +34,6 @@ import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL; import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates.AVAILABLE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.mockito.Mockito.mock; class JsonObjectFromDataPlaneInstanceTransformerTest { @@ -43,7 +43,7 @@ class JsonObjectFromDataPlaneInstanceTransformerTest { @BeforeEach void setUp() { - transformer = new JsonObjectFromDataPlaneInstanceTransformer(Json.createBuilderFactory(Map.of()), createObjectMapper()); + transformer = new JsonObjectFromDataPlaneInstanceTransformer(Json.createBuilderFactory(Map.of()), JacksonJsonLd::createObjectMapper); } @Test diff --git a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3TransformerTest.java b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3TransformerTest.java index 12cf9327921..6681711309b 100644 --- a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3TransformerTest.java +++ b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3TransformerTest.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import jakarta.json.JsonString; import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,7 +36,6 @@ import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL; import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates.AVAILABLE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.mockito.Mockito.mock; class JsonObjectFromDataPlaneInstanceV3TransformerTest { @@ -45,7 +45,7 @@ class JsonObjectFromDataPlaneInstanceV3TransformerTest { @BeforeEach void setUp() { - transformer = new JsonObjectFromDataPlaneInstanceV3Transformer(Json.createBuilderFactory(Map.of()), createObjectMapper()); + transformer = new JsonObjectFromDataPlaneInstanceV3Transformer(Json.createBuilderFactory(Map.of()), JacksonJsonLd::createObjectMapper); } @Test diff --git a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToCriterionTransformerTest.java b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToCriterionTransformerTest.java index cfd52db8a12..577e872dd81 100644 --- a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToCriterionTransformerTest.java +++ b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToCriterionTransformerTest.java @@ -17,13 +17,13 @@ import jakarta.json.Json; import jakarta.json.JsonValue; import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.Test; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.spi.query.Criterion.CRITERION_OPERAND_LEFT; import static org.eclipse.edc.spi.query.Criterion.CRITERION_OPERAND_RIGHT; import static org.eclipse.edc.spi.query.Criterion.CRITERION_OPERATOR; @@ -38,7 +38,7 @@ class JsonObjectToCriterionTransformerTest { private final JsonObjectToCriterionTransformer transformer = new JsonObjectToCriterionTransformer(); - private final JsonValueToGenericTypeTransformer genericTypeTransformer = new JsonValueToGenericTypeTransformer(createObjectMapper()); + private final JsonValueToGenericTypeTransformer genericTypeTransformer = new JsonValueToGenericTypeTransformer(JacksonJsonLd::createObjectMapper); @Test void transform() { diff --git a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToDataAddressTransformerTest.java b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToDataAddressTransformerTest.java index 22aa08be0ee..2ed3016543e 100644 --- a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToDataAddressTransformerTest.java +++ b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToDataAddressTransformerTest.java @@ -19,6 +19,7 @@ import jakarta.json.JsonValue; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.spi.ProblemBuilder; @@ -31,7 +32,6 @@ import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; import static org.mockito.ArgumentMatchers.any; @@ -46,7 +46,7 @@ class JsonObjectToDataAddressTransformerTest { private static final String CUSTOM_PAYLOAD_NAME = "max"; private static final String TEST_TYPE = "test-type"; private static final String TEST_KEY_NAME = "test-key-name"; - private final JsonValueToGenericTypeTransformer objectTransformer = new JsonValueToGenericTypeTransformer(createObjectMapper()); + private final JsonValueToGenericTypeTransformer objectTransformer = new JsonValueToGenericTypeTransformer(JacksonJsonLd::createObjectMapper); private final JsonLd jsonLd = new TitaniumJsonLd(mock(Monitor.class)); private JsonObjectToDataAddressTransformer transformer; private TransformerContext transformerContext; diff --git a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonValueToGenericPropertyTransformerTest.java b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonValueToGenericPropertyTransformerTest.java index bbf5938b5cf..50c9af0eb13 100644 --- a/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonValueToGenericPropertyTransformerTest.java +++ b/core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/to/JsonValueToGenericPropertyTransformerTest.java @@ -49,7 +49,7 @@ class JsonValueToGenericPropertyTransformerTest { @BeforeEach void setUp() { - transformer = new JsonValueToGenericTypeTransformer(mapper); + transformer = new JsonValueToGenericTypeTransformer(() -> mapper); } @Test diff --git a/core/control-plane/control-plane-transform/src/main/java/org/eclipse/edc/connector/controlplane/transform/edc/from/JsonObjectFromAssetTransformer.java b/core/control-plane/control-plane-transform/src/main/java/org/eclipse/edc/connector/controlplane/transform/edc/from/JsonObjectFromAssetTransformer.java index c08a75b59bc..45c2678302f 100644 --- a/core/control-plane/control-plane-transform/src/main/java/org/eclipse/edc/connector/controlplane/transform/edc/from/JsonObjectFromAssetTransformer.java +++ b/core/control-plane/control-plane-transform/src/main/java/org/eclipse/edc/connector/controlplane/transform/edc/from/JsonObjectFromAssetTransformer.java @@ -23,18 +23,20 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Supplier; + import static org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset.EDC_CATALOG_ASSET_TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; public class JsonObjectFromAssetTransformer extends AbstractJsonLdTransformer { - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; private final JsonBuilderFactory jsonFactory; - public JsonObjectFromAssetTransformer(JsonBuilderFactory jsonFactory, ObjectMapper jsonLdMapper) { + public JsonObjectFromAssetTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { super(Asset.class, JsonObject.class); this.jsonFactory = jsonFactory; - this.mapper = jsonLdMapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -44,12 +46,12 @@ public JsonObjectFromAssetTransformer(JsonBuilderFactory jsonFactory, ObjectMapp .add(TYPE, Asset.EDC_ASSET_TYPE); var propBuilder = jsonFactory.createObjectBuilder(); - transformProperties(asset.getProperties(), propBuilder, mapper, context); + transformProperties(asset.getProperties(), propBuilder, objectMapperSupplier.get(), context); builder.add(Asset.EDC_ASSET_PROPERTIES, propBuilder); if (asset.getPrivateProperties() != null && !asset.getPrivateProperties().isEmpty()) { var privatePropBuilder = jsonFactory.createObjectBuilder(); - transformProperties(asset.getPrivateProperties(), privatePropBuilder, mapper, context); + transformProperties(asset.getPrivateProperties(), privatePropBuilder, objectMapperSupplier.get(), context); builder.add(Asset.EDC_ASSET_PRIVATE_PROPERTIES, privatePropBuilder); } diff --git a/core/control-plane/control-plane-transform/src/test/java/org/eclipse/edc/connector/controlplane/transform/edc/from/JsonObjectFromAssetTransformerTest.java b/core/control-plane/control-plane-transform/src/test/java/org/eclipse/edc/connector/controlplane/transform/edc/from/JsonObjectFromAssetTransformerTest.java index 9eaa4be71ec..5991b1961bd 100644 --- a/core/control-plane/control-plane-transform/src/test/java/org/eclipse/edc/connector/controlplane/transform/edc/from/JsonObjectFromAssetTransformerTest.java +++ b/core/control-plane/control-plane-transform/src/test/java/org/eclipse/edc/connector/controlplane/transform/edc/from/JsonObjectFromAssetTransformerTest.java @@ -22,6 +22,7 @@ import jakarta.json.JsonValue; import org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset; import org.eclipse.edc.connector.controlplane.transform.Payload; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.BeforeEach; @@ -41,7 +42,6 @@ import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.types.domain.DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY; import static org.mockito.ArgumentMatchers.eq; @@ -62,7 +62,7 @@ class JsonObjectFromAssetTransformerTest { @BeforeEach void setUp() { - transformer = new JsonObjectFromAssetTransformer(Json.createBuilderFactory(Map.of()), createObjectMapper()); + transformer = new JsonObjectFromAssetTransformer(Json.createBuilderFactory(Map.of()), JacksonJsonLd::createObjectMapper); } @Test diff --git a/core/control-plane/control-plane-transform/src/test/java/org/eclipse/edc/connector/controlplane/transform/edc/to/JsonObjectToAssetTransformerTest.java b/core/control-plane/control-plane-transform/src/test/java/org/eclipse/edc/connector/controlplane/transform/edc/to/JsonObjectToAssetTransformerTest.java index 3840e4b37ba..9d10c906108 100644 --- a/core/control-plane/control-plane-transform/src/test/java/org/eclipse/edc/connector/controlplane/transform/edc/to/JsonObjectToAssetTransformerTest.java +++ b/core/control-plane/control-plane-transform/src/test/java/org/eclipse/edc/connector/controlplane/transform/edc/to/JsonObjectToAssetTransformerTest.java @@ -19,6 +19,7 @@ import jakarta.json.JsonObjectBuilder; import org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset; import org.eclipse.edc.connector.controlplane.transform.TestInput; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.TypeTransformerRegistryImpl; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; @@ -46,7 +47,6 @@ import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; @@ -65,10 +65,9 @@ class JsonObjectToAssetTransformerTest { @BeforeEach void setUp() { - var objectMapper = createObjectMapper(); var transformer = new JsonObjectToAssetTransformer(); typeTransformerRegistry = new TypeTransformerRegistryImpl(); - typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapper)); + typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(JacksonJsonLd::createObjectMapper)); typeTransformerRegistry.register(transformer); typeTransformerRegistry.register(new JsonObjectToDataAddressTransformer()); } diff --git a/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java b/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java index 79d2bfb9b74..2859718f823 100644 --- a/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java +++ b/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.protocol.dsp.catalog.http.api; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.edc.connector.controlplane.catalog.spi.DataService; import org.eclipse.edc.connector.controlplane.catalog.spi.DataServiceRegistry; import org.eclipse.edc.connector.controlplane.services.spi.catalog.CatalogProtocolService; @@ -41,6 +42,8 @@ import org.eclipse.edc.web.spi.WebService; import org.eclipse.edc.web.spi.configuration.ApiContext; +import java.util.function.Supplier; + import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; @@ -92,14 +95,14 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var jsonLdMapper = typeManager.getMapper(JSON_LD); + Supplier jsonLdMapperSupplier = () -> typeManager.getMapper(JSON_LD); registerValidators(DSP_NAMESPACE_V_08); registerValidators(DSP_NAMESPACE_V_2024_1); webService.registerResource(ApiContext.PROTOCOL, new DspCatalogApiController(service, dspRequestHandler, continuationTokenManager(monitor, DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08))); webService.registerResource(ApiContext.PROTOCOL, new DspCatalogApiController20241(service, dspRequestHandler, continuationTokenManager(monitor, DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1))); - webService.registerDynamicResource(ApiContext.PROTOCOL, DspCatalogApiController.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE_V_08)); - webService.registerDynamicResource(ApiContext.PROTOCOL, DspCatalogApiController20241.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE_V_2024_1)); + webService.registerDynamicResource(ApiContext.PROTOCOL, DspCatalogApiController.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapperSupplier, DSP_SCOPE_V_08)); + webService.registerDynamicResource(ApiContext.PROTOCOL, DspCatalogApiController20241.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapperSupplier, DSP_SCOPE_V_2024_1)); dataServiceRegistry.register(DataService.Builder.newInstance() .endpointDescription("dspace:connector") diff --git a/data-protocols/dsp/dsp-catalog/dsp-catalog-transform/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/DspCatalogTransformExtension.java b/data-protocols/dsp/dsp-catalog/dsp-catalog-transform/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/DspCatalogTransformExtension.java index 3c55c99f7cd..81d53bd5e25 100644 --- a/data-protocols/dsp/dsp-catalog/dsp-catalog-transform/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/DspCatalogTransformExtension.java +++ b/data-protocols/dsp/dsp-catalog/dsp-catalog-transform/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/DspCatalogTransformExtension.java @@ -34,6 +34,7 @@ import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import java.util.Map; +import java.util.function.Supplier; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; @@ -65,40 +66,40 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var mapper = typeManager.getMapper(JSON_LD); + Supplier mapperSupplier = () -> typeManager.getMapper(JSON_LD); - registerV08Transformers(mapper); - registerV2024Transformers(mapper); - - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, mapper); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, mapper); + registerV08Transformers(mapperSupplier); + registerV2024Transformers(mapperSupplier); + + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, mapperSupplier); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, mapperSupplier); } - private void registerTransformers(String version, JsonLdNamespace namespace, ObjectMapper mapper) { + private void registerTransformers(String version, JsonLdNamespace namespace, Supplier mapperSupplier) { var jsonFactory = Json.createBuilderFactory(Map.of()); var dspApiTransformerRegistry = registry.forContext(version); dspApiTransformerRegistry.register(new JsonObjectFromCatalogRequestMessageTransformer(jsonFactory, namespace)); dspApiTransformerRegistry.register(new JsonObjectToCatalogRequestMessageTransformer(namespace)); - dspApiTransformerRegistry.register(new JsonObjectFromDatasetTransformer(jsonFactory, mapper)); + dspApiTransformerRegistry.register(new JsonObjectFromDatasetTransformer(jsonFactory, mapperSupplier)); dspApiTransformerRegistry.register(new JsonObjectFromDistributionTransformer(jsonFactory)); dspApiTransformerRegistry.register(new JsonObjectFromDataServiceTransformer(jsonFactory)); dspApiTransformerRegistry.register(new JsonObjectFromCatalogErrorTransformer(jsonFactory, namespace)); } - private void registerV08Transformers(ObjectMapper mapper) { + private void registerV08Transformers(Supplier mapperSupplier) { var jsonFactory = Json.createBuilderFactory(Map.of()); var dspApiTransformerRegistry = registry.forContext(DSP_TRANSFORMER_CONTEXT_V_08); - dspApiTransformerRegistry.register(new JsonObjectFromCatalogTransformer(jsonFactory, mapper, participantIdMapper, DSP_NAMESPACE_V_08)); + dspApiTransformerRegistry.register(new JsonObjectFromCatalogTransformer(jsonFactory, mapperSupplier, participantIdMapper, DSP_NAMESPACE_V_08)); } - private void registerV2024Transformers(ObjectMapper mapper) { + private void registerV2024Transformers(Supplier mapperSupplier) { var jsonFactory = Json.createBuilderFactory(Map.of()); var dspApiTransformerRegistry = registry.forContext(DSP_TRANSFORMER_CONTEXT_V_2024_1); - dspApiTransformerRegistry.register(new JsonObjectFromCatalogV2024Transformer(jsonFactory, mapper, participantIdMapper, DSP_NAMESPACE_V_2024_1)); + dspApiTransformerRegistry.register(new JsonObjectFromCatalogV2024Transformer(jsonFactory, mapperSupplier, participantIdMapper, DSP_NAMESPACE_V_2024_1)); } } diff --git a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-http-api-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/Base64ContinuationTokenSerDesTest.java b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-http-api-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/Base64ContinuationTokenSerDesTest.java index 6bc834eb175..a685d9ce155 100644 --- a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-http-api-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/Base64ContinuationTokenSerDesTest.java +++ b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-http-api-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/Base64ContinuationTokenSerDesTest.java @@ -54,8 +54,8 @@ class Base64ContinuationTokenSerDesTest { void setup() { var builderFactory = Json.createBuilderFactory(emptyMap()); typeTransformerRegistry.register(new JsonObjectFromQuerySpecTransformer(builderFactory)); - typeTransformerRegistry.register(new JsonObjectFromCriterionTransformer(builderFactory, objectMapper)); - typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapper)); + typeTransformerRegistry.register(new JsonObjectFromCriterionTransformer(builderFactory, () -> objectMapper)); + typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(() -> objectMapper)); typeTransformerRegistry.register(new JsonObjectToQuerySpecTransformer()); typeTransformerRegistry.register(new JsonObjectToCriterionTransformer()); } diff --git a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromCatalogTransformer.java b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromCatalogTransformer.java index f94558e6844..66c052ccd09 100644 --- a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromCatalogTransformer.java +++ b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromCatalogTransformer.java @@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.function.Supplier; import java.util.stream.Collectors; import static jakarta.json.stream.JsonCollectors.toJsonArray; @@ -46,17 +47,17 @@ */ public class JsonObjectFromCatalogTransformer extends AbstractNamespaceAwareJsonLdTransformer { private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; private final ParticipantIdMapper participantIdMapper; - public JsonObjectFromCatalogTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, ParticipantIdMapper participantIdMapper) { - this(jsonFactory, mapper, participantIdMapper, DSP_NAMESPACE_V_08); + public JsonObjectFromCatalogTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier, ParticipantIdMapper participantIdMapper) { + this(jsonFactory, objectMapperSupplier, participantIdMapper, DSP_NAMESPACE_V_08); } - public JsonObjectFromCatalogTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, ParticipantIdMapper participantIdMapper, JsonLdNamespace namespace) { + public JsonObjectFromCatalogTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier, ParticipantIdMapper participantIdMapper, JsonLdNamespace namespace) { super(Catalog.class, JsonObject.class, namespace); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; this.participantIdMapper = participantIdMapper; } @@ -92,9 +93,9 @@ public JsonObjectFromCatalogTransformer(JsonBuilderFactory jsonFactory, ObjectMa ofNullable(catalog.getParticipantId()).ifPresent(pid -> objectBuilder.add(forNamespace(DSPACE_PROPERTY_PARTICIPANT_ID_TERM), participantIdMapper.toIri(pid))); - transformProperties(catalog.getProperties(), objectBuilder, mapper, context); + transformProperties(catalog.getProperties(), objectBuilder, objectMapperSupplier.get(), context); return objectBuilder.build(); } - + } diff --git a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromDatasetTransformer.java b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromDatasetTransformer.java index 91897d798b0..ed32ff6b550 100644 --- a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromDatasetTransformer.java +++ b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromDatasetTransformer.java @@ -26,6 +26,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Supplier; + import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATASET_TYPE; @@ -38,12 +40,12 @@ public class JsonObjectFromDatasetTransformer extends AbstractJsonLdTransformer { private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier mapperSupplier; - public JsonObjectFromDatasetTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { + public JsonObjectFromDatasetTransformer(JsonBuilderFactory jsonFactory, Supplier mapperSupplier) { super(Dataset.class, JsonObject.class); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.mapperSupplier = mapperSupplier; } @Override @@ -61,7 +63,7 @@ public JsonObjectFromDatasetTransformer(JsonBuilderFactory jsonFactory, ObjectMa .build(); objectBuilder.add(DCAT_DISTRIBUTION_ATTRIBUTE, distributions); - transformProperties(dataset.getProperties(), objectBuilder, mapper, context); + transformProperties(dataset.getProperties(), objectBuilder, mapperSupplier.get(), context); return objectBuilder.build(); } diff --git a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/v2024/from/JsonObjectFromCatalogV2024Transformer.java b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/v2024/from/JsonObjectFromCatalogV2024Transformer.java index 6db6120fbe8..ab64bdfa8c9 100644 --- a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/v2024/from/JsonObjectFromCatalogV2024Transformer.java +++ b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/v2024/from/JsonObjectFromCatalogV2024Transformer.java @@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.function.Supplier; import java.util.stream.Collectors; import static jakarta.json.stream.JsonCollectors.toJsonArray; @@ -46,17 +47,17 @@ */ public class JsonObjectFromCatalogV2024Transformer extends AbstractNamespaceAwareJsonLdTransformer { private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier mapperSupplier; private final ParticipantIdMapper participantIdMapper; - public JsonObjectFromCatalogV2024Transformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, ParticipantIdMapper participantIdMapper) { - this(jsonFactory, mapper, participantIdMapper, DSP_NAMESPACE_V_2024_1); + public JsonObjectFromCatalogV2024Transformer(JsonBuilderFactory jsonFactory, Supplier mapperSupplier, ParticipantIdMapper participantIdMapper) { + this(jsonFactory, mapperSupplier, participantIdMapper, DSP_NAMESPACE_V_2024_1); } - public JsonObjectFromCatalogV2024Transformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, ParticipantIdMapper participantIdMapper, JsonLdNamespace namespace) { + public JsonObjectFromCatalogV2024Transformer(JsonBuilderFactory jsonFactory, Supplier mapperSupplier, ParticipantIdMapper participantIdMapper, JsonLdNamespace namespace) { super(Catalog.class, JsonObject.class, namespace); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.mapperSupplier = mapperSupplier; this.participantIdMapper = participantIdMapper; } @@ -92,9 +93,9 @@ public JsonObjectFromCatalogV2024Transformer(JsonBuilderFactory jsonFactory, Obj ofNullable(catalog.getParticipantId()).ifPresent(pid -> objectBuilder.add(forNamespace(DSPACE_PROPERTY_PARTICIPANT_ID_TERM), createId(jsonFactory, participantIdMapper.toIri(pid)))); - transformProperties(catalog.getProperties(), objectBuilder, mapper, context); + transformProperties(catalog.getProperties(), objectBuilder, mapperSupplier.get(), context); return objectBuilder.build(); } - + } diff --git a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromCatalogTransformerTest.java b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromCatalogTransformerTest.java index fcb52c90d6f..418b7f41e01 100644 --- a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromCatalogTransformerTest.java +++ b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromCatalogTransformerTest.java @@ -59,7 +59,7 @@ class JsonObjectFromCatalogTransformerTest { private final TransformerContext context = mock(); private final ParticipantIdMapper participantIdMapper = mock(); - private final JsonObjectFromCatalogTransformer transformer = new JsonObjectFromCatalogTransformer(jsonFactory, mapper, participantIdMapper); + private final JsonObjectFromCatalogTransformer transformer = new JsonObjectFromCatalogTransformer(jsonFactory, () -> mapper, participantIdMapper); private JsonObject datasetJson; private JsonObject catalogJson; diff --git a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromDatasetTransformerTest.java b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromDatasetTransformerTest.java index 450ea4be840..2a0d9ed17ea 100644 --- a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromDatasetTransformerTest.java +++ b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/from/JsonObjectFromDatasetTransformerTest.java @@ -62,7 +62,7 @@ class JsonObjectFromDatasetTransformerTest { @BeforeEach void setUp() { - transformer = new JsonObjectFromDatasetTransformer(jsonFactory, mapper); + transformer = new JsonObjectFromDatasetTransformer(jsonFactory, () -> mapper); policyJson = getJsonObject("policy"); distributionJson = getJsonObject("distribution"); diff --git a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/v2024/from/JsonObjectFromCatalogV2024TransformerTest.java b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/v2024/from/JsonObjectFromCatalogV2024TransformerTest.java index 568b8169bec..c963b4ff782 100644 --- a/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/v2024/from/JsonObjectFromCatalogV2024TransformerTest.java +++ b/data-protocols/dsp/dsp-catalog/lib/dsp-catalog-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/catalog/transform/v2024/from/JsonObjectFromCatalogV2024TransformerTest.java @@ -60,7 +60,7 @@ class JsonObjectFromCatalogV2024TransformerTest { private final TransformerContext context = mock(); private final ParticipantIdMapper participantIdMapper = mock(); - private final JsonObjectFromCatalogV2024Transformer transformer = new JsonObjectFromCatalogV2024Transformer(jsonFactory, mapper, participantIdMapper); + private final JsonObjectFromCatalogV2024Transformer transformer = new JsonObjectFromCatalogV2024Transformer(jsonFactory, () -> mapper, participantIdMapper); private JsonObject datasetJson; private JsonObject catalogJson; diff --git a/data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java b/data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java index bb5f57d4a47..7e40bf03daf 100644 --- a/data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java +++ b/data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java @@ -52,6 +52,7 @@ import org.eclipse.edc.web.spi.configuration.PortMappingRegistry; import java.util.Map; +import java.util.function.Supplier; import static java.lang.String.format; import static java.util.Optional.ofNullable; @@ -118,21 +119,25 @@ public void initialize(ServiceExtensionContext context) { var dspWebhookAddress = ofNullable(callbackAddress).orElseGet(() -> format("http://%s:%s%s", hostname.get(), portMapping.port(), portMapping.path())); context.registerService(ProtocolWebhook.class, () -> dspWebhookAddress); - var jsonLdMapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); // registers ns for DSP scope registerNamespaces(DSP_SCOPE_V_08, DSP_NAMESPACE_V_08); registerNamespaces(DSP_SCOPE_V_2024_1, DSP_NAMESPACE_V_2024_1); - webService.registerResource(ApiContext.PROTOCOL, new ObjectMapperProvider(jsonLdMapper)); + webService.registerResource(ApiContext.PROTOCOL, new ObjectMapperProvider(objectMapperSupplier)); + + registerV08Transformers(objectMapperSupplier); + registerV2024Transformers(objectMapperSupplier); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, objectMapperSupplier); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, objectMapperSupplier); + } + + @Override + public void prepare() { var mapper = typeManager.getMapper(JSON_LD); mapper.registerSubtypes(AtomicConstraint.class, LiteralExpression.class); - - registerV08Transformers(mapper); - registerV2024Transformers(mapper); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, mapper); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, mapper); } private void registerNamespaces(String scope, JsonLdNamespace dspNamespace) { @@ -144,20 +149,20 @@ private void registerNamespaces(String scope, JsonLdNamespace dspNamespace) { jsonLd.registerNamespace(EDC_PREFIX, EDC_NAMESPACE, scope); } - private void registerTransformers(String version, JsonLdNamespace dspNamespace, ObjectMapper mapper) { + private void registerTransformers(String version, JsonLdNamespace dspNamespace, Supplier objectMapperSupplier) { var jsonBuilderFactory = Json.createBuilderFactory(Map.of()); // EDC model to JSON-LD transformers var dspApiTransformerRegistry = transformerRegistry.forContext(version); - dspApiTransformerRegistry.register(new JsonObjectFromAssetTransformer(jsonBuilderFactory, mapper)); + dspApiTransformerRegistry.register(new JsonObjectFromAssetTransformer(jsonBuilderFactory, objectMapperSupplier)); dspApiTransformerRegistry.register(new JsonObjectFromQuerySpecTransformer(jsonBuilderFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromCriterionTransformer(jsonBuilderFactory, mapper)); + dspApiTransformerRegistry.register(new JsonObjectFromCriterionTransformer(jsonBuilderFactory, objectMapperSupplier)); // JSON-LD to EDC model transformers // ODRL Transformers OdrlTransformersFactory.jsonObjectToOdrlTransformers(participantIdMapper).forEach(dspApiTransformerRegistry::register); - dspApiTransformerRegistry.register(new JsonValueToGenericTypeTransformer(mapper)); + dspApiTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapperSupplier)); dspApiTransformerRegistry.register(new JsonObjectToAssetTransformer()); dspApiTransformerRegistry.register(new JsonObjectToQuerySpecTransformer()); dspApiTransformerRegistry.register(new JsonObjectToCriterionTransformer()); @@ -165,24 +170,24 @@ private void registerTransformers(String version, JsonLdNamespace dspNamespace, } - private void registerV08Transformers(ObjectMapper mapper) { + private void registerV08Transformers(Supplier objectMapperSupplier) { var jsonBuilderFactory = Json.createBuilderFactory(Map.of()); // EDC model to JSON-LD transformers var dspApiTransformerRegistry = transformerRegistry.forContext(DSP_TRANSFORMER_CONTEXT_V_08); dspApiTransformerRegistry.register(new JsonObjectFromPolicyTransformer(jsonBuilderFactory, participantIdMapper)); - dspApiTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(jsonBuilderFactory, mapper)); + dspApiTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(jsonBuilderFactory, objectMapperSupplier)); } - private void registerV2024Transformers(ObjectMapper mapper) { + private void registerV2024Transformers(Supplier objectMapperSupplier) { var jsonBuilderFactory = Json.createBuilderFactory(Map.of()); // EDC model to JSON-LD transformers var dspApiTransformerRegistry = transformerRegistry.forContext(DSP_TRANSFORMER_CONTEXT_V_2024_1); dspApiTransformerRegistry.register(new JsonObjectFromPolicyTransformer(jsonBuilderFactory, participantIdMapper, true)); - dspApiTransformerRegistry.register(new JsonObjectFromDataAddressDspace2024Transformer(jsonBuilderFactory, mapper)); + dspApiTransformerRegistry.register(new JsonObjectFromDataAddressDspace2024Transformer(jsonBuilderFactory, objectMapperSupplier)); } @Settings diff --git a/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/DspHttpCoreExtension.java b/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/DspHttpCoreExtension.java index 4a128f6e018..88e02c17a1e 100644 --- a/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/DspHttpCoreExtension.java +++ b/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/DspHttpCoreExtension.java @@ -150,7 +150,7 @@ public DspRequestHandler dspRequestHandler() { @Provider public JsonLdRemoteMessageSerializer jsonLdRemoteMessageSerializer() { - return new JsonLdRemoteMessageSerializerImpl(dspTransformerRegistry(), typeManager.getMapper(JSON_LD), jsonLdService, dspProtocolParser(), DSP_SCOPE); + return new JsonLdRemoteMessageSerializerImpl(dspTransformerRegistry(), () -> typeManager.getMapper(JSON_LD), jsonLdService, dspProtocolParser(), DSP_SCOPE); } @Provider diff --git a/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdRemoteMessageSerializerImpl.java b/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdRemoteMessageSerializerImpl.java index 6f046700d71..119fa338211 100644 --- a/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdRemoteMessageSerializerImpl.java +++ b/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdRemoteMessageSerializerImpl.java @@ -25,6 +25,8 @@ import org.eclipse.edc.spi.types.domain.message.RemoteMessage; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import java.util.function.Supplier; + import static java.lang.String.format; import static java.lang.String.join; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_CONTEXT_SEPARATOR; @@ -34,16 +36,16 @@ */ public class JsonLdRemoteMessageSerializerImpl implements JsonLdRemoteMessageSerializer { - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; private final JsonLd jsonLdService; private final String scopePrefix; private final DspProtocolTypeTransformerRegistry dspTransformerRegistry; private final DspProtocolParser protocolParser; public JsonLdRemoteMessageSerializerImpl(DspProtocolTypeTransformerRegistry dspTransformerRegistry, - ObjectMapper mapper, JsonLd jsonLdService, DspProtocolParser protocolParser, String scopePrefix) { + Supplier objectMapperSupplier, JsonLd jsonLdService, DspProtocolParser protocolParser, String scopePrefix) { this.dspTransformerRegistry = dspTransformerRegistry; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; this.jsonLdService = jsonLdService; this.scopePrefix = scopePrefix; this.protocolParser = protocolParser; @@ -73,7 +75,7 @@ public String serialize(RemoteMessage message) { var compacted = protocolParser.parse(message.getProtocol()) .compose(protocol -> jsonLdService.compact(transformResult.getContent(), scopePrefix + DSP_CONTEXT_SEPARATOR + protocol.version())); if (compacted.succeeded()) { - return mapper.writeValueAsString(compacted.getContent()); + return objectMapperSupplier.get().writeValueAsString(compacted.getContent()); } throw new EdcException("Failed to compact JSON-LD: " + compacted.getFailureDetail()); } diff --git a/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdResponseBodyDeserializer.java b/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdResponseBodyDeserializer.java index 082a8b522fe..8be5b6c7dad 100644 --- a/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdResponseBodyDeserializer.java +++ b/data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdResponseBodyDeserializer.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.util.function.Function; +import java.util.function.Supplier; import static java.lang.String.format; import static java.lang.String.join; @@ -35,13 +36,13 @@ */ public class JsonLdResponseBodyDeserializer implements DspHttpResponseBodyExtractor { private final Class type; - private final ObjectMapper objectMapper; + private final Supplier objectMapperSupplier; private final JsonLd jsonLd; private final DspProtocolTypeTransformerRegistry dspTransformerRegistry; - public JsonLdResponseBodyDeserializer(Class type, ObjectMapper objectMapper, JsonLd jsonLd, DspProtocolTypeTransformerRegistry dspTransformerRegistry) { + public JsonLdResponseBodyDeserializer(Class type, Supplier objectMapperSupplier, JsonLd jsonLd, DspProtocolTypeTransformerRegistry dspTransformerRegistry) { this.type = type; - this.objectMapper = objectMapper; + this.objectMapperSupplier = objectMapperSupplier; this.jsonLd = jsonLd; this.dspTransformerRegistry = dspTransformerRegistry; } @@ -49,7 +50,7 @@ public JsonLdResponseBodyDeserializer(Class type, ObjectMapper objectMapper, @Override public T extractBody(ResponseBody responseBody, String protocol) { try { - var jsonObject = objectMapper.readValue(responseBody.byteStream(), JsonObject.class); + var jsonObject = objectMapperSupplier.get().readValue(responseBody.byteStream(), JsonObject.class); var transformerRegistryResult = dspTransformerRegistry.forProtocol(protocol); if (transformerRegistryResult.failed()) { throw new EdcException(format("Failed to extract body: %s", join(", ", transformerRegistryResult.getFailureMessages()))); diff --git a/data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdRemoteMessageSerializerImplTest.java b/data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdRemoteMessageSerializerImplTest.java index dab5ef16e88..5656ee70017 100644 --- a/data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdRemoteMessageSerializerImplTest.java +++ b/data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdRemoteMessageSerializerImplTest.java @@ -56,7 +56,7 @@ void setUp() { var jsonLdService = new TitaniumJsonLd(mock(Monitor.class)); jsonLdService.registerNamespace("schema", "http://schema/"); //needed for compaction when(registry.forContext(DSP_TRANSFORMER_CONTEXT_V_08)).thenReturn(registry); - serializer = new JsonLdRemoteMessageSerializerImpl(dspTransformerRegistry, mapper, jsonLdService, protocolParser, "scope"); + serializer = new JsonLdRemoteMessageSerializerImpl(dspTransformerRegistry, () -> mapper, jsonLdService, protocolParser, "scope"); when(message.getProtocol()).thenReturn(DATASPACE_PROTOCOL_HTTP); } diff --git a/data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdResponseBodyDeserializerTest.java b/data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdResponseBodyDeserializerTest.java index 16357da73bf..090b8213522 100644 --- a/data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdResponseBodyDeserializerTest.java +++ b/data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/serialization/JsonLdResponseBodyDeserializerTest.java @@ -52,7 +52,7 @@ class JsonLdResponseBodyDeserializerTest { private final TypeTransformerRegistry transformerRegistry = mock(); private final DspProtocolTypeTransformerRegistry dspTransformerRegistry = mock(); private final JsonLdResponseBodyDeserializer bodyExtractor = - new JsonLdResponseBodyDeserializer<>(Object.class, objectMapper, jsonLd, dspTransformerRegistry); + new JsonLdResponseBodyDeserializer<>(Object.class, () -> objectMapper, jsonLd, dspTransformerRegistry); @BeforeEach diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java index 7f49640d9b0..0c979a10e5d 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.protocol.dsp.negotiation.http.api; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.edc.connector.controlplane.services.spi.contractnegotiation.ContractNegotiationProtocolService; import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; import org.eclipse.edc.jsonld.spi.JsonLd; @@ -37,6 +38,8 @@ import org.eclipse.edc.web.spi.WebService; import org.eclipse.edc.web.spi.configuration.ApiContext; +import java.util.function.Supplier; + import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_08; @@ -83,15 +86,15 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var jsonLdMapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); registerValidators(DSP_NAMESPACE_V_08); registerValidators(DSP_NAMESPACE_V_2024_1); webService.registerResource(ApiContext.PROTOCOL, new DspNegotiationApiController(protocolService, dspRequestHandler)); webService.registerResource(ApiContext.PROTOCOL, new DspNegotiationApiController20241(protocolService, dspRequestHandler)); - webService.registerDynamicResource(ApiContext.PROTOCOL, DspNegotiationApiController.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE_V_08)); - webService.registerDynamicResource(ApiContext.PROTOCOL, DspNegotiationApiController20241.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE_V_2024_1)); + webService.registerDynamicResource(ApiContext.PROTOCOL, DspNegotiationApiController.class, new JerseyJsonLdInterceptor(jsonLd, objectMapperSupplier, DSP_SCOPE_V_08)); + webService.registerDynamicResource(ApiContext.PROTOCOL, DspNegotiationApiController20241.class, new JerseyJsonLdInterceptor(jsonLd, objectMapperSupplier, DSP_SCOPE_V_2024_1)); versionRegistry.register(V_2024_1); versionRegistry.register(V_08); diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-dispatcher/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/dispatcher/DspNegotiationHttpDispatcherExtension.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-dispatcher/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/dispatcher/DspNegotiationHttpDispatcherExtension.java index 6af7bf789b6..c7295df8e71 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-dispatcher/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/dispatcher/DspNegotiationHttpDispatcherExtension.java +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-dispatcher/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/dispatcher/DspNegotiationHttpDispatcherExtension.java @@ -68,7 +68,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { var contractNegotiationAckDeserializer = new JsonLdResponseBodyDeserializer<>( - ContractNegotiationAck.class, typeManager.getMapper(JSON_LD), jsonLd, dspTransformerRegistry); + ContractNegotiationAck.class, () -> typeManager.getMapper(JSON_LD), jsonLd, dspTransformerRegistry); messageDispatcher.registerMessage( ContractAgreementMessage.class, diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java index 7405509b882..7a764e36265 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.protocol.dsp.transferprocess.http.api; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; import org.eclipse.edc.connector.controlplane.services.spi.transferprocess.TransferProcessProtocolService; import org.eclipse.edc.jsonld.spi.JsonLd; @@ -35,6 +36,8 @@ import org.eclipse.edc.web.spi.WebService; import org.eclipse.edc.web.spi.configuration.ApiContext; +import java.util.function.Supplier; + import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_08; @@ -71,15 +74,15 @@ public class DspTransferProcessApiExtension implements ServiceExtension { @Override public void initialize(ServiceExtensionContext context) { - var jsonLdMapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); registerValidators(DSP_NAMESPACE_V_08); registerValidators(DSP_NAMESPACE_V_2024_1); webService.registerResource(ApiContext.PROTOCOL, new DspTransferProcessApiController(transferProcessProtocolService, dspRequestHandler)); webService.registerResource(ApiContext.PROTOCOL, new DspTransferProcessApiController20241(transferProcessProtocolService, dspRequestHandler)); - webService.registerDynamicResource(ApiContext.PROTOCOL, DspTransferProcessApiController.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE_V_08)); - webService.registerDynamicResource(ApiContext.PROTOCOL, DspTransferProcessApiController20241.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE_V_2024_1)); + webService.registerDynamicResource(ApiContext.PROTOCOL, DspTransferProcessApiController.class, new JerseyJsonLdInterceptor(jsonLd, objectMapperSupplier, DSP_SCOPE_V_08)); + webService.registerDynamicResource(ApiContext.PROTOCOL, DspTransferProcessApiController20241.class, new JerseyJsonLdInterceptor(jsonLd, objectMapperSupplier, DSP_SCOPE_V_2024_1)); versionRegistry.register(V_2024_1); versionRegistry.register(V_08); diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-dispatcher/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/dispatcher/DspTransferProcessDispatcherExtension.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-dispatcher/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/dispatcher/DspTransferProcessDispatcherExtension.java index 6fadce273d0..9b739f0febc 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-dispatcher/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/dispatcher/DspTransferProcessDispatcherExtension.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-dispatcher/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/dispatcher/DspTransferProcessDispatcherExtension.java @@ -80,7 +80,7 @@ public void initialize(ServiceExtensionContext context) { messageDispatcher.registerMessage( TransferRequestMessage.class, new PostDspHttpRequestFactory<>(remoteMessageSerializer, dspProtocolParser, m -> BASE_PATH + TRANSFER_INITIAL_REQUEST), - new JsonLdResponseBodyDeserializer<>(TransferProcessAck.class, typeManager.getMapper(JSON_LD), jsonLd, dspTransformerRegistry) + new JsonLdResponseBodyDeserializer<>(TransferProcessAck.class, () -> typeManager.getMapper(JSON_LD), jsonLd, dspTransformerRegistry) ); messageDispatcher.registerMessage( TransferCompletionMessage.class, diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/DspTransferProcessTransformExtension.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/DspTransferProcessTransformExtension.java index 29a9ac83edc..a3f891d4fb0 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/DspTransferProcessTransformExtension.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/DspTransferProcessTransformExtension.java @@ -44,6 +44,7 @@ import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import java.util.Map; +import java.util.function.Supplier; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; @@ -72,16 +73,16 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var objectMapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); registerV08transformers(); registerV2024transformers(); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, objectMapper); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, objectMapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, objectMapperSupplier); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, objectMapperSupplier); } - private void registerTransformers(String version, JsonLdNamespace namespace, ObjectMapper objectMapper) { + private void registerTransformers(String version, JsonLdNamespace namespace, Supplier objectMapperSupplier) { var builderFactory = Json.createBuilderFactory(Map.of()); var dspRegistry = registry.forContext(version); @@ -93,7 +94,7 @@ private void registerTransformers(String version, JsonLdNamespace namespace, Obj dspRegistry.register(new JsonObjectToTransferStartMessageTransformer(namespace)); dspRegistry.register(new JsonObjectToTransferTerminationMessageTransformer(namespace)); dspRegistry.register(new JsonObjectToTransferProcessAckTransformer(namespace)); - dspRegistry.register(new JsonObjectToTransferSuspensionMessageTransformer(objectMapper, namespace)); + dspRegistry.register(new JsonObjectToTransferSuspensionMessageTransformer(objectMapperSupplier, namespace)); } private void registerV08transformers() { diff --git a/data-protocols/dsp/dsp-transfer-process/lib/dsp-transfer-process-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/type/to/JsonObjectToTransferSuspensionMessageTransformer.java b/data-protocols/dsp/dsp-transfer-process/lib/dsp-transfer-process-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/type/to/JsonObjectToTransferSuspensionMessageTransformer.java index 2fa8e594656..c4ca76f7d54 100644 --- a/data-protocols/dsp/dsp-transfer-process/lib/dsp-transfer-process-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/type/to/JsonObjectToTransferSuspensionMessageTransformer.java +++ b/data-protocols/dsp/dsp-transfer-process/lib/dsp-transfer-process-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/type/to/JsonObjectToTransferSuspensionMessageTransformer.java @@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Map; +import java.util.function.Supplier; import static jakarta.json.JsonValue.ValueType.ARRAY; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; @@ -40,15 +41,15 @@ public class JsonObjectToTransferSuspensionMessageTransformer extends AbstractNamespaceAwareJsonLdTransformer { - private final ObjectMapper objectMapper; + private final Supplier objectMapperSupplier; - public JsonObjectToTransferSuspensionMessageTransformer(ObjectMapper objectMapper) { - this(objectMapper, DSP_NAMESPACE_V_08); + public JsonObjectToTransferSuspensionMessageTransformer(Supplier objectMapperSupplier) { + this(objectMapperSupplier, DSP_NAMESPACE_V_08); } - public JsonObjectToTransferSuspensionMessageTransformer(ObjectMapper objectMapper, JsonLdNamespace namespace) { + public JsonObjectToTransferSuspensionMessageTransformer(Supplier objectMapperSupplier, JsonLdNamespace namespace) { super(JsonObject.class, TransferSuspensionMessage.class, namespace); - this.objectMapper = objectMapper; + this.objectMapperSupplier = objectMapperSupplier; } @@ -99,7 +100,7 @@ public JsonObjectToTransferSuspensionMessageTransformer(ObjectMapper objectMappe private Object deserialize(JsonValue it) { try { - return objectMapper.readValue(it.toString(), Map.class); + return objectMapperSupplier.get().readValue(it.toString(), Map.class); } catch (JsonProcessingException e) { throw new EdcException("Error deserializing 'reason' field."); } diff --git a/data-protocols/dsp/dsp-transfer-process/lib/dsp-transfer-process-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/to/JsonObjectToTransferSuspensionMessageTransformerTest.java b/data-protocols/dsp/dsp-transfer-process/lib/dsp-transfer-process-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/to/JsonObjectToTransferSuspensionMessageTransformerTest.java index a78cc9842d2..25903b844a0 100644 --- a/data-protocols/dsp/dsp-transfer-process/lib/dsp-transfer-process-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/to/JsonObjectToTransferSuspensionMessageTransformerTest.java +++ b/data-protocols/dsp/dsp-transfer-process/lib/dsp-transfer-process-transform-lib/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/to/JsonObjectToTransferSuspensionMessageTransformerTest.java @@ -49,7 +49,7 @@ class JsonObjectToTransferSuspensionMessageTransformerTest { private final TransformerContext context = mock(); private final ObjectMapper objectMapper = JacksonJsonLd.createObjectMapper(); private final JsonObjectToTransferSuspensionMessageTransformer transformer = - new JsonObjectToTransferSuspensionMessageTransformer(objectMapper); + new JsonObjectToTransferSuspensionMessageTransformer(() -> objectMapper); @Test void shouldTransform() { diff --git a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/model/ApiCoreSchemaTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/model/ApiCoreSchemaTest.java index 340e7adacf3..e3b485bab0e 100644 --- a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/model/ApiCoreSchemaTest.java +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/model/ApiCoreSchemaTest.java @@ -58,7 +58,7 @@ class ApiCoreSchemaTest { void setUp() { transformer.register(new JsonObjectToQuerySpecTransformer()); transformer.register(new JsonObjectToCriterionTransformer()); - transformer.register(new JsonValueToGenericTypeTransformer(objectMapper)); + transformer.register(new JsonValueToGenericTypeTransformer(() -> objectMapper)); transformer.register(new JsonObjectToDataAddressTransformer()); } diff --git a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressTransformerTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressTransformerTest.java index ed09dd96097..cf84fb5ddce 100644 --- a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressTransformerTest.java +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressTransformerTest.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.transform.spi.TransformerContext; import org.eclipse.edc.transform.transformer.edc.to.JsonValueToGenericTypeTransformer; @@ -24,7 +25,6 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.AUTH_CODE_ID; import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.AUTH_KEY; import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.EVENTS; @@ -60,7 +60,7 @@ void transform() { .build(); var contextMock = mock(TransformerContext.class); - var genericTransformer = new JsonValueToGenericTypeTransformer(createObjectMapper()); + var genericTransformer = new JsonValueToGenericTypeTransformer(JacksonJsonLd::createObjectMapper); when(contextMock.transform(any(), eq(String.class))).thenAnswer(a -> genericTransformer.transform(a.getArgument(0), contextMock)); var cba = transformer.transform(jsonLd.expand(jobj).getContent(), contextMock); diff --git a/extensions/common/api/control-api-configuration/src/main/java/org/eclipse/edc/connector/api/control/configuration/ControlApiConfigurationExtension.java b/extensions/common/api/control-api-configuration/src/main/java/org/eclipse/edc/connector/api/control/configuration/ControlApiConfigurationExtension.java index 8b7abd429e7..9dea57a1bd9 100644 --- a/extensions/common/api/control-api-configuration/src/main/java/org/eclipse/edc/connector/api/control/configuration/ControlApiConfigurationExtension.java +++ b/extensions/common/api/control-api-configuration/src/main/java/org/eclipse/edc/connector/api/control/configuration/ControlApiConfigurationExtension.java @@ -15,6 +15,7 @@ package org.eclipse.edc.connector.api.control.configuration; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.edc.api.auth.spi.AuthenticationRequestFilter; import org.eclipse.edc.api.auth.spi.registry.ApiAuthenticationRegistry; import org.eclipse.edc.jsonld.spi.JsonLd; @@ -41,6 +42,7 @@ import java.io.IOException; import java.net.URI; +import java.util.function.Supplier; import java.util.stream.Stream; import static java.lang.String.format; @@ -97,7 +99,7 @@ public String name() { public void initialize(ServiceExtensionContext context) { var portMapping = new PortMapping(ApiContext.CONTROL, apiConfiguration.port(), apiConfiguration.path()); portMappingRegistry.register(portMapping); - var jsonLdMapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); context.registerService(ControlApiUrl.class, controlApiUrl(context, portMapping)); jsonLd.registerNamespace(EDC_PREFIX, EDC_NAMESPACE, CONTROL_SCOPE); @@ -107,8 +109,8 @@ public void initialize(ServiceExtensionContext context) { var authenticationRequestFilter = new AuthenticationRequestFilter(authenticationRegistry, "control-api"); webService.registerResource(ApiContext.CONTROL, authenticationRequestFilter); - webService.registerResource(ApiContext.CONTROL, new ObjectMapperProvider(jsonLdMapper)); - webService.registerResource(ApiContext.CONTROL, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, CONTROL_SCOPE)); + webService.registerResource(ApiContext.CONTROL, new ObjectMapperProvider(objectMapperSupplier)); + webService.registerResource(ApiContext.CONTROL, new JerseyJsonLdInterceptor(jsonLd, objectMapperSupplier, CONTROL_SCOPE)); registerVersionInfo(getClass().getClassLoader()); } @@ -129,7 +131,7 @@ private void registerVersionInfo(ClassLoader resourceClassLoader) { private ControlApiUrl controlApiUrl(ServiceExtensionContext context, PortMapping config) { var callbackAddress = ofNullable(controlEndpoint).orElseGet(() -> format("http://%s:%s%s", hostname.get(), config.port(), config.path())); - + try { var url = URI.create(callbackAddress); return () -> url; diff --git a/extensions/common/api/lib/management-api-lib/src/test/java/org/eclipse/edc/api/management/schema/ManagementApiSchemaTest.java b/extensions/common/api/lib/management-api-lib/src/test/java/org/eclipse/edc/api/management/schema/ManagementApiSchemaTest.java index 9f26709f478..530fa5a363a 100644 --- a/extensions/common/api/lib/management-api-lib/src/test/java/org/eclipse/edc/api/management/schema/ManagementApiSchemaTest.java +++ b/extensions/common/api/lib/management-api-lib/src/test/java/org/eclipse/edc/api/management/schema/ManagementApiSchemaTest.java @@ -63,7 +63,7 @@ class ManagementApiSchemaTest { @BeforeEach void setUp() { transformer.register(new JsonObjectToDataAddressTransformer()); - transformer.register(new JsonValueToGenericTypeTransformer(objectMapper)); + transformer.register(new JsonValueToGenericTypeTransformer(() -> objectMapper)); } @Test diff --git a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java index 822aa0e8c85..eed4c9fd763 100644 --- a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java +++ b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java @@ -15,6 +15,7 @@ package org.eclipse.edc.connector.api.management.configuration; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; import org.eclipse.edc.api.auth.spi.AuthenticationRequestFilter; import org.eclipse.edc.api.auth.spi.registry.ApiAuthenticationRegistry; @@ -57,6 +58,7 @@ import java.io.IOException; import java.net.URI; import java.util.Map; +import java.util.function.Supplier; import java.util.stream.Stream; import static java.lang.String.format; @@ -135,26 +137,26 @@ public void initialize(ServiceExtensionContext context) { jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, MANAGEMENT_SCOPE); } - var jsonLdMapper = typeManager.getMapper(JSON_LD); - webService.registerResource(ApiContext.MANAGEMENT, new ObjectMapperProvider(jsonLdMapper)); - webService.registerResource(ApiContext.MANAGEMENT, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, MANAGEMENT_SCOPE)); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); + webService.registerResource(ApiContext.MANAGEMENT, new ObjectMapperProvider(objectMapperSupplier)); + webService.registerResource(ApiContext.MANAGEMENT, new JerseyJsonLdInterceptor(jsonLd, objectMapperSupplier, MANAGEMENT_SCOPE)); var managementApiTransformerRegistry = transformerRegistry.forContext(MANAGEMENT_API_CONTEXT); var factory = Json.createBuilderFactory(Map.of()); managementApiTransformerRegistry.register(new JsonObjectFromContractAgreementTransformer(factory)); managementApiTransformerRegistry.register(new JsonObjectFromDataAddressTransformer(factory)); - managementApiTransformerRegistry.register(new JsonObjectFromAssetTransformer(factory, jsonLdMapper)); + managementApiTransformerRegistry.register(new JsonObjectFromAssetTransformer(factory, objectMapperSupplier)); managementApiTransformerRegistry.register(new JsonObjectFromPolicyTransformer(factory, participantIdMapper)); managementApiTransformerRegistry.register(new JsonObjectFromQuerySpecTransformer(factory)); - managementApiTransformerRegistry.register(new JsonObjectFromCriterionTransformer(factory, jsonLdMapper)); + managementApiTransformerRegistry.register(new JsonObjectFromCriterionTransformer(factory, objectMapperSupplier)); OdrlTransformersFactory.jsonObjectToOdrlTransformers(participantIdMapper).forEach(managementApiTransformerRegistry::register); managementApiTransformerRegistry.register(new JsonObjectToDataAddressTransformer()); managementApiTransformerRegistry.register(new JsonObjectToQuerySpecTransformer()); managementApiTransformerRegistry.register(new JsonObjectToCriterionTransformer()); managementApiTransformerRegistry.register(new JsonObjectToAssetTransformer()); - managementApiTransformerRegistry.register(new JsonValueToGenericTypeTransformer(jsonLdMapper)); + managementApiTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapperSupplier)); var managementApiTransformerRegistryV4Alpha = managementApiTransformerRegistry.forContext(MANAGEMENT_API_V_4_ALPHA); diff --git a/extensions/common/crypto/jwt-verifiable-credentials/src/main/java/org/eclipse/edc/verifiablecredentials/jwt/JwtPresentationVerifier.java b/extensions/common/crypto/jwt-verifiable-credentials/src/main/java/org/eclipse/edc/verifiablecredentials/jwt/JwtPresentationVerifier.java index 8f82f3deef0..0ea20cd6aeb 100644 --- a/extensions/common/crypto/jwt-verifiable-credentials/src/main/java/org/eclipse/edc/verifiablecredentials/jwt/JwtPresentationVerifier.java +++ b/extensions/common/crypto/jwt-verifiable-credentials/src/main/java/org/eclipse/edc/verifiablecredentials/jwt/JwtPresentationVerifier.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Supplier; /** * Computes the cryptographic integrity of a VerifiablePresentation when it's represented as JWT. Internally, for the actual @@ -68,7 +69,7 @@ public class JwtPresentationVerifier implements CredentialVerifier { public static final String VERIFIABLE_CREDENTIAL_JSON_KEY = "verifiableCredential"; public static final String VP_CLAIM = "vp"; public static final String VC_CLAIM = "vc"; - private final ObjectMapper objectMapper; + private final Supplier objectMapperSupplier; private final TokenValidationService tokenValidationService; private final TokenValidationRulesRegistry tokenValidationRulesRegistry; private final PublicKeyResolver publicKeyResolver; @@ -76,8 +77,8 @@ public class JwtPresentationVerifier implements CredentialVerifier { /** * Verifies the JWT presentation by checking the cryptographic integrity. */ - public JwtPresentationVerifier(ObjectMapper objectMapper, TokenValidationService tokenValidationService, TokenValidationRulesRegistry tokenValidationRulesRegistry, PublicKeyResolver publicKeyResolver) { - this.objectMapper = objectMapper; + public JwtPresentationVerifier(Supplier objectMapperSupplier, TokenValidationService tokenValidationService, TokenValidationRulesRegistry tokenValidationRulesRegistry, PublicKeyResolver publicKeyResolver) { + this.objectMapperSupplier = objectMapperSupplier; this.tokenValidationService = tokenValidationService; this.tokenValidationRulesRegistry = tokenValidationRulesRegistry; this.publicKeyResolver = publicKeyResolver; @@ -177,7 +178,7 @@ private List extractCredentials(Object credentialsObject) { if (credentialsObject instanceof Collection) { return ((Collection) credentialsObject).stream().map(obj -> { try { - return (obj instanceof String) ? obj.toString() : objectMapper.writeValueAsString(obj); + return (obj instanceof String) ? obj.toString() : objectMapperSupplier.get().writeValueAsString(obj); } catch (JsonProcessingException e) { throw new RuntimeException(e); } diff --git a/extensions/common/crypto/jwt-verifiable-credentials/src/test/java/org/eclipse/edc/verifiablecredentials/jwt/JwtPresentationVerifierTest.java b/extensions/common/crypto/jwt-verifiable-credentials/src/test/java/org/eclipse/edc/verifiablecredentials/jwt/JwtPresentationVerifierTest.java index 539edeabfa5..afb6f3c3430 100644 --- a/extensions/common/crypto/jwt-verifiable-credentials/src/test/java/org/eclipse/edc/verifiablecredentials/jwt/JwtPresentationVerifierTest.java +++ b/extensions/common/crypto/jwt-verifiable-credentials/src/test/java/org/eclipse/edc/verifiablecredentials/jwt/JwtPresentationVerifierTest.java @@ -68,7 +68,7 @@ class JwtPresentationVerifierTest { private final TokenValidationService tokenValidationService = new TokenValidationServiceImpl(); private final TokenValidationRulesRegistry ruleRegistry = new TokenValidationRulesRegistryImpl(); private final ObjectMapper mapper = JacksonJsonLd.createObjectMapper(); - private final JwtPresentationVerifier verifier = new JwtPresentationVerifier(mapper, tokenValidationService, ruleRegistry, publicKeyResolverMock); + private final JwtPresentationVerifier verifier = new JwtPresentationVerifier(() -> mapper, tokenValidationService, ruleRegistry, publicKeyResolverMock); private ECKey vpSigningKey; private ECKey vcSigningKey; diff --git a/extensions/common/crypto/ldp-verifiable-credentials/src/main/java/org/eclipse/edc/verifiablecredentials/linkeddata/LdpVerifier.java b/extensions/common/crypto/ldp-verifiable-credentials/src/main/java/org/eclipse/edc/verifiablecredentials/linkeddata/LdpVerifier.java index a332f43c7e0..56102f20cf5 100644 --- a/extensions/common/crypto/ldp-verifiable-credentials/src/main/java/org/eclipse/edc/verifiablecredentials/linkeddata/LdpVerifier.java +++ b/extensions/common/crypto/ldp-verifiable-credentials/src/main/java/org/eclipse/edc/verifiablecredentials/linkeddata/LdpVerifier.java @@ -52,6 +52,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.function.Supplier; import static org.eclipse.edc.spi.result.Result.failure; import static org.eclipse.edc.spi.result.Result.success; @@ -59,7 +60,7 @@ public class LdpVerifier implements CredentialVerifier { private JsonLd jsonLd; - private ObjectMapper jsonLdMapper; + private Supplier objectMapperSupplier; private SignatureSuiteRegistry suiteRegistry; private Map params; private Collection methodResolvers = new ArrayList<>(List.of(new HttpMethodResolver())); @@ -71,7 +72,7 @@ private LdpVerifier() { @Override public boolean canHandle(String rawInput) { - try (var parser = jsonLdMapper.createParser(rawInput)) { + try (var parser = objectMapperSupplier.get().createParser(rawInput)) { parser.nextToken(); return true; } catch (IOException e) { @@ -90,7 +91,7 @@ public boolean canHandle(String rawInput) { public Result verify(String rawInput, VerifierContext verifierContext) { JsonObject jo; try { - jo = jsonLdMapper.readValue(rawInput, JsonObject.class); + jo = objectMapperSupplier.get().readValue(rawInput, JsonObject.class); } catch (JsonProcessingException e) { return failure("Failed to parse JSON: %s".formatted(e.toString())); } @@ -333,8 +334,8 @@ public Builder methodResolver(MethodResolver resolver) { return this; } - public Builder objectMapper(ObjectMapper mapper) { - this.verifier.jsonLdMapper = mapper; + public Builder objectMapperSupplier(Supplier objectMapperSupplier) { + this.verifier.objectMapperSupplier = objectMapperSupplier; return this; } @@ -360,7 +361,7 @@ public Builder loader(DocumentLoader loader) { public LdpVerifier build() { Objects.requireNonNull(this.verifier.jsonLd, "Must have a JsonLD service!"); - Objects.requireNonNull(this.verifier.jsonLdMapper, "Must have an ObjectMapper!"); + Objects.requireNonNull(this.verifier.objectMapperSupplier, "Must have an ObjectMapper!"); Objects.requireNonNull(this.verifier.suiteRegistry, "Must have a Signature registry!"); return this.verifier; } diff --git a/extensions/common/crypto/ldp-verifiable-credentials/src/test/java/org/eclipse/edc/verifiablecredentials/linkeddata/LdpVerifierTest.java b/extensions/common/crypto/ldp-verifiable-credentials/src/test/java/org/eclipse/edc/verifiablecredentials/linkeddata/LdpVerifierTest.java index a8ebcce825e..56a1c58dc04 100644 --- a/extensions/common/crypto/ldp-verifiable-credentials/src/test/java/org/eclipse/edc/verifiablecredentials/linkeddata/LdpVerifierTest.java +++ b/extensions/common/crypto/ldp-verifiable-credentials/src/test/java/org/eclipse/edc/verifiablecredentials/linkeddata/LdpVerifierTest.java @@ -82,7 +82,7 @@ void setUp() throws URISyntaxException { ldpVerifier = LdpVerifier.Builder.newInstance() .signatureSuites(suiteRegistry) .jsonLd(jsonLd) - .objectMapper(mapper) + .objectMapperSupplier(() -> mapper) .methodResolvers(List.of(mockDidResolver)) .loader(testDocLoader) .build(); diff --git a/extensions/common/http/jersey-core/src/main/java/org/eclipse/edc/web/jersey/JerseyRestService.java b/extensions/common/http/jersey-core/src/main/java/org/eclipse/edc/web/jersey/JerseyRestService.java index 030ac2db959..4034d5d8c1e 100644 --- a/extensions/common/http/jersey-core/src/main/java/org/eclipse/edc/web/jersey/JerseyRestService.java +++ b/extensions/common/http/jersey-core/src/main/java/org/eclipse/edc/web/jersey/JerseyRestService.java @@ -101,7 +101,7 @@ private void registerContext(String contextAlias, List controllers) { // In order to use instances with Jersey, the controller types must be registered along with an {@link AbstractBinder} that maps those types to the instances. resourceConfig.registerClasses(controllers.stream().map(Object::getClass).collect(toSet())); resourceConfig.registerInstances(new Binder(controllers)); - resourceConfig.registerInstances(new ObjectMapperProvider(typeManager.getMapper())); + resourceConfig.registerInstances(new ObjectMapperProvider(typeManager::getMapper)); resourceConfig.registerInstances(new EdcApiExceptionMapper()); resourceConfig.registerInstances(new UnexpectedExceptionMapper(monitor)); resourceConfig.registerInstances(new DynamicResourceFeature(dynamicResourcesForContext)); diff --git a/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java b/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java index 3a7a382397a..fbf968bfb38 100644 --- a/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java +++ b/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java @@ -49,7 +49,7 @@ final void startJetty() { portMappings.register(new PortMapping("test", port, "/")); jetty = new JettyService(config, monitor, portMappings); var jerseyService = new JerseyRestService(jetty, new JacksonTypeManager(), mock(JerseyConfiguration.class), monitor); - jerseyService.registerResource("test", new ObjectMapperProvider(objectMapper)); + jerseyService.registerResource("test", new ObjectMapperProvider(() -> objectMapper)); jerseyService.registerResource("test", controller()); var additionalResource = additionalResource(); if (additionalResource != null) { diff --git a/extensions/common/http/lib/jersey-providers-lib/src/main/java/org/eclipse/edc/web/jersey/providers/jsonld/JerseyJsonLdInterceptor.java b/extensions/common/http/lib/jersey-providers-lib/src/main/java/org/eclipse/edc/web/jersey/providers/jsonld/JerseyJsonLdInterceptor.java index d0f47e0a40f..5443442af13 100644 --- a/extensions/common/http/lib/jersey-providers-lib/src/main/java/org/eclipse/edc/web/jersey/providers/jsonld/JerseyJsonLdInterceptor.java +++ b/extensions/common/http/lib/jersey-providers-lib/src/main/java/org/eclipse/edc/web/jersey/providers/jsonld/JerseyJsonLdInterceptor.java @@ -29,19 +29,20 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.function.Supplier; import static jakarta.json.stream.JsonCollectors.toJsonArray; @Provider public class JerseyJsonLdInterceptor implements ReaderInterceptor, WriterInterceptor { private final JsonLd jsonLd; - private final ObjectMapper objectMapper; + private final Supplier objectMapperSupplier; private final String scope; - public JerseyJsonLdInterceptor(JsonLd jsonLd, ObjectMapper objectMapper, String scope) { + public JerseyJsonLdInterceptor(JsonLd jsonLd, Supplier objectMapperSupplier, String scope) { this.jsonLd = jsonLd; - this.objectMapper = objectMapper; + this.objectMapperSupplier = objectMapperSupplier; this.scope = scope; } @@ -50,12 +51,12 @@ public Object aroundReadFrom(ReaderInterceptorContext context) throws IOExceptio if (context.getType().equals(JsonObject.class)) { var bytes = context.getInputStream().readAllBytes(); if (bytes.length > 0) { - var jsonObject = objectMapper.readValue(bytes, JsonObject.class); + var jsonObject = objectMapperSupplier.get().readValue(bytes, JsonObject.class); var expanded = jsonLd.expand(jsonObject) .orElseThrow(f -> new BadRequestException("Failed to expand JsonObject: " + f.getFailureDetail())); - var expandedBytes = objectMapper.writeValueAsBytes(expanded); + var expandedBytes = objectMapperSupplier.get().writeValueAsBytes(expanded); context.setInputStream(new ByteArrayInputStream(expandedBytes)); } } diff --git a/extensions/common/http/lib/jersey-providers-lib/src/main/java/org/eclipse/edc/web/jersey/providers/jsonld/ObjectMapperProvider.java b/extensions/common/http/lib/jersey-providers-lib/src/main/java/org/eclipse/edc/web/jersey/providers/jsonld/ObjectMapperProvider.java index bcb06d22e63..4fd6d92ff33 100644 --- a/extensions/common/http/lib/jersey-providers-lib/src/main/java/org/eclipse/edc/web/jersey/providers/jsonld/ObjectMapperProvider.java +++ b/extensions/common/http/lib/jersey-providers-lib/src/main/java/org/eclipse/edc/web/jersey/providers/jsonld/ObjectMapperProvider.java @@ -17,20 +17,22 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.ws.rs.ext.ContextResolver; +import java.util.function.Supplier; + /** * Provides an ObjectMapper to be used for parsing incoming requests. A custom ObjectMapper that supports the * Jakarta JSON API is required to allow JsonObject as a controller parameter. */ public class ObjectMapperProvider implements ContextResolver { - private final ObjectMapper objectMapper; + private final Supplier objectMapperSupplier; - public ObjectMapperProvider(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; + public ObjectMapperProvider(Supplier objectMapperSupplier) { + this.objectMapperSupplier = objectMapperSupplier; } @Override public ObjectMapper getContext(Class type) { - return objectMapper; + return objectMapperSupplier.get(); } } diff --git a/extensions/common/http/lib/jersey-providers-lib/src/test/java/org/eclipse/edc/web/jersey/providers/jsonld/JerseyJsonLdInterceptorTest.java b/extensions/common/http/lib/jersey-providers-lib/src/test/java/org/eclipse/edc/web/jersey/providers/jsonld/JerseyJsonLdInterceptorTest.java index 84b9997a35f..c8dbf769f41 100644 --- a/extensions/common/http/lib/jersey-providers-lib/src/test/java/org/eclipse/edc/web/jersey/providers/jsonld/JerseyJsonLdInterceptorTest.java +++ b/extensions/common/http/lib/jersey-providers-lib/src/test/java/org/eclipse/edc/web/jersey/providers/jsonld/JerseyJsonLdInterceptorTest.java @@ -44,7 +44,7 @@ class JerseyJsonLdInterceptorTest extends RestControllerTestBase { private static final String SCOPE = "scope"; private final JsonLd jsonLd = mock(); - private final JerseyJsonLdInterceptor interceptor = new JerseyJsonLdInterceptor(jsonLd, objectMapper, SCOPE); + private final JerseyJsonLdInterceptor interceptor = new JerseyJsonLdInterceptor(jsonLd, () -> objectMapper, SCOPE); @Test void expansion_shouldSucceed_whenInputIsJsonObject() { diff --git a/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/IdentityAndTrustExtension.java b/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/IdentityAndTrustExtension.java index 621af09c73c..6aaf8d8c3d4 100644 --- a/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/IdentityAndTrustExtension.java +++ b/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/IdentityAndTrustExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.iam.identitytrust.core; +import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; import org.eclipse.edc.http.spi.EdcHttpClient; import org.eclipse.edc.iam.did.spi.resolution.DidPublicKeyResolver; @@ -69,6 +70,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import static org.eclipse.edc.iam.verifiablecredentials.spi.VcConstants.STATUSLIST_2021_URL; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -78,20 +80,15 @@ public class IdentityAndTrustExtension implements ServiceExtension { public static final long DEFAULT_REVOCATION_CACHE_VALIDITY_MILLIS = 15 * 60 * 1000L; + public static final String DCP_SELF_ISSUED_TOKEN_CONTEXT = "dcp-si"; + public static final String JSON_2020_SIGNATURE_SUITE = "JsonWebSignature2020"; + public static final long DEFAULT_CLEANUP_PERIOD_SECONDS = 60; @Setting(description = "Validity period of cached StatusList2021 credential entries in milliseconds.", defaultValue = DEFAULT_REVOCATION_CACHE_VALIDITY_MILLIS + "", key = "edc.iam.credential.revocation.cache.validity") private long revocationCacheValidity; - @Setting(description = "DID of this connector", key = "edc.iam.issuer.id") private String issuerId; - @Setting(description = "The period of the JTI entry reaper thread in seconds", defaultValue = DEFAULT_CLEANUP_PERIOD_SECONDS + "", key = "edc.sql.store.jti.cleanup.period") private long reaperCleanupPeriod; - - public static final String DCP_SELF_ISSUED_TOKEN_CONTEXT = "dcp-si"; - public static final String JSON_2020_SIGNATURE_SUITE = "JsonWebSignature2020"; - public static final long DEFAULT_CLEANUP_PERIOD_SECONDS = 60; - - @Inject private SecureTokenService secureTokenService; @@ -159,9 +156,6 @@ public void initialize(ServiceExtensionContext context) { // add all rules for validating VerifiableCredential JWTs rulesRegistry.addRule(JWT_VC_TOKEN_CONTEXT, new HasSubjectRule()); - // TODO move in a separated extension? - signatureSuiteRegistry.register(JSON_2020_SIGNATURE_SUITE, new Jws2020SignatureSuite(typeManager.getMapper(JSON_LD))); - try { jsonLd.registerCachedDocument(STATUSLIST_2021_URL, getClass().getClassLoader().getResource("statuslist2021.json").toURI()); @@ -187,6 +181,12 @@ public void shutdown() { jtiEntryReaperThread.cancel(true); } + @Override + public void prepare() { + // TODO move in a separated extension? + signatureSuiteRegistry.register(JSON_2020_SIGNATURE_SUITE, new Jws2020SignatureSuite(typeManager.getMapper(JSON_LD))); + } + @Provider public IdentityService createIdentityService(ServiceExtensionContext context) { var credentialServiceUrlResolver = new DidCredentialServiceUrlResolver(didResolverRegistry); @@ -204,7 +204,7 @@ public IdentityService createIdentityService(ServiceExtensionContext context) { public CredentialServiceClient getCredentialServiceClient(ServiceExtensionContext context) { if (credentialServiceClient == null) { credentialServiceClient = new DefaultCredentialServiceClient(httpClient, Json.createBuilderFactory(Map.of()), - typeManager.getMapper(JSON_LD), typeTransformerRegistry, jsonLd, context.getMonitor()); + () -> typeManager.getMapper(JSON_LD), typeTransformerRegistry, jsonLd, context.getMonitor()); } return credentialServiceClient; } @@ -212,13 +212,13 @@ public CredentialServiceClient getCredentialServiceClient(ServiceExtensionContex @Provider public PresentationVerifier createPresentationVerifier(ServiceExtensionContext context) { if (presentationVerifier == null) { - var mapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); - var jwtVerifier = new JwtPresentationVerifier(mapper, tokenValidationService, rulesRegistry, didPublicKeyResolver); + var jwtVerifier = new JwtPresentationVerifier(objectMapperSupplier, tokenValidationService, rulesRegistry, didPublicKeyResolver); var ldpVerifier = LdpVerifier.Builder.newInstance() .signatureSuites(signatureSuiteRegistry) .jsonLd(jsonLd) - .objectMapper(mapper) + .objectMapperSupplier(objectMapperSupplier) .methodResolver(new DidMethodResolver(didResolverRegistry)) .build(); diff --git a/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/IdentityTrustTransformExtension.java b/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/IdentityTrustTransformExtension.java index bbaa77cd4b3..79c5dd8062b 100644 --- a/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/IdentityTrustTransformExtension.java +++ b/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/IdentityTrustTransformExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.iam.identitytrust.core; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.edc.iam.identitytrust.transform.from.JsonObjectFromPresentationQueryTransformer; import org.eclipse.edc.iam.identitytrust.transform.from.JsonObjectFromPresentationResponseMessageTransformer; import org.eclipse.edc.iam.identitytrust.transform.to.JsonObjectToCredentialStatusTransformer; @@ -38,6 +39,7 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; +import java.util.function.Supplier; import static java.lang.String.format; import static org.eclipse.edc.iam.identitytrust.spi.DcpConstants.DCP_CONTEXT_URL; @@ -69,8 +71,9 @@ public void initialize(ServiceExtensionContext context) { .onSuccess(uri -> jsonLdService.registerCachedDocument(DCP_CONTEXT_URL, uri)) .onFailure(failure -> context.getMonitor().warning("Failed to register cached json-ld document: " + failure.getFailureDetail())); - typeTransformerRegistry.register(new JsonObjectToPresentationQueryTransformer(typeManager.getMapper(JSON_LD))); - typeTransformerRegistry.register(new JsonObjectToPresentationResponseMessageTransformer(typeManager.getMapper(JSON_LD))); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); + typeTransformerRegistry.register(new JsonObjectToPresentationQueryTransformer(objectMapperSupplier)); + typeTransformerRegistry.register(new JsonObjectToPresentationResponseMessageTransformer(objectMapperSupplier)); typeTransformerRegistry.register(new JsonObjectFromPresentationQueryTransformer()); typeTransformerRegistry.register(new JsonObjectFromPresentationResponseMessageTransformer()); typeTransformerRegistry.register(new JsonObjectToVerifiablePresentationTransformer()); @@ -78,7 +81,7 @@ public void initialize(ServiceExtensionContext context) { typeTransformerRegistry.register(new JsonObjectToIssuerTransformer()); typeTransformerRegistry.register(new JsonObjectToCredentialSubjectTransformer()); typeTransformerRegistry.register(new JsonObjectToCredentialStatusTransformer()); - typeTransformerRegistry.register(new JwtToVerifiablePresentationTransformer(context.getMonitor(), typeManager.getMapper(JSON_LD), jsonLdService)); + typeTransformerRegistry.register(new JwtToVerifiablePresentationTransformer(context.getMonitor(), objectMapperSupplier, jsonLdService)); typeTransformerRegistry.register(new JwtToVerifiableCredentialTransformer(context.getMonitor())); } diff --git a/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/defaults/DefaultCredentialServiceClient.java b/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/defaults/DefaultCredentialServiceClient.java index fcc285f928f..8e9e7558a44 100644 --- a/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/defaults/DefaultCredentialServiceClient.java +++ b/extensions/common/iam/identity-trust/identity-trust-core/src/main/java/org/eclipse/edc/iam/identitytrust/core/defaults/DefaultCredentialServiceClient.java @@ -15,7 +15,6 @@ package org.eclipse.edc.iam.identitytrust.core.defaults; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; @@ -42,6 +41,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.function.Supplier; import java.util.stream.Collectors; import static org.eclipse.edc.spi.result.Result.failure; @@ -51,15 +51,15 @@ public class DefaultCredentialServiceClient implements CredentialServiceClient { public static final String PRESENTATION_ENDPOINT = "/presentations/query"; private final EdcHttpClient httpClient; private final JsonBuilderFactory jsonFactory; - private final ObjectMapper objectMapper; + private final Supplier objectMapperSupplier; private final TypeTransformerRegistry transformerRegistry; private final JsonLd jsonLd; private final Monitor monitor; - public DefaultCredentialServiceClient(EdcHttpClient httpClient, JsonBuilderFactory jsonFactory, ObjectMapper jsonLdMapper, TypeTransformerRegistry transformerRegistry, JsonLd jsonLd, Monitor monitor) { + public DefaultCredentialServiceClient(EdcHttpClient httpClient, JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier, TypeTransformerRegistry transformerRegistry, JsonLd jsonLd, Monitor monitor) { this.httpClient = httpClient; this.jsonFactory = jsonFactory; - this.objectMapper = jsonLdMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + this.objectMapperSupplier = objectMapperSupplier; this.transformerRegistry = transformerRegistry; this.jsonLd = jsonLd; this.monitor = monitor; @@ -72,7 +72,7 @@ public Result> requestPresentation(String var url = credentialServiceBaseUrl + PRESENTATION_ENDPOINT; try { - var requestJson = objectMapper.writeValueAsString(query); + var requestJson = objectMapperSupplier.get().writeValueAsString(query); var request = new Request.Builder() .post(RequestBody.create(requestJson, MediaType.parse("application/json"))) .url(url) @@ -87,7 +87,7 @@ public Result> requestPresentation(String } if (response.isSuccessful() && response.body() != null) { - var presentationResponse = objectMapper.readValue(body, JsonObject.class); + var presentationResponse = objectMapperSupplier.get().readValue(body, JsonObject.class); return parseResponse(presentationResponse); } return failure("Presentation Query failed: HTTP %s, message: %s".formatted(response.code(), body)); @@ -130,7 +130,7 @@ private Result parseVpToken(Object vpObj) { } private Result parseLdpVp(Object vpObj) { - var jsonObj = objectMapper.convertValue(vpObj, JsonObject.class); + var jsonObj = objectMapperSupplier.get().convertValue(vpObj, JsonObject.class); var rawStr = jsonObj.toString(); return jsonLd.expand(jsonObj) diff --git a/extensions/common/iam/identity-trust/identity-trust-core/src/test/java/org/eclipse/edc/iam/identitytrust/core/defaults/DefaultCredentialServiceClientTest.java b/extensions/common/iam/identity-trust/identity-trust-core/src/test/java/org/eclipse/edc/iam/identitytrust/core/defaults/DefaultCredentialServiceClientTest.java index 29b47aa11fa..12fbc90753f 100644 --- a/extensions/common/iam/identity-trust/identity-trust-core/src/test/java/org/eclipse/edc/iam/identitytrust/core/defaults/DefaultCredentialServiceClientTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-core/src/test/java/org/eclipse/edc/iam/identitytrust/core/defaults/DefaultCredentialServiceClientTest.java @@ -55,7 +55,6 @@ import java.util.Objects; import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.junit.testfixtures.TestUtils.getResourceFileContentAsString; import static org.eclipse.edc.spi.result.Result.success; import static org.mockito.ArgumentMatchers.any; @@ -75,6 +74,17 @@ class DefaultCredentialServiceClientTest { private DefaultCredentialServiceClient client; private TypeTransformerRegistry transformerRegistry; + private static VerifiableCredential.Builder createCredential() { + return VerifiableCredential.Builder.newInstance() + .issuer(new Issuer("test-issuer", Map.of())) + .type("VerifiableCredential") + .issuanceDate(Instant.now()) + .credentialSubject(CredentialSubject.Builder.newInstance() + .id("test-subject") + .claim("foo", "bar") + .build()); + } + @BeforeEach void setup() { transformerRegistry = mock(TypeTransformerRegistry.class); @@ -85,7 +95,7 @@ void setup() { var jsonLdMock = mock(JsonLd.class); when(jsonLdMock.expand(any())).thenAnswer(a -> success(a.getArgument(0))); client = new DefaultCredentialServiceClient(httpClientMock, Json.createBuilderFactory(Map.of()), - createObjectMapper(), transformerRegistry, jsonLdMock, mock()); + JacksonJsonLd::createObjectMapper, transformerRegistry, jsonLdMock, mock()); } @Test @@ -102,6 +112,51 @@ void requestPresentation_sendScopes() throws IOException { verify(httpClientMock).execute(argThat((r) -> containsScope(r, scopes))); } + @SuppressWarnings("unchecked") + private boolean containsScope(Request request, List scopes) { + + try (var buffer = new Buffer()) { + Objects.requireNonNull(request.body()).writeTo(buffer); + var body = mapper.readValue(buffer.inputStream(), new TypeReference>() { + + }); + var requestScopes = (Collection) body.get("scope"); + + return requestScopes.containsAll(scopes); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private VerifiablePresentation.Builder createPresentation() { + return VerifiablePresentation.Builder.newInstance() + .type("VerifiablePresentation") + .credential(createCredential().build()); + } + + private Result presentationResponse(InvocationOnMock args) { + try { + var response = mapper.readValue(args.getArgument(0, JsonObject.class).toString(), PresentationResponseMessage.class); + return Result.success(response); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + private Response response(int code, String body) { + return new Response.Builder() + .request(mock()) + .protocol(Protocol.HTTP_2) + .code(code) // status code + .message("") + .body(ResponseBody.create( + body, + MediaType.get("application/json; charset=utf-8") + )) + .build(); + } + @Nested class VcDataModel11 { @Test @@ -257,61 +312,5 @@ void requestPresentation_noCredentials() throws IOException { } } - @SuppressWarnings("unchecked") - private boolean containsScope(Request request, List scopes) { - - try (var buffer = new Buffer()) { - Objects.requireNonNull(request.body()).writeTo(buffer); - var body = mapper.readValue(buffer.inputStream(), new TypeReference>() { - - }); - var requestScopes = (Collection) body.get("scope"); - - return requestScopes.containsAll(scopes); - - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private VerifiablePresentation.Builder createPresentation() { - return VerifiablePresentation.Builder.newInstance() - .type("VerifiablePresentation") - .credential(createCredential().build()); - } - - private static VerifiableCredential.Builder createCredential() { - return VerifiableCredential.Builder.newInstance() - .issuer(new Issuer("test-issuer", Map.of())) - .type("VerifiableCredential") - .issuanceDate(Instant.now()) - .credentialSubject(CredentialSubject.Builder.newInstance() - .id("test-subject") - .claim("foo", "bar") - .build()); - } - - private Result presentationResponse(InvocationOnMock args) { - try { - var response = mapper.readValue(args.getArgument(0, JsonObject.class).toString(), PresentationResponseMessage.class); - return Result.success(response); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - - private Response response(int code, String body) { - return new Response.Builder() - .request(mock()) - .protocol(Protocol.HTTP_2) - .code(code) // status code - .message("") - .body(ResponseBody.create( - body, - MediaType.get("application/json; charset=utf-8") - )) - .build(); - } - } \ No newline at end of file diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/service/verification/MultiFormatPresentationVerifierTest.java b/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/service/verification/MultiFormatPresentationVerifierTest.java index d2f789bb0d7..9185eac095c 100644 --- a/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/service/verification/MultiFormatPresentationVerifierTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/service/verification/MultiFormatPresentationVerifierTest.java @@ -116,10 +116,10 @@ void setup() { var ldpVerifier = LdpVerifier.Builder.newInstance() .signatureSuites(SIGNATURE_SUITE_REGISTRY) .jsonLd(jsonLd) - .objectMapper(MAPPER) + .objectMapperSupplier(() -> MAPPER) .build(); - var jwtPresentationVerifier = new JwtPresentationVerifier(MAPPER, tokenValidationService, mock(), publicKeyResolverMock); + var jwtPresentationVerifier = new JwtPresentationVerifier(() -> MAPPER, tokenValidationService, mock(), publicKeyResolverMock); multiFormatVerifier = new MultiFormatPresentationVerifier(MY_OWN_DID, jwtPresentationVerifier, ldpVerifier); } diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationQueryTransformer.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationQueryTransformer.java index 183bdc62cba..ed01adfa731 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationQueryTransformer.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationQueryTransformer.java @@ -28,17 +28,18 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.function.Supplier; /** * Transforms a JsonObject into a PresentationQuery object. */ public class JsonObjectToPresentationQueryTransformer extends AbstractJsonLdTransformer { - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonObjectToPresentationQueryTransformer(ObjectMapper mapper) { + public JsonObjectToPresentationQueryTransformer(Supplier objectMapperSupplier) { super(JsonObject.class, PresentationQueryMessage.class); - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -66,7 +67,7 @@ private PresentationDefinition readPresentationDefinition(JsonValue v, Transform } var rawJson = jo.get(JsonLdKeywords.VALUE); try { - return mapper.readValue(rawJson.toString(), PresentationDefinition.class); + return objectMapperSupplier.get().readValue(rawJson.toString(), PresentationDefinition.class); } catch (JsonProcessingException e) { context.reportProblem("Error reading JSON literal: %s".formatted(e.getMessage())); return null; diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationResponseMessageTransformer.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationResponseMessageTransformer.java index 21ddc29058b..6e737bfea5a 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationResponseMessageTransformer.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationResponseMessageTransformer.java @@ -16,7 +16,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.JsonArray; import jakarta.json.JsonObject; @@ -30,17 +29,18 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.function.Supplier; /** * Transforms a {@link JsonObject} into a {@link PresentationResponseMessage} object. */ public class JsonObjectToPresentationResponseMessageTransformer extends AbstractJsonLdTransformer { - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonObjectToPresentationResponseMessageTransformer(ObjectMapper mapper) { + public JsonObjectToPresentationResponseMessageTransformer(Supplier objectMapperSupplier) { super(JsonObject.class, PresentationResponseMessage.class); - this.mapper = mapper.copy().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -62,7 +62,7 @@ public JsonObjectToPresentationResponseMessageTransformer(ObjectMapper mapper) { private PresentationSubmission readPresentationSubmission(JsonValue v, TransformerContext context) { var rawJson = getRawJsonValue(v); try { - return mapper.readValue(rawJson.toString(), PresentationSubmission.class); + return objectMapperSupplier.get().readValue(rawJson.toString(), PresentationSubmission.class); } catch (JsonProcessingException e) { context.reportProblem("Error reading JSON literal: %s".formatted(e.getMessage())); return null; @@ -73,7 +73,7 @@ private PresentationSubmission readPresentationSubmission(JsonValue v, Transform private List readPresentation(JsonValue v, TransformerContext context) { var rawJson = getRawJsonValue(v); try { - return mapper.readValue(rawJson.toString(), new TypeReference<>() { + return objectMapperSupplier.get().readValue(rawJson.toString(), new TypeReference<>() { }); } catch (JsonProcessingException e) { context.reportProblem("Error reading JSON literal: %s".formatted(e.getMessage())); diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JwtToVerifiablePresentationTransformer.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JwtToVerifiablePresentationTransformer.java index 84bb2ae6267..6e10e758033 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JwtToVerifiablePresentationTransformer.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/main/java/org/eclipse/edc/iam/identitytrust/transform/to/JwtToVerifiablePresentationTransformer.java @@ -31,6 +31,7 @@ import java.text.ParseException; import java.util.Map; +import java.util.function.Supplier; @SuppressWarnings("unchecked") public class JwtToVerifiablePresentationTransformer extends AbstractJwtTransformer { @@ -42,13 +43,13 @@ public class JwtToVerifiablePresentationTransformer extends AbstractJwtTransform private static final String DATA_URL_VC_JWT = "data:application/vc+jwt,"; private final Monitor monitor; - private final ObjectMapper objectMapper; + private final Supplier objectMapperSupplier; private final JsonLd jsonLd; - public JwtToVerifiablePresentationTransformer(Monitor monitor, ObjectMapper objectMapper, JsonLd jsonLd) { + public JwtToVerifiablePresentationTransformer(Monitor monitor, Supplier objectMapperSupplier, JsonLd jsonLd) { super(VerifiablePresentation.class); this.monitor = monitor; - this.objectMapper = objectMapper; + this.objectMapperSupplier = objectMapperSupplier; this.jsonLd = jsonLd; } @@ -67,7 +68,7 @@ public JwtToVerifiablePresentationTransformer(Monitor monitor, ObjectMapper obje builder.id(claimsSet.getJWTID()); if (vpObject instanceof String) { - vpObject = objectMapper.readValue(vpObject.toString(), Map.class); + vpObject = objectMapperSupplier.get().readValue(vpObject.toString(), Map.class); } if (vpObject instanceof Map vp) { @@ -150,7 +151,7 @@ private VerifiableCredential extractCredentials(Object credential, TransformerCo return context.transform(credential.toString(), VerifiableCredential.class); } // VC is LDP - var input = objectMapper.convertValue(credential, JsonObject.class); + var input = objectMapperSupplier.get().convertValue(credential, JsonObject.class); var expansion = jsonLd.expand(input); if (expansion.succeeded()) { return context.transform(expansion.getContent(), VerifiableCredential.class); diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/serde/PresentationResponseMessageSerdeTest.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/serde/PresentationResponseMessageSerdeTest.java index ed2c06480d3..edcaf59e62e 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/serde/PresentationResponseMessageSerdeTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/serde/PresentationResponseMessageSerdeTest.java @@ -44,7 +44,7 @@ public class PresentationResponseMessageSerdeTest { private final TypeTransformerRegistry trr = new TypeTransformerRegistryImpl(); private final TransformerContext context = new TransformerContextImpl(trr); private final JsonObjectFromPresentationResponseMessageTransformer fromTransformer = new JsonObjectFromPresentationResponseMessageTransformer(); - private final JsonObjectToPresentationResponseMessageTransformer toTransformer = new JsonObjectToPresentationResponseMessageTransformer(mapper); + private final JsonObjectToPresentationResponseMessageTransformer toTransformer = new JsonObjectToPresentationResponseMessageTransformer(() -> mapper); @BeforeEach void setUp() { @@ -53,7 +53,7 @@ void setUp() { jsonLd.registerContext(DCP_CONTEXT_URL); // delegate to the generic transformer - trr.register(new JsonValueToGenericTypeTransformer(mapper)); + trr.register(new JsonValueToGenericTypeTransformer(() -> mapper)); } diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationQueryMessageTransformerTest.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationQueryMessageTransformerTest.java index c2ad3d26143..c5a70323931 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationQueryMessageTransformerTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationQueryMessageTransformerTest.java @@ -35,7 +35,7 @@ class JsonObjectToPresentationQueryMessageTransformerTest { private final ObjectMapper mapper = JacksonJsonLd.createObjectMapper(); - private final JsonObjectToPresentationQueryTransformer transformer = new JsonObjectToPresentationQueryTransformer(mapper); + private final JsonObjectToPresentationQueryTransformer transformer = new JsonObjectToPresentationQueryTransformer(() -> mapper); private final JsonLd jsonLd = new TitaniumJsonLd(mock()); private final TypeTransformerRegistry trr = new TypeTransformerRegistryImpl(); private final TransformerContext context = new TransformerContextImpl(trr); @@ -47,7 +47,7 @@ void setUp() { jsonLd.registerCachedDocument(DCP_CONTEXT_URL, TestUtils.getFileFromResourceName("document/dcp.v08.jsonld").toURI()); // delegate to the generic transformer - trr.register(new JsonValueToGenericTypeTransformer(mapper)); + trr.register(new JsonValueToGenericTypeTransformer(() -> mapper)); } @Test diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationResponseMessageTransformerTest.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationResponseMessageTransformerTest.java index d4982dd666d..3e519fdc82d 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationResponseMessageTransformerTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToPresentationResponseMessageTransformerTest.java @@ -37,7 +37,7 @@ class JsonObjectToPresentationResponseMessageTransformerTest { private final ObjectMapper mapper = JacksonJsonLd.createObjectMapper(); - private final JsonObjectToPresentationResponseMessageTransformer transformer = new JsonObjectToPresentationResponseMessageTransformer(mapper); + private final JsonObjectToPresentationResponseMessageTransformer transformer = new JsonObjectToPresentationResponseMessageTransformer(() -> mapper); private final JsonLd jsonLd = new TitaniumJsonLd(mock()); private final TypeTransformerRegistry trr = new TypeTransformerRegistryImpl(); private final TransformerContext context = new TransformerContextImpl(trr); @@ -48,7 +48,7 @@ void setUp() { jsonLd.registerCachedDocument(DCP_CONTEXT_URL, TestUtils.getFileFromResourceName("document/dcp.v08.jsonld").toURI()); // delegate to the generic transformer - trr.register(new JsonValueToGenericTypeTransformer(mapper)); + trr.register(new JsonValueToGenericTypeTransformer(() -> mapper)); } @Test diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToVerifiableCredentialTransformerTest.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToVerifiableCredentialTransformerTest.java index 89f01439542..2f183fcae18 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToVerifiableCredentialTransformerTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToVerifiableCredentialTransformerTest.java @@ -52,7 +52,7 @@ void setUp() throws URISyntaxException { var registry = new TypeTransformerRegistryImpl(); registry.register(new JsonObjectToCredentialSubjectTransformer()); registry.register(new JsonObjectToCredentialStatusTransformer()); - registry.register(new JsonValueToGenericTypeTransformer(OBJECT_MAPPER)); + registry.register(new JsonValueToGenericTypeTransformer(() -> OBJECT_MAPPER)); registry.register(new JsonObjectToIssuerTransformer()); registry.register(transformer); diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToVerifiablePresentationTransformerTest.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToVerifiablePresentationTransformerTest.java index 56bf7516ada..ad53176bf64 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToVerifiablePresentationTransformerTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JsonObjectToVerifiablePresentationTransformerTest.java @@ -52,7 +52,7 @@ void setup() throws URISyntaxException { registry.register(new JsonObjectToCredentialStatusTransformer()); registry.register(new JsonObjectToVerifiableCredentialTransformer()); registry.register(new JsonObjectToIssuerTransformer()); - registry.register(new JsonValueToGenericTypeTransformer(OBJECT_MAPPER)); + registry.register(new JsonValueToGenericTypeTransformer(() -> OBJECT_MAPPER)); registry.register(transformer); context = spy(new TransformerContextImpl(registry)); diff --git a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JwtToVerifiablePresentationTransformerTest.java b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JwtToVerifiablePresentationTransformerTest.java index e7fda5d8548..626d1384575 100644 --- a/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JwtToVerifiablePresentationTransformerTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-transform/src/test/java/org/eclipse/edc/iam/identitytrust/transform/to/JwtToVerifiablePresentationTransformerTest.java @@ -58,7 +58,7 @@ class JwtToVerifiablePresentationTransformerTest { private final Monitor monitor = mock(); private final JwtToVerifiableCredentialTransformer credentialTransformer = new JwtToVerifiableCredentialTransformer(monitor); private final JsonLd jsonLd = mock(); - private final JwtToVerifiablePresentationTransformer transformer = new JwtToVerifiablePresentationTransformer(monitor, MAPPER, jsonLd); + private final JwtToVerifiablePresentationTransformer transformer = new JwtToVerifiablePresentationTransformer(monitor, () -> MAPPER, jsonLd); @BeforeEach void setup() { diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/asset/v3/AssetApiTest.java b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/asset/v3/AssetApiTest.java index 7742de1bcb2..0127325d5a9 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/asset/v3/AssetApiTest.java +++ b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/asset/v3/AssetApiTest.java @@ -49,7 +49,7 @@ class AssetApiTest { @BeforeEach void setUp() { transformer.register(new JsonObjectToAssetTransformer()); - transformer.register(new JsonValueToGenericTypeTransformer(objectMapper)); + transformer.register(new JsonValueToGenericTypeTransformer(() -> objectMapper)); transformer.register(new JsonObjectToDataAddressTransformer()); } diff --git a/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/ContractDefinitionApiExtension.java b/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/ContractDefinitionApiExtension.java index 71cc9391a2a..b8c4db0c6a0 100644 --- a/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/ContractDefinitionApiExtension.java +++ b/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/ContractDefinitionApiExtension.java @@ -69,8 +69,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { var jsonFactory = Json.createBuilderFactory(Map.of()); - var mapper = typeManager.getMapper(JSON_LD); - transformerRegistry.register(new JsonObjectFromContractDefinitionTransformer(jsonFactory, mapper)); + transformerRegistry.register(new JsonObjectFromContractDefinitionTransformer(jsonFactory, () -> typeManager.getMapper(JSON_LD))); transformerRegistry.register(new JsonObjectToContractDefinitionTransformer()); validatorRegistry.register(CONTRACT_DEFINITION_TYPE, ContractDefinitionValidator.instance(criterionOperatorRegistry)); diff --git a/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/transform/JsonObjectFromContractDefinitionTransformer.java b/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/transform/JsonObjectFromContractDefinitionTransformer.java index 6bbb3bac58a..546ef8f6262 100644 --- a/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/transform/JsonObjectFromContractDefinitionTransformer.java +++ b/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/transform/JsonObjectFromContractDefinitionTransformer.java @@ -24,6 +24,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Supplier; + import static jakarta.json.stream.JsonCollectors.toJsonArray; import static org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition.CONTRACT_DEFINITION_ACCESSPOLICY_ID; import static org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition.CONTRACT_DEFINITION_ASSETS_SELECTOR; @@ -33,13 +35,13 @@ import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; public class JsonObjectFromContractDefinitionTransformer extends AbstractJsonLdTransformer { - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; private final JsonBuilderFactory jsonFactory; - public JsonObjectFromContractDefinitionTransformer(JsonBuilderFactory jsonFactory, ObjectMapper jsonLdMapper) { + public JsonObjectFromContractDefinitionTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { super(ContractDefinition.class, JsonObject.class); this.jsonFactory = jsonFactory; - this.mapper = jsonLdMapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -57,7 +59,7 @@ public JsonObjectFromContractDefinitionTransformer(JsonBuilderFactory jsonFactor if (!contractDefinition.getPrivateProperties().isEmpty()) { var privatePropBuilder = jsonFactory.createObjectBuilder(); - transformProperties(contractDefinition.getPrivateProperties(), privatePropBuilder, mapper, context); + transformProperties(contractDefinition.getPrivateProperties(), privatePropBuilder, objectMapperSupplier.get(), context); builder.add(ContractDefinition.CONTRACT_DEFINITION_PRIVATE_PROPERTIES, privatePropBuilder); } diff --git a/extensions/control-plane/api/management-api/contract-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/transform/JsonObjectFromContractDefinitionTransformerTest.java b/extensions/control-plane/api/management-api/contract-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/transform/JsonObjectFromContractDefinitionTransformerTest.java index 6b5a79d5f66..223ca730749 100644 --- a/extensions/control-plane/api/management-api/contract-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/transform/JsonObjectFromContractDefinitionTransformerTest.java +++ b/extensions/control-plane/api/management-api/contract-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/contractdefinition/transform/JsonObjectFromContractDefinitionTransformerTest.java @@ -19,6 +19,7 @@ import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.spi.query.Criterion; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.Test; @@ -34,7 +35,6 @@ import static org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition.CONTRACT_DEFINITION_TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.spi.query.Criterion.criterion; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -49,7 +49,7 @@ class JsonObjectFromContractDefinitionTransformerTest { private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); private final TransformerContext context = mock(TransformerContext.class); - private final JsonObjectFromContractDefinitionTransformer transformer = new JsonObjectFromContractDefinitionTransformer(jsonFactory, createObjectMapper()); + private final JsonObjectFromContractDefinitionTransformer transformer = new JsonObjectFromContractDefinitionTransformer(jsonFactory, JacksonJsonLd::createObjectMapper); @Test void transform() { diff --git a/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/PolicyDefinitionApiExtension.java b/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/PolicyDefinitionApiExtension.java index 29e74df099d..73d848b7177 100644 --- a/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/PolicyDefinitionApiExtension.java +++ b/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/PolicyDefinitionApiExtension.java @@ -71,10 +71,9 @@ public String name() { public void initialize(ServiceExtensionContext context) { var jsonBuilderFactory = Json.createBuilderFactory(Map.of()); var managementApiTransformerRegistry = transformerRegistry.forContext("management-api"); - var mapper = typeManager.getMapper(JSON_LD); managementApiTransformerRegistry.register(new JsonObjectToPolicyEvaluationPlanRequestTransformer()); managementApiTransformerRegistry.register(new JsonObjectToPolicyDefinitionTransformer()); - managementApiTransformerRegistry.register(new JsonObjectFromPolicyDefinitionTransformer(jsonBuilderFactory, mapper)); + managementApiTransformerRegistry.register(new JsonObjectFromPolicyDefinitionTransformer(jsonBuilderFactory, () -> typeManager.getMapper(JSON_LD))); managementApiTransformerRegistry.register(new JsonObjectFromPolicyValidationResultTransformer(jsonBuilderFactory)); managementApiTransformerRegistry.register(new JsonObjectFromPolicyEvaluationPlanTransformer(jsonBuilderFactory)); diff --git a/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyDefinitionTransformer.java b/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyDefinitionTransformer.java index 33420b7fa8d..6aaab951a38 100644 --- a/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyDefinitionTransformer.java +++ b/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyDefinitionTransformer.java @@ -23,6 +23,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Supplier; + import static org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition.EDC_POLICY_DEFINITION_POLICY; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; @@ -30,13 +32,13 @@ public class JsonObjectFromPolicyDefinitionTransformer extends AbstractJsonLdTransformer { - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; private final JsonBuilderFactory jsonFactory; - public JsonObjectFromPolicyDefinitionTransformer(JsonBuilderFactory jsonFactory, ObjectMapper jsonLdMapper) { + public JsonObjectFromPolicyDefinitionTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { super(PolicyDefinition.class, JsonObject.class); this.jsonFactory = jsonFactory; - this.mapper = jsonLdMapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override @@ -51,7 +53,7 @@ public JsonObjectFromPolicyDefinitionTransformer(JsonBuilderFactory jsonFactory, objectBuilder.add(EDC_POLICY_DEFINITION_POLICY, policy); if (!input.getPrivateProperties().isEmpty()) { var privatePropBuilder = jsonFactory.createObjectBuilder(); - transformProperties(input.getPrivateProperties(), privatePropBuilder, mapper, context); + transformProperties(input.getPrivateProperties(), privatePropBuilder, objectMapperSupplier.get(), context); objectBuilder.add(PolicyDefinition.EDC_POLICY_DEFINITION_PRIVATE_PROPERTIES, privatePropBuilder); } diff --git a/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyDefinitionTransformerTest.java b/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyDefinitionTransformerTest.java index e6b95243374..37420268a3b 100644 --- a/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyDefinitionTransformerTest.java +++ b/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyDefinitionTransformerTest.java @@ -18,6 +18,7 @@ import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.Test; @@ -31,7 +32,6 @@ import static org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition.EDC_POLICY_DEFINITION_TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -40,7 +40,7 @@ class JsonObjectFromPolicyDefinitionTransformerTest { - private final JsonObjectFromPolicyDefinitionTransformer transformer = new JsonObjectFromPolicyDefinitionTransformer(Json.createBuilderFactory(emptyMap()), createObjectMapper()); + private final JsonObjectFromPolicyDefinitionTransformer transformer = new JsonObjectFromPolicyDefinitionTransformer(Json.createBuilderFactory(emptyMap()), JacksonJsonLd::createObjectMapper); private final TransformerContext context = mock(TransformerContext.class); diff --git a/extensions/control-plane/api/management-api/secrets-api/src/test/java/org/eclipse/edc/connector/api/management/secret/SecretsApiTest.java b/extensions/control-plane/api/management-api/secrets-api/src/test/java/org/eclipse/edc/connector/api/management/secret/SecretsApiTest.java index 5b78a7ce117..487200a434d 100644 --- a/extensions/control-plane/api/management-api/secrets-api/src/test/java/org/eclipse/edc/connector/api/management/secret/SecretsApiTest.java +++ b/extensions/control-plane/api/management-api/secrets-api/src/test/java/org/eclipse/edc/connector/api/management/secret/SecretsApiTest.java @@ -48,7 +48,7 @@ class SecretsApiTest { @BeforeEach void setUp() { transformer.register(new JsonObjectToSecretTransformer()); - transformer.register(new JsonValueToGenericTypeTransformer(objectMapper)); + transformer.register(new JsonValueToGenericTypeTransformer(() -> objectMapper)); } @Test diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/transferprocess/TransferProcessApiTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/transferprocess/TransferProcessApiTest.java index ae7c1d1f558..e619b7ebe83 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/transferprocess/TransferProcessApiTest.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/transferprocess/TransferProcessApiTest.java @@ -78,7 +78,7 @@ void setUp() { transformer.register(new JsonObjectToDataAddressTransformer()); transformer.register(new JsonObjectToTerminateTransferTransformer()); transformer.register(new JsonObjectToSuspendTransferTransformer()); - transformer.register(new JsonValueToGenericTypeTransformer(objectMapper)); + transformer.register(new JsonValueToGenericTypeTransformer(() -> objectMapper)); } @Test diff --git a/extensions/data-plane-selector/data-plane-selector-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorApiExtension.java b/extensions/data-plane-selector/data-plane-selector-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorApiExtension.java index 3928592a3f8..f467ffa1cab 100644 --- a/extensions/data-plane-selector/data-plane-selector-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorApiExtension.java +++ b/extensions/data-plane-selector/data-plane-selector-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorApiExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.connector.dataplane.selector; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.edc.connector.dataplane.selector.api.v3.DataplaneSelectorApiV3Controller; import org.eclipse.edc.connector.dataplane.selector.api.v4.DataplaneSelectorApiV4Controller; import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; @@ -29,6 +30,7 @@ import org.eclipse.edc.web.spi.configuration.ApiContext; import java.util.Map; +import java.util.function.Supplier; import static jakarta.json.Json.createBuilderFactory; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -52,13 +54,14 @@ public class DataPlaneSelectorApiExtension implements ServiceExtension { public void initialize(ServiceExtensionContext context) { var managementApiTransformerRegistry = transformerRegistry.forContext("management-api"); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); // V4 - managementApiTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), typeManager.getMapper(JSON_LD))); + managementApiTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), objectMapperSupplier)); webservice.registerResource(ApiContext.MANAGEMENT, new DataplaneSelectorApiV4Controller(selectionService, managementApiTransformerRegistry)); // V3 var managementApiTransformerRegistryV3 = managementApiTransformerRegistry.forContext("v3"); - managementApiTransformerRegistryV3.register(new JsonObjectFromDataPlaneInstanceV3Transformer(createBuilderFactory(Map.of()), typeManager.getMapper(JSON_LD))); + managementApiTransformerRegistryV3.register(new JsonObjectFromDataPlaneInstanceV3Transformer(createBuilderFactory(Map.of()), objectMapperSupplier)); webservice.registerResource(ApiContext.MANAGEMENT, new DataplaneSelectorApiV3Controller(selectionService, managementApiTransformerRegistryV3)); } diff --git a/extensions/data-plane-selector/data-plane-selector-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/api/v3/DataPlaneApiSelectorV3Test.java b/extensions/data-plane-selector/data-plane-selector-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/api/v3/DataPlaneApiSelectorV3Test.java index a9d362b7431..f266040a20f 100644 --- a/extensions/data-plane-selector/data-plane-selector-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/api/v3/DataPlaneApiSelectorV3Test.java +++ b/extensions/data-plane-selector/data-plane-selector-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/api/v3/DataPlaneApiSelectorV3Test.java @@ -44,7 +44,7 @@ public class DataPlaneApiSelectorV3Test { void setUp() { transformer.register(new JsonObjectToDataPlaneInstanceTransformer()); transformer.register(new JsonObjectToDataAddressTransformer()); - transformer.register(new JsonValueToGenericTypeTransformer(objectMapper)); + transformer.register(new JsonValueToGenericTypeTransformer(() -> objectMapper)); } @Test diff --git a/extensions/data-plane-selector/data-plane-selector-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/api/v4/DataPlaneApiSelectorV4Test.java b/extensions/data-plane-selector/data-plane-selector-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/api/v4/DataPlaneApiSelectorV4Test.java index 36c4e96f729..24e0f2448bd 100644 --- a/extensions/data-plane-selector/data-plane-selector-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/api/v4/DataPlaneApiSelectorV4Test.java +++ b/extensions/data-plane-selector/data-plane-selector-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/api/v4/DataPlaneApiSelectorV4Test.java @@ -44,7 +44,7 @@ public class DataPlaneApiSelectorV4Test { void setUp() { transformer.register(new JsonObjectToDataPlaneInstanceTransformer()); transformer.register(new JsonObjectToDataAddressTransformer()); - transformer.register(new JsonValueToGenericTypeTransformer(objectMapper)); + transformer.register(new JsonValueToGenericTypeTransformer(() -> objectMapper)); } @Test diff --git a/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorClientExtension.java b/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorClientExtension.java index b6a3c652143..8d9b3654f4e 100644 --- a/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorClientExtension.java +++ b/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorClientExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.connector.dataplane.selector; +import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; import org.eclipse.edc.http.spi.ControlApiHttpClient; @@ -32,6 +33,8 @@ import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataPlaneInstanceTransformer; import org.eclipse.edc.transform.transformer.edc.to.JsonValueToGenericTypeTransformer; +import java.util.function.Supplier; + import static java.util.Collections.emptyMap; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -66,17 +69,17 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { var builderFactory = Json.createBuilderFactory(emptyMap()); - var objectMapper = typeManager.getMapper(JSON_LD); - typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(builderFactory, objectMapper)); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); + typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(builderFactory, objectMapperSupplier)); typeTransformerRegistry.register(new JsonObjectFromDataAddressTransformer(builderFactory)); typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer()); typeTransformerRegistry.register(new JsonObjectToDataAddressTransformer()); - typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapper)); + typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapperSupplier)); } @Provider public DataPlaneSelectorService dataPlaneSelectorService(ServiceExtensionContext context) { - return new RemoteDataPlaneSelectorService(httpClient, selectorApiUrl, typeManager.getMapper(JSON_LD), typeTransformerRegistry, + return new RemoteDataPlaneSelectorService(httpClient, selectorApiUrl, () -> typeManager.getMapper(JSON_LD), typeTransformerRegistry, selectionStrategy, jsonLd); } } diff --git a/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorService.java b/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorService.java index 00e83af70fe..48054e88869 100644 --- a/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorService.java +++ b/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorService.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Optional; +import java.util.function.Supplier; import static jakarta.json.Json.createObjectBuilder; import static okhttp3.internal.Util.EMPTY_REQUEST; @@ -51,17 +52,17 @@ public class RemoteDataPlaneSelectorService implements DataPlaneSelectorService private static final String SELECT_PATH = "/select"; private final ControlApiHttpClient httpClient; private final String url; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; private final TypeTransformerRegistry typeTransformerRegistry; private final String selectionStrategy; private final JsonLd jsonLd; - public RemoteDataPlaneSelectorService(ControlApiHttpClient controlClient, String url, ObjectMapper mapper, + public RemoteDataPlaneSelectorService(ControlApiHttpClient controlClient, String url, Supplier objectMapperSupplier, TypeTransformerRegistry typeTransformerRegistry, String selectionStrategy, JsonLd jsonLd) { this.httpClient = controlClient; this.url = url; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; this.typeTransformerRegistry = typeTransformerRegistry; this.selectionStrategy = selectionStrategy; this.jsonLd = jsonLd; @@ -145,7 +146,7 @@ public ServiceResult findById(String id) { private ServiceResult toJsonObject(String it) { try { - return ServiceResult.success(mapper.readValue(it, JsonObject.class)); + return ServiceResult.success(objectMapperSupplier.get().readValue(it, JsonObject.class)); } catch (JsonProcessingException e) { return ServiceResult.unexpected("Cannot deserialize response body as JsonObject"); } @@ -153,7 +154,7 @@ private ServiceResult toJsonObject(String it) { private ServiceResult toJsonArray(String it) { try { - return ServiceResult.success(mapper.readValue(it, JsonArray.class)); + return ServiceResult.success(objectMapperSupplier.get().readValue(it, JsonArray.class)); } catch (JsonProcessingException e) { return ServiceResult.unexpected("Cannot deserialize response body as JsonObject"); } diff --git a/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtension.java b/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtension.java index 7c86cc90b55..9b7c04c9e67 100644 --- a/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtension.java +++ b/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtension.java @@ -15,6 +15,7 @@ package org.eclipse.edc.connector.dataplane.selector.control.api; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.edc.connector.dataplane.selector.control.api.transformer.JsonObjectToSelectionRequestTransformer; import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; import org.eclipse.edc.runtime.metamodel.annotation.Extension; @@ -33,6 +34,7 @@ import java.time.Clock; import java.util.Map; +import java.util.function.Supplier; import static jakarta.json.Json.createBuilderFactory; import static org.eclipse.edc.connector.dataplane.selector.control.api.DataplaneSelectorControlApiExtension.NAME; @@ -70,13 +72,13 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { validatorRegistry.register(DATAPLANE_INSTANCE_TYPE, DataPlaneInstanceValidator.instance()); - var objectMapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer()); typeTransformerRegistry.register(new JsonObjectToSelectionRequestTransformer()); typeTransformerRegistry.register(new JsonObjectToDataAddressTransformer()); - typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapper)); - typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), objectMapper)); + typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapperSupplier)); + typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), objectMapperSupplier)); var controller = new DataplaneSelectorControlApiController(validatorRegistry, typeTransformerRegistry, dataPlaneSelectorService, clock); webService.registerResource(ApiContext.CONTROL, controller); diff --git a/extensions/data-plane/data-plane-signaling/data-plane-signaling-api/src/main/java/org/eclipse/edc/connector/dataplane/api/DataPlaneSignalingApiExtension.java b/extensions/data-plane/data-plane-signaling/data-plane-signaling-api/src/main/java/org/eclipse/edc/connector/dataplane/api/DataPlaneSignalingApiExtension.java index 2c83596744c..037407db577 100644 --- a/extensions/data-plane/data-plane-signaling/data-plane-signaling-api/src/main/java/org/eclipse/edc/connector/dataplane/api/DataPlaneSignalingApiExtension.java +++ b/extensions/data-plane/data-plane-signaling/data-plane-signaling-api/src/main/java/org/eclipse/edc/connector/dataplane/api/DataPlaneSignalingApiExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.connector.dataplane.api; +import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; import org.eclipse.edc.connector.api.signaling.transform.from.JsonObjectFromDataFlowResponseMessageTransformer; import org.eclipse.edc.connector.api.signaling.transform.to.JsonObjectToDataFlowStartMessageTransformer; @@ -33,6 +34,7 @@ import org.eclipse.edc.web.spi.configuration.ApiContext; import java.util.Map; +import java.util.function.Supplier; import static org.eclipse.edc.connector.dataplane.api.DataPlaneSignalingApiExtension.NAME; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -59,7 +61,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { var factory = Json.createBuilderFactory(Map.of()); - var jsonLdMapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); var signalingApiTypeTransformerRegistry = transformerRegistry.forContext("signaling-api"); signalingApiTypeTransformerRegistry.register(new JsonObjectToDataFlowStartMessageTransformer()); @@ -67,7 +69,7 @@ public void initialize(ServiceExtensionContext context) { signalingApiTypeTransformerRegistry.register(new JsonObjectToDataFlowTerminateMessageTransformer()); signalingApiTypeTransformerRegistry.register(new JsonObjectToDataAddressDspaceTransformer()); signalingApiTypeTransformerRegistry.register(new JsonObjectFromDataFlowResponseMessageTransformer(factory)); - signalingApiTypeTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(factory, jsonLdMapper)); + signalingApiTypeTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(factory, objectMapperSupplier)); var controller = new DataPlaneSignalingApiController(signalingApiTypeTransformerRegistry, dataPlaneManager, context.getMonitor().withPrefix("SignalingAPI")); diff --git a/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClient.java b/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClient.java index f1a2f16ec1f..41dc1483e24 100644 --- a/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClient.java +++ b/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClient.java @@ -38,6 +38,7 @@ import java.io.IOException; import java.util.Optional; +import java.util.function.Supplier; import static java.lang.String.format; import static org.eclipse.edc.spi.response.ResponseStatus.FATAL_ERROR; @@ -54,15 +55,15 @@ public class DataPlaneSignalingClient implements DataPlaneClient { private final JsonLd jsonLd; private final String jsonLdScope; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; public DataPlaneSignalingClient(ControlApiHttpClient httpClient, TypeTransformerRegistry transformerRegistry, JsonLd jsonLd, String jsonLdScope, - ObjectMapper mapper, DataPlaneInstance dataPlane) { + Supplier objectMapperSupplier, DataPlaneInstance dataPlane) { this.httpClient = httpClient; this.transformerRegistry = transformerRegistry; this.jsonLd = jsonLd; this.jsonLdScope = jsonLdScope; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; this.dataPlane = dataPlane; } @@ -131,7 +132,7 @@ private StatusResult handleStartResponse(String respons private StatusResult deserializeStartMessage(String responseBody) { try { - var jsonObject = mapper.readValue(responseBody, JsonObject.class); + var jsonObject = objectMapperSupplier.get().readValue(responseBody, JsonObject.class); var result = jsonLd.expand(jsonObject) .compose(expanded -> transformerRegistry.transform(expanded, DataFlowResponseMessage.class)); if (result.succeeded()) { @@ -151,7 +152,7 @@ private Result compact(JsonObject object) { private Result serializeMessage(Object message) { try { - return Result.success(mapper.writeValueAsString(message)); + return Result.success(objectMapperSupplier.get().writeValueAsString(message)); } catch (JsonProcessingException e) { return Result.failure(e.getMessage()); } diff --git a/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientExtension.java b/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientExtension.java index aa42ad92e4f..681adad988a 100644 --- a/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientExtension.java +++ b/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientExtension.java @@ -74,11 +74,10 @@ public DataPlaneClientFactory dataPlaneClientFactory(ServiceExtensionContext con jsonLd.registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, CONTROL_CLIENT_SCOPE); jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE, CONTROL_CLIENT_SCOPE); - var mapper = typeManager.getMapper(JSON_LD); context.getMonitor().debug(() -> "Using remote Data Plane client."); Objects.requireNonNull(httpClient, "To use remote Data Plane client, a ControlApiHttpClient instance must be registered"); var signalingApiTypeTransformerRegistry = transformerRegistry.forContext("signaling-api"); - return instance -> new DataPlaneSignalingClient(httpClient, signalingApiTypeTransformerRegistry, jsonLd, CONTROL_CLIENT_SCOPE, mapper, + return instance -> new DataPlaneSignalingClient(httpClient, signalingApiTypeTransformerRegistry, jsonLd, CONTROL_CLIENT_SCOPE, () -> typeManager.getMapper(JSON_LD), instance); } } diff --git a/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientTransformExtension.java b/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientTransformExtension.java index b237224321c..5e9748c9888 100644 --- a/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientTransformExtension.java +++ b/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientTransformExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.connector.dataplane.client; +import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; import org.eclipse.edc.connector.api.signaling.transform.from.JsonObjectFromDataFlowStartMessageTransformer; import org.eclipse.edc.connector.api.signaling.transform.from.JsonObjectFromDataFlowSuspendMessageTransformer; @@ -29,6 +30,7 @@ import org.eclipse.edc.transform.transformer.dspace.to.JsonObjectToDataAddressDspaceTransformer; import java.util.Map; +import java.util.function.Supplier; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -53,16 +55,16 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var mapper = typeManager.getMapper(JSON_LD); + Supplier objectMapperSupplier = () -> typeManager.getMapper(JSON_LD); var factory = Json.createBuilderFactory(Map.of()); var signalingApiTransformerRegistry = transformerRegistry.forContext("signaling-api"); - signalingApiTransformerRegistry.register(new JsonObjectFromDataFlowStartMessageTransformer(factory, mapper)); + signalingApiTransformerRegistry.register(new JsonObjectFromDataFlowStartMessageTransformer(factory, objectMapperSupplier)); signalingApiTransformerRegistry.register(new JsonObjectFromDataFlowSuspendMessageTransformer(factory)); signalingApiTransformerRegistry.register(new JsonObjectFromDataFlowTerminateMessageTransformer(factory)); signalingApiTransformerRegistry.register(new JsonObjectToDataFlowResponseMessageTransformer()); signalingApiTransformerRegistry.register(new JsonObjectToDataAddressDspaceTransformer()); - signalingApiTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(factory, mapper)); + signalingApiTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(factory, objectMapperSupplier)); } } diff --git a/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/test/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientTest.java b/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/test/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientTest.java index c506ef792f4..9cd9fbfc181 100644 --- a/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/test/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientTest.java +++ b/extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/test/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientTest.java @@ -99,7 +99,7 @@ class DataPlaneSignalingClientTest { private final ControlApiHttpClient httpClient = new ControlApiHttpClientImpl(testHttpClient(), mock()); private final DataPlaneClient dataPlaneClient = new DataPlaneSignalingClient(httpClient, TRANSFORMER_REGISTRY, - JSON_LD, CONTROL_CLIENT_SCOPE, MAPPER, instance); + JSON_LD, CONTROL_CLIENT_SCOPE, () -> MAPPER, instance); @BeforeAll public static void setUp() { @@ -113,10 +113,10 @@ public static void setUp() { dataPlane = startClientAndServer(DATA_PLANE_API_PORT); TRANSFORMER_REGISTRY.register(new JsonObjectFromDataFlowTerminateMessageTransformer(factory)); TRANSFORMER_REGISTRY.register(new JsonObjectFromDataFlowSuspendMessageTransformer(factory)); - TRANSFORMER_REGISTRY.register(new JsonObjectFromDataFlowStartMessageTransformer(factory, MAPPER)); + TRANSFORMER_REGISTRY.register(new JsonObjectFromDataFlowStartMessageTransformer(factory, () -> MAPPER)); TRANSFORMER_REGISTRY.register(new JsonObjectFromDataFlowResponseMessageTransformer(factory)); TRANSFORMER_REGISTRY.register(new JsonObjectToDataFlowResponseMessageTransformer()); - TRANSFORMER_REGISTRY.register(new JsonObjectFromDataAddressDspaceTransformer(factory, MAPPER)); + TRANSFORMER_REGISTRY.register(new JsonObjectFromDataAddressDspaceTransformer(factory, () -> MAPPER)); TRANSFORMER_REGISTRY.register(new JsonObjectToDataAddressDspaceTransformer()); } @@ -183,7 +183,7 @@ void verifyReturnFatalErrorIfReceiveErrorInResponse() throws JsonProcessingExcep void verifyReturnFatalErrorIfTransformFails() { var flowRequest = createDataFlowRequest(); TypeTransformerRegistry registry = mock(); - var dataPlaneClient = new DataPlaneSignalingClient(httpClient, registry, JSON_LD, CONTROL_CLIENT_SCOPE, MAPPER, instance); + var dataPlaneClient = new DataPlaneSignalingClient(httpClient, registry, JSON_LD, CONTROL_CLIENT_SCOPE, () -> MAPPER, instance); when(registry.transform(any(), any())).thenReturn(Result.failure("Transform Failure")); @@ -316,7 +316,7 @@ void shouldFail_whenConflictResponse() { @Test void verifyReturnFatalErrorIfTransformFails() { TypeTransformerRegistry registry = mock(); - var dataPlaneClient = new DataPlaneSignalingClient(httpClient, registry, JSON_LD, CONTROL_CLIENT_SCOPE, MAPPER, instance); + var dataPlaneClient = new DataPlaneSignalingClient(httpClient, registry, JSON_LD, CONTROL_CLIENT_SCOPE, () -> MAPPER, instance); when(registry.transform(any(), any())).thenReturn(Result.failure("Transform Failure")); @@ -359,7 +359,7 @@ void shouldFail_whenConflictResponse() { @Test void verifyReturnFatalErrorIfTransformFails() { TypeTransformerRegistry registry = mock(); - var dataPlaneClient = new DataPlaneSignalingClient(httpClient, registry, JSON_LD, CONTROL_CLIENT_SCOPE, MAPPER, instance); + var dataPlaneClient = new DataPlaneSignalingClient(httpClient, registry, JSON_LD, CONTROL_CLIENT_SCOPE, () -> MAPPER, instance); when(registry.transform(any(), any())).thenReturn(Result.failure("Transform Failure")); diff --git a/extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/src/main/java/org/eclipse/edc/connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformer.java b/extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/src/main/java/org/eclipse/edc/connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformer.java index 03cb43e0a29..8aa0c210a9c 100644 --- a/extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/src/main/java/org/eclipse/edc/connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformer.java +++ b/extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/src/main/java/org/eclipse/edc/connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformer.java @@ -23,6 +23,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Supplier; + import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.DC_DATA_FLOW_START_MESSAGE_PROCESS_ID; import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_AGREEMENT_ID; @@ -42,18 +44,18 @@ */ public class JsonObjectFromDataFlowStartMessageTransformer extends AbstractJsonLdTransformer { private final JsonBuilderFactory jsonFactory; - private final ObjectMapper mapper; + private final Supplier objectMapperSupplier; - public JsonObjectFromDataFlowStartMessageTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { + public JsonObjectFromDataFlowStartMessageTransformer(JsonBuilderFactory jsonFactory, Supplier objectMapperSupplier) { super(DataFlowStartMessage.class, JsonObject.class); this.jsonFactory = jsonFactory; - this.mapper = mapper; + this.objectMapperSupplier = objectMapperSupplier; } @Override public @Nullable JsonObject transform(@NotNull DataFlowStartMessage message, @NotNull TransformerContext context) { var propertiesBuilder = jsonFactory.createObjectBuilder(); - transformProperties(message.getProperties(), propertiesBuilder, mapper, context); + transformProperties(message.getProperties(), propertiesBuilder, objectMapperSupplier.get(), context); var builder = jsonFactory.createObjectBuilder() .add(TYPE, EDC_DATA_FLOW_START_MESSAGE_TYPE) .add(EDC_DATA_FLOW_START_MESSAGE_TRANSFER_TYPE_DESTINATION, message.getTransferType().destinationType()) diff --git a/extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/src/test/java/org/eclipse/edc/connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformerTest.java b/extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/src/test/java/org/eclipse/edc/connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformerTest.java index 2fc7430fed2..aa608e0b476 100644 --- a/extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/src/test/java/org/eclipse/edc/connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformerTest.java +++ b/extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/src/test/java/org/eclipse/edc/connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformerTest.java @@ -15,6 +15,7 @@ package org.eclipse.edc.connector.api.signaling.transform.from; import jakarta.json.Json; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; import org.eclipse.edc.spi.types.domain.transfer.FlowType; @@ -28,7 +29,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.DC_DATA_FLOW_START_MESSAGE_PROCESS_ID; import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_AGREEMENT_ID; import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_DATASET_ID; @@ -52,7 +52,7 @@ class JsonObjectFromDataFlowStartMessageTransformerTest { @BeforeEach void setUp() { - transformer = new JsonObjectFromDataFlowStartMessageTransformer(Json.createBuilderFactory(Map.of()), createObjectMapper()); + transformer = new JsonObjectFromDataFlowStartMessageTransformer(Json.createBuilderFactory(Map.of()), JacksonJsonLd::createObjectMapper); when(context.transform(isA(DataAddress.class), any())).thenReturn(Json.createObjectBuilder().build()); } diff --git a/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSignalingApiEndToEndTest.java b/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSignalingApiEndToEndTest.java index 40bc475dd18..8d92de0529c 100644 --- a/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSignalingApiEndToEndTest.java +++ b/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSignalingApiEndToEndTest.java @@ -67,8 +67,8 @@ public class DataPlaneSignalingApiEndToEndTest extends AbstractDataPlaneTest { void setup() { var builderFactory = Json.createBuilderFactory(Map.of()); mapper = JacksonJsonLd.createObjectMapper(); - registry.register(new JsonObjectFromDataFlowStartMessageTransformer(builderFactory, mapper)); - registry.register(new JsonObjectFromDataAddressDspaceTransformer(builderFactory, mapper)); + registry.register(new JsonObjectFromDataFlowStartMessageTransformer(builderFactory, () -> mapper)); + registry.register(new JsonObjectFromDataAddressDspaceTransformer(builderFactory, () -> mapper)); registry.register(new JsonObjectToDataAddressDspaceTransformer()); registry.register(new JsonObjectToDataFlowResponseMessageTransformer()); }