From aba67ee84692c241af009149a0d8ede35a6049e4 Mon Sep 17 00:00:00 2001 From: Enrico Risa Date: Fri, 17 Jan 2025 16:40:00 +0100 Subject: [PATCH] fix: add deterministic ObjectMapper for JSON-LD --- .../http/api/DspCatalogApiExtension.java | 9 +++--- .../DspCatalogTransformExtension.java | 9 +++--- .../DspApiConfigurationExtension.java | 18 +++++------- .../dsp/http/DspHttpCoreExtension.java | 7 ++--- .../http/api/DspNegotiationApiExtension.java | 7 ++--- ...DspNegotiationHttpDispatcherExtension.java | 7 ++--- .../api/DspTransferProcessApiExtension.java | 7 ++--- ...DspTransferProcessDispatcherExtension.java | 7 ++--- .../DspTransferProcessTransformExtension.java | 7 ++--- .../ControlApiConfigurationExtension.java | 8 +++-- .../ManagementApiConfigurationExtension.java | 6 ++-- .../core/IdentityAndTrustExtension.java | 26 +++++++---------- .../core/IdentityTrustTransformExtension.java | 11 ++++--- .../IdentityTrustTransformExtensionTest.java | 11 ++----- .../eclipse/edc/jsonld/JsonLdExtension.java | 14 +++++---- .../ContractDefinitionApiExtension.java | 7 ++--- .../policy/PolicyDefinitionApiExtension.java | 7 ++--- .../DataPlaneSelectorApiExtension.java | 9 +++--- .../DataPlaneSelectorClientExtension.java | 9 +++--- .../DataplaneSelectorControlApiExtension.java | 7 ++--- .../api/DataPlaneSignalingApiExtension.java | 7 ++--- .../DataPlaneSignalingClientExtension.java | 7 ++--- ...laneSignalingClientTransformExtension.java | 8 ++--- .../spi/JsonLdObjectMapperProvider.java | 29 +++++++++++++++++++ 24 files changed, 124 insertions(+), 120 deletions(-) create mode 100644 spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/JsonLdObjectMapperProvider.java 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..d39d17fa75b 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 @@ -20,6 +20,7 @@ import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.spi.JsonLdNamespace; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.protocol.dsp.catalog.http.api.controller.DspCatalogApiController; import org.eclipse.edc.protocol.dsp.catalog.http.api.controller.DspCatalogApiController20241; import org.eclipse.edc.protocol.dsp.catalog.http.api.decorator.Base64continuationTokenSerDes; @@ -34,7 +35,6 @@ import org.eclipse.edc.spi.query.CriterionOperatorRegistry; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.jersey.providers.jsonld.JerseyJsonLdInterceptor; @@ -50,7 +50,6 @@ import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_08; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Creates and registers the controller for dataspace protocol catalog requests. @@ -81,9 +80,9 @@ public class DspCatalogApiExtension implements ServiceExtension { @Inject private Monitor monitor; @Inject - private TypeManager typeManager; - @Inject private JsonLd jsonLd; + @Inject + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public String name() { @@ -92,7 +91,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var jsonLdMapper = typeManager.getMapper(JSON_LD); + var jsonLdMapper = jsonLdMapperProvider.get(); registerValidators(DSP_NAMESPACE_V_08); registerValidators(DSP_NAMESPACE_V_2024_1); 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..7a2397ae0d2 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 @@ -17,6 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; import org.eclipse.edc.jsonld.spi.JsonLdNamespace; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.participant.spi.ParticipantIdMapper; import org.eclipse.edc.protocol.dsp.catalog.transform.from.JsonObjectFromCatalogErrorTransformer; import org.eclipse.edc.protocol.dsp.catalog.transform.from.JsonObjectFromCatalogRequestMessageTransformer; @@ -30,7 +31,6 @@ import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import java.util.Map; @@ -39,7 +39,6 @@ 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_TRANSFORMER_CONTEXT_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_2024_1; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Provides the transformers for catalog message types via the {@link TypeTransformerRegistry}. @@ -53,7 +52,7 @@ public class DspCatalogTransformExtension implements ServiceExtension { private TypeTransformerRegistry registry; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider objectMapperProvider; @Inject private ParticipantIdMapper participantIdMapper; @@ -65,11 +64,11 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var mapper = typeManager.getMapper(JSON_LD); + var mapper = objectMapperProvider.get(); 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); 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..634a9d30c70 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 @@ -22,6 +22,7 @@ import org.eclipse.edc.connector.controlplane.transform.odrl.from.JsonObjectFromPolicyTransformer; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.spi.JsonLdNamespace; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.participant.spi.ParticipantIdMapper; import org.eclipse.edc.policy.model.AtomicConstraint; import org.eclipse.edc.policy.model.LiteralExpression; @@ -35,7 +36,6 @@ import org.eclipse.edc.spi.system.Hostname; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.transform.transformer.dspace.from.JsonObjectFromDataAddressDspaceTransformer; import org.eclipse.edc.transform.transformer.dspace.to.JsonObjectToDataAddressDspaceTransformer; @@ -71,7 +71,6 @@ import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_2024_1; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Configure 'protocol' api context. @@ -91,7 +90,7 @@ public class DspApiConfigurationExtension implements ServiceExtension { private DspApiConfiguration apiConfiguration; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider mapperProvider; @Inject private WebService webService; @Inject @@ -118,7 +117,7 @@ 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); + var jsonLdMapper = mapperProvider.get(); // registers ns for DSP scope registerNamespaces(DSP_SCOPE_V_08, DSP_NAMESPACE_V_08); @@ -126,13 +125,12 @@ public void initialize(ServiceExtensionContext context) { webService.registerResource(ApiContext.PROTOCOL, new ObjectMapperProvider(jsonLdMapper)); - var mapper = typeManager.getMapper(JSON_LD); - mapper.registerSubtypes(AtomicConstraint.class, LiteralExpression.class); + jsonLdMapper.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); + registerV08Transformers(jsonLdMapper); + registerV2024Transformers(jsonLdMapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, jsonLdMapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, jsonLdMapper); } private void registerNamespaces(String scope, JsonLdNamespace dspNamespace) { 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..66b65304f4a 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 @@ -32,6 +32,7 @@ import org.eclipse.edc.connector.controlplane.transfer.spi.types.protocol.TransferTerminationMessage; import org.eclipse.edc.http.spi.EdcHttpClient; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.policy.context.request.spi.RequestCatalogPolicyContext; import org.eclipse.edc.policy.context.request.spi.RequestContractNegotiationPolicyContext; import org.eclipse.edc.policy.context.request.spi.RequestTransferProcessPolicyContext; @@ -56,7 +57,6 @@ import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.token.spi.TokenDecorator; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; @@ -69,7 +69,6 @@ import static org.eclipse.edc.protocol.dsp.http.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Provides an implementation of {@link DspHttpRemoteMessageDispatcher} to support sending dataspace @@ -90,7 +89,7 @@ public class DspHttpCoreExtension implements ServiceExtension { @Inject private TypeTransformerRegistry transformerRegistry; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private JsonLd jsonLdService; @Inject(required = false) @@ -150,7 +149,7 @@ public DspRequestHandler dspRequestHandler() { @Provider public JsonLdRemoteMessageSerializer jsonLdRemoteMessageSerializer() { - return new JsonLdRemoteMessageSerializerImpl(dspTransformerRegistry(), typeManager.getMapper(JSON_LD), jsonLdService, dspProtocolParser(), DSP_SCOPE); + return new JsonLdRemoteMessageSerializerImpl(dspTransformerRegistry(), jsonLdMapperProvider.get(), jsonLdService, dspProtocolParser(), DSP_SCOPE); } @Provider 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..c5557a64a6a 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 @@ -18,6 +18,7 @@ import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.spi.JsonLdNamespace; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler; import org.eclipse.edc.protocol.dsp.negotiation.http.api.controller.DspNegotiationApiController; import org.eclipse.edc.protocol.dsp.negotiation.http.api.controller.DspNegotiationApiController20241; @@ -31,7 +32,6 @@ import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.jersey.providers.jsonld.JerseyJsonLdInterceptor; import org.eclipse.edc.web.spi.WebService; @@ -49,7 +49,6 @@ import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE_TERM; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_08; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Creates and registers the controller for dataspace protocol negotiation requests. @@ -74,7 +73,7 @@ public class DspNegotiationApiExtension implements ServiceExtension { private JsonLd jsonLd; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public String name() { @@ -83,7 +82,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var jsonLdMapper = typeManager.getMapper(JSON_LD); + var jsonLdMapper = jsonLdMapperProvider.get(); registerValidators(DSP_NAMESPACE_V_08); registerValidators(DSP_NAMESPACE_V_2024_1); 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..619b8231e8b 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 @@ -22,6 +22,7 @@ import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequestMessage; import org.eclipse.edc.connector.controlplane.contract.spi.types.protocol.ContractNegotiationAck; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.protocol.dsp.http.dispatcher.PostDspHttpRequestFactory; import org.eclipse.edc.protocol.dsp.http.serialization.JsonLdResponseBodyDeserializer; import org.eclipse.edc.protocol.dsp.http.spi.DspProtocolParser; @@ -32,10 +33,8 @@ import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import static org.eclipse.edc.protocol.dsp.http.spi.dispatcher.response.DspHttpResponseBodyExtractor.NOOP; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(value = DspNegotiationHttpDispatcherExtension.NAME) public class DspNegotiationHttpDispatcherExtension implements ServiceExtension { @@ -49,7 +48,7 @@ public class DspNegotiationHttpDispatcherExtension implements ServiceExtension { private JsonLdRemoteMessageSerializer remoteMessageSerializer; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private DspProtocolTypeTransformerRegistry dspTransformerRegistry; @@ -68,7 +67,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { var contractNegotiationAckDeserializer = new JsonLdResponseBodyDeserializer<>( - ContractNegotiationAck.class, typeManager.getMapper(JSON_LD), jsonLd, dspTransformerRegistry); + ContractNegotiationAck.class, jsonLdMapperProvider.get(), 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..b05c0e1ade3 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 @@ -18,6 +18,7 @@ import org.eclipse.edc.connector.controlplane.services.spi.transferprocess.TransferProcessProtocolService; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.spi.JsonLdNamespace; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler; import org.eclipse.edc.protocol.dsp.transferprocess.http.api.controller.DspTransferProcessApiController; import org.eclipse.edc.protocol.dsp.transferprocess.http.api.controller.DspTransferProcessApiController20241; @@ -29,7 +30,6 @@ import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.jersey.providers.jsonld.JerseyJsonLdInterceptor; import org.eclipse.edc.web.spi.WebService; @@ -45,7 +45,6 @@ import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_TERMINATION_MESSAGE_TERM; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_08; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Creates and registers the controller for dataspace protocol transfer process requests. @@ -67,11 +66,11 @@ public class DspTransferProcessApiExtension implements ServiceExtension { @Inject private JsonLd jsonLd; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public void initialize(ServiceExtensionContext context) { - var jsonLdMapper = typeManager.getMapper(JSON_LD); + var jsonLdMapper = jsonLdMapperProvider.get(); registerValidators(DSP_NAMESPACE_V_08); registerValidators(DSP_NAMESPACE_V_2024_1); 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..eb0c6ea02ab 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 @@ -22,6 +22,7 @@ import org.eclipse.edc.connector.controlplane.transfer.spi.types.protocol.TransferSuspensionMessage; import org.eclipse.edc.connector.controlplane.transfer.spi.types.protocol.TransferTerminationMessage; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.protocol.dsp.http.dispatcher.PostDspHttpRequestFactory; import org.eclipse.edc.protocol.dsp.http.serialization.JsonLdResponseBodyDeserializer; import org.eclipse.edc.protocol.dsp.http.spi.DspProtocolParser; @@ -32,7 +33,6 @@ import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import static org.eclipse.edc.protocol.dsp.http.spi.dispatcher.response.DspHttpResponseBodyExtractor.NOOP; import static org.eclipse.edc.protocol.dsp.transferprocess.http.dispatcher.TransferProcessApiPaths.BASE_PATH; @@ -41,7 +41,6 @@ import static org.eclipse.edc.protocol.dsp.transferprocess.http.dispatcher.TransferProcessApiPaths.TRANSFER_START; import static org.eclipse.edc.protocol.dsp.transferprocess.http.dispatcher.TransferProcessApiPaths.TRANSFER_SUSPENSION; import static org.eclipse.edc.protocol.dsp.transferprocess.http.dispatcher.TransferProcessApiPaths.TRANSFER_TERMINATION; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** @@ -59,7 +58,7 @@ public class DspTransferProcessDispatcherExtension implements ServiceExtension { private JsonLdRemoteMessageSerializer remoteMessageSerializer; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private DspProtocolTypeTransformerRegistry dspTransformerRegistry; @@ -80,7 +79,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, jsonLdMapperProvider.get(), 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..5169f26f275 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 @@ -17,6 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; import org.eclipse.edc.jsonld.spi.JsonLdNamespace; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.protocol.dsp.transferprocess.transform.type.from.JsonObjectFromTransferCompletionMessageTransformer; import org.eclipse.edc.protocol.dsp.transferprocess.transform.type.from.JsonObjectFromTransferErrorTransformer; import org.eclipse.edc.protocol.dsp.transferprocess.transform.type.from.JsonObjectFromTransferProcessTransformer; @@ -40,7 +41,6 @@ import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import java.util.Map; @@ -49,7 +49,6 @@ 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_TRANSFORMER_CONTEXT_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_2024_1; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Provides the transformers for transferprocess message types via the {@link TypeTransformerRegistry}. @@ -63,7 +62,7 @@ public class DspTransferProcessTransformExtension implements ServiceExtension { private TypeTransformerRegistry registry; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public String name() { @@ -72,7 +71,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var objectMapper = typeManager.getMapper(JSON_LD); + var objectMapper = jsonLdMapperProvider.get(); registerV08transformers(); registerV2024transformers(); 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..110208406bb 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 @@ -18,6 +18,7 @@ import org.eclipse.edc.api.auth.spi.AuthenticationRequestFilter; import org.eclipse.edc.api.auth.spi.registry.ApiAuthenticationRegistry; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Configuration; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; @@ -52,7 +53,6 @@ import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Tells all the Control API controllers under which context alias they need to register their resources: either @@ -87,6 +87,8 @@ public class ControlApiConfigurationExtension implements ServiceExtension { private ApiAuthenticationRegistry authenticationRegistry; @Inject private ApiVersionService apiVersionService; + @Inject + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public String name() { @@ -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); + var jsonLdMapper = jsonLdMapperProvider.get(); context.registerService(ControlApiUrl.class, controlApiUrl(context, portMapping)); jsonLd.registerNamespace(EDC_PREFIX, EDC_NAMESPACE, CONTROL_SCOPE); @@ -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/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..e51dfe14e3f 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 @@ -24,6 +24,7 @@ import org.eclipse.edc.connector.controlplane.transform.odrl.OdrlTransformersFactory; import org.eclipse.edc.connector.controlplane.transform.odrl.from.JsonObjectFromPolicyTransformer; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.participant.spi.ParticipantIdMapper; import org.eclipse.edc.runtime.metamodel.annotation.Configuration; import org.eclipse.edc.runtime.metamodel.annotation.Extension; @@ -69,7 +70,6 @@ import static org.eclipse.edc.spi.constants.CoreConstants.EDC_CONNECTOR_MANAGEMENT_CONTEXT; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * Configure 'management' api context. @@ -103,6 +103,8 @@ public class ManagementApiConfigurationExtension implements ServiceExtension { @Inject private JsonLd jsonLd; @Inject + private JsonLdObjectMapperProvider jsonLdMapperProvider; + @Inject private TypeTransformerRegistry transformerRegistry; @Inject private ParticipantIdMapper participantIdMapper; @@ -135,7 +137,7 @@ public void initialize(ServiceExtensionContext context) { jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, MANAGEMENT_SCOPE); } - var jsonLdMapper = typeManager.getMapper(JSON_LD); + var jsonLdMapper = jsonLdMapperProvider.get(); webService.registerResource(ApiContext.MANAGEMENT, new ObjectMapperProvider(jsonLdMapper)); webService.registerResource(ApiContext.MANAGEMENT, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, MANAGEMENT_SCOPE)); 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..a59b9a05e43 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 @@ -37,6 +37,7 @@ import org.eclipse.edc.iam.verifiablecredentials.spi.validation.PresentationVerifier; import org.eclipse.edc.iam.verifiablecredentials.spi.validation.TrustedIssuerRegistry; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.jwt.validation.jti.JtiValidationStore; import org.eclipse.edc.participant.spi.ParticipantAgentService; import org.eclipse.edc.runtime.metamodel.annotation.Extension; @@ -48,7 +49,6 @@ import org.eclipse.edc.spi.system.ExecutorInstrumentation; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.token.rules.AudienceValidationRule; import org.eclipse.edc.token.rules.ExpirationIssuedAtValidationRule; import org.eclipse.edc.token.spi.TokenValidationRulesRegistry; @@ -71,27 +71,21 @@ import java.util.concurrent.TimeUnit; import static org.eclipse.edc.iam.verifiablecredentials.spi.VcConstants.STATUSLIST_2021_URL; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; import static org.eclipse.edc.verifiablecredentials.jwt.JwtPresentationVerifier.JWT_VC_TOKEN_CONTEXT; @Extension("Identity And Trust Extension") 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; @@ -99,7 +93,7 @@ public class IdentityAndTrustExtension implements ServiceExtension { private TrustedIssuerRegistry trustedIssuerRegistry; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private SignatureSuiteRegistry signatureSuiteRegistry; @@ -160,7 +154,7 @@ public void initialize(ServiceExtensionContext context) { 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))); + signatureSuiteRegistry.register(JSON_2020_SIGNATURE_SUITE, new Jws2020SignatureSuite(jsonLdMapperProvider.get())); try { @@ -172,8 +166,8 @@ public void initialize(ServiceExtensionContext context) { participantAgentService.register(participantAgentServiceExtension); // register revocation services - revocationServiceRegistry.addService(StatusList2021Status.TYPE, new StatusList2021RevocationService(typeManager.getMapper(), revocationCacheValidity)); - revocationServiceRegistry.addService(BitstringStatusListStatus.TYPE, new BitstringStatusListRevocationService(typeManager.getMapper(), revocationCacheValidity)); + revocationServiceRegistry.addService(StatusList2021Status.TYPE, new StatusList2021RevocationService(jsonLdMapperProvider.get(), revocationCacheValidity)); + revocationServiceRegistry.addService(BitstringStatusListStatus.TYPE, new BitstringStatusListRevocationService(jsonLdMapperProvider.get(), revocationCacheValidity)); } @Override @@ -204,7 +198,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()); + jsonLdMapperProvider.get(), typeTransformerRegistry, jsonLd, context.getMonitor()); } return credentialServiceClient; } @@ -212,7 +206,7 @@ public CredentialServiceClient getCredentialServiceClient(ServiceExtensionContex @Provider public PresentationVerifier createPresentationVerifier(ServiceExtensionContext context) { if (presentationVerifier == null) { - var mapper = typeManager.getMapper(JSON_LD); + var mapper = jsonLdMapperProvider.get(); var jwtVerifier = new JwtPresentationVerifier(mapper, tokenValidationService, rulesRegistry, didPublicKeyResolver); var ldpVerifier = LdpVerifier.Builder.newInstance() 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..3f104144c47 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 @@ -26,12 +26,12 @@ import org.eclipse.edc.iam.identitytrust.transform.to.JwtToVerifiableCredentialTransformer; import org.eclipse.edc.iam.identitytrust.transform.to.JwtToVerifiablePresentationTransformer; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.result.Result; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.jetbrains.annotations.NotNull; @@ -41,7 +41,6 @@ import static java.lang.String.format; import static org.eclipse.edc.iam.identitytrust.spi.DcpConstants.DCP_CONTEXT_URL; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(value = IdentityTrustTransformExtension.NAME, categories = { "iam", "transform", "jsonld" }) public class IdentityTrustTransformExtension implements ServiceExtension { @@ -53,7 +52,7 @@ public class IdentityTrustTransformExtension implements ServiceExtension { @Inject private JsonLd jsonLdService; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public void initialize(ServiceExtensionContext context) { @@ -69,8 +68,8 @@ 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))); + typeTransformerRegistry.register(new JsonObjectToPresentationQueryTransformer(jsonLdMapperProvider.get())); + typeTransformerRegistry.register(new JsonObjectToPresentationResponseMessageTransformer(jsonLdMapperProvider.get())); typeTransformerRegistry.register(new JsonObjectFromPresentationQueryTransformer()); typeTransformerRegistry.register(new JsonObjectFromPresentationResponseMessageTransformer()); typeTransformerRegistry.register(new JsonObjectToVerifiablePresentationTransformer()); @@ -78,7 +77,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(), jsonLdMapperProvider.get(), jsonLdService)); typeTransformerRegistry.register(new JwtToVerifiableCredentialTransformer(context.getMonitor())); } diff --git a/extensions/common/iam/identity-trust/identity-trust-core/src/test/java/org/eclipse/edc/iam/identitytrust/transform/IdentityTrustTransformExtensionTest.java b/extensions/common/iam/identity-trust/identity-trust-core/src/test/java/org/eclipse/edc/iam/identitytrust/transform/IdentityTrustTransformExtensionTest.java index fdfe1b28488..b6db33d57c5 100644 --- a/extensions/common/iam/identity-trust/identity-trust-core/src/test/java/org/eclipse/edc/iam/identitytrust/transform/IdentityTrustTransformExtensionTest.java +++ b/extensions/common/iam/identity-trust/identity-trust-core/src/test/java/org/eclipse/edc/iam/identitytrust/transform/IdentityTrustTransformExtensionTest.java @@ -26,31 +26,26 @@ import org.eclipse.edc.iam.identitytrust.transform.to.JsonObjectToVerifiablePresentationTransformer; import org.eclipse.edc.iam.identitytrust.transform.to.JwtToVerifiableCredentialTransformer; import org.eclipse.edc.iam.identitytrust.transform.to.JwtToVerifiablePresentationTransformer; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @ExtendWith(DependencyInjectionExtension.class) class IdentityTrustTransformExtensionTest { private final TypeTransformerRegistry mockRegistry = mock(); - - private final TypeManager typeManager = mock(); - + @BeforeEach void setup(ServiceExtensionContext context) { - when(typeManager.getMapper(JSON_LD)).thenReturn(new ObjectMapper()); - context.registerService(TypeManager.class, typeManager); + context.registerService(JsonLdObjectMapperProvider.class, ObjectMapper::new); context.registerService(TypeTransformerRegistry.class, mockRegistry); } diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java b/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java index 6faea41ee95..a22c67ea4ed 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java +++ b/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java @@ -15,11 +15,13 @@ package org.eclipse.edc.jsonld; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.jsonld.spi.transformer.JsonLdTransformer; import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provider; +import org.eclipse.edc.runtime.metamodel.annotation.Provides; import org.eclipse.edc.runtime.metamodel.annotation.Setting; import org.eclipse.edc.spi.constants.CoreConstants; import org.eclipse.edc.spi.result.Result; @@ -44,6 +46,7 @@ * functions for working with JSON-LD structures. */ @Extension(value = JsonLdExtension.NAME) +@Provides(JsonLdObjectMapperProvider.class) public class JsonLdExtension implements ServiceExtension { public static final String NAME = "JSON-LD Extension"; @@ -56,17 +59,14 @@ public class JsonLdExtension implements ServiceExtension { public static final String CONFIG_VALUE_URL = "url"; private static final boolean DEFAULT_HTTP_HTTPS_RESOLUTION = false; + private static final boolean DEFAULT_AVOID_VOCAB_CONTEXT = false; + private static final boolean DEFAULT_CHECK_PREFIXES = true; @Setting(description = "If set enable http json-ld document resolution", defaultValue = DEFAULT_HTTP_HTTPS_RESOLUTION + "", key = "edc.jsonld.http.enabled") private boolean httpResolutionEnabled; - @Setting(description = "If set enable https json-ld document resolution", type = "boolean", defaultValue = DEFAULT_HTTP_HTTPS_RESOLUTION + "", key = "edc.jsonld.https.enabled") private boolean httpsResolutionEnabled; - - private static final boolean DEFAULT_AVOID_VOCAB_CONTEXT = false; @Setting(description = "If true disable the @vocab context definition. This could be used to avoid api breaking changes", defaultValue = DEFAULT_AVOID_VOCAB_CONTEXT + "", key = "edc.jsonld.vocab.disable") private boolean avoidVocab; - - private static final boolean DEFAULT_CHECK_PREFIXES = true; @Setting(description = "If true a validation on expended object will be made against configured prefixes", type = "boolean", defaultValue = DEFAULT_CHECK_PREFIXES + "", key = "edc.jsonld.prefixes.check") private boolean checkPrefixes; @@ -80,7 +80,9 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - typeManager.registerContext(JSON_LD, JacksonJsonLd.createObjectMapper()); + var objectMapper = JacksonJsonLd.createObjectMapper(); + typeManager.registerContext(JSON_LD, objectMapper); + context.registerService(JsonLdObjectMapperProvider.class, () -> objectMapper); } @Provider 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..a9192dbe38a 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 @@ -22,12 +22,12 @@ import org.eclipse.edc.connector.controlplane.api.management.contractdefinition.v3.ContractDefinitionApiV3Controller; import org.eclipse.edc.connector.controlplane.api.management.contractdefinition.validation.ContractDefinitionValidator; import org.eclipse.edc.connector.controlplane.services.spi.contractdefinition.ContractDefinitionService; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.query.CriterionOperatorRegistry; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; @@ -36,7 +36,6 @@ import java.util.Map; import static org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition.CONTRACT_DEFINITION_TYPE; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(value = ContractDefinitionApiExtension.NAME) public class ContractDefinitionApiExtension implements ServiceExtension { @@ -56,7 +55,7 @@ public class ContractDefinitionApiExtension implements ServiceExtension { JsonObjectValidatorRegistry validatorRegistry; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private CriterionOperatorRegistry criterionOperatorRegistry; @@ -69,7 +68,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { var jsonFactory = Json.createBuilderFactory(Map.of()); - var mapper = typeManager.getMapper(JSON_LD); + var mapper = jsonLdMapperProvider.get(); transformerRegistry.register(new JsonObjectFromContractDefinitionTransformer(jsonFactory, mapper)); transformerRegistry.register(new JsonObjectToContractDefinitionTransformer()); 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..aa11dd2cb8c 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 @@ -25,11 +25,11 @@ import org.eclipse.edc.connector.controlplane.api.management.policy.validation.PolicyDefinitionValidator; import org.eclipse.edc.connector.controlplane.api.management.policy.validation.PolicyEvaluationPlanRequestValidator; import org.eclipse.edc.connector.controlplane.services.spi.policydefinition.PolicyDefinitionService; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; @@ -39,7 +39,6 @@ import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE; import static org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition.EDC_POLICY_DEFINITION_TYPE; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(value = PolicyDefinitionApiExtension.NAME) @@ -60,7 +59,7 @@ public class PolicyDefinitionApiExtension implements ServiceExtension { private JsonObjectValidatorRegistry validatorRegistry; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public String name() { @@ -71,7 +70,7 @@ 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); + var mapper = jsonLdMapperProvider.get(); managementApiTransformerRegistry.register(new JsonObjectToPolicyEvaluationPlanRequestTransformer()); managementApiTransformerRegistry.register(new JsonObjectToPolicyDefinitionTransformer()); managementApiTransformerRegistry.register(new JsonObjectFromPolicyDefinitionTransformer(jsonBuilderFactory, mapper)); 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..22d208e9cb2 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 @@ -17,11 +17,11 @@ 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; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer; import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceV3Transformer; @@ -31,7 +31,6 @@ import java.util.Map; import static jakarta.json.Json.createBuilderFactory; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(value = "DataPlane selector API") public class DataPlaneSelectorApiExtension implements ServiceExtension { @@ -43,7 +42,7 @@ public class DataPlaneSelectorApiExtension implements ServiceExtension { private DataPlaneSelectorService selectionService; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private TypeTransformerRegistry transformerRegistry; @@ -53,12 +52,12 @@ public void initialize(ServiceExtensionContext context) { var managementApiTransformerRegistry = transformerRegistry.forContext("management-api"); // V4 - managementApiTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), typeManager.getMapper(JSON_LD))); + managementApiTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), jsonLdMapperProvider.get())); 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()), jsonLdMapperProvider.get())); webservice.registerResource(ApiContext.MANAGEMENT, new DataplaneSelectorApiV3Controller(selectionService, managementApiTransformerRegistryV3)); } 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..4d37fe50cc7 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 @@ -18,13 +18,13 @@ import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; import org.eclipse.edc.http.spi.ControlApiHttpClient; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provider; import org.eclipse.edc.runtime.metamodel.annotation.Setting; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataAddressTransformer; import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer; @@ -33,7 +33,6 @@ import org.eclipse.edc.transform.transformer.edc.to.JsonValueToGenericTypeTransformer; import static java.util.Collections.emptyMap; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(DataPlaneSelectorClientExtension.NAME) public class DataPlaneSelectorClientExtension implements ServiceExtension { @@ -50,7 +49,7 @@ public class DataPlaneSelectorClientExtension implements ServiceExtension { private ControlApiHttpClient httpClient; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private TypeTransformerRegistry typeTransformerRegistry; @@ -66,7 +65,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { var builderFactory = Json.createBuilderFactory(emptyMap()); - var objectMapper = typeManager.getMapper(JSON_LD); + var objectMapper = jsonLdMapperProvider.get(); typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(builderFactory, objectMapper)); typeTransformerRegistry.register(new JsonObjectFromDataAddressTransformer(builderFactory)); typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer()); @@ -76,7 +75,7 @@ public void initialize(ServiceExtensionContext context) { @Provider public DataPlaneSelectorService dataPlaneSelectorService(ServiceExtensionContext context) { - return new RemoteDataPlaneSelectorService(httpClient, selectorApiUrl, typeManager.getMapper(JSON_LD), typeTransformerRegistry, + return new RemoteDataPlaneSelectorService(httpClient, selectorApiUrl, jsonLdMapperProvider.get(), typeTransformerRegistry, selectionStrategy, jsonLd); } } 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..4b9b910b849 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 @@ -17,11 +17,11 @@ import org.eclipse.edc.connector.dataplane.selector.control.api.transformer.JsonObjectToSelectionRequestTransformer; import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer; import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataAddressTransformer; @@ -37,7 +37,6 @@ import static jakarta.json.Json.createBuilderFactory; import static org.eclipse.edc.connector.dataplane.selector.control.api.DataplaneSelectorControlApiExtension.NAME; import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_TYPE; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(NAME) public class DataplaneSelectorControlApiExtension implements ServiceExtension { @@ -51,7 +50,7 @@ public class DataplaneSelectorControlApiExtension implements ServiceExtension { private JsonObjectValidatorRegistry validatorRegistry; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private TypeTransformerRegistry typeTransformerRegistry; @@ -70,7 +69,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { validatorRegistry.register(DATAPLANE_INSTANCE_TYPE, DataPlaneInstanceValidator.instance()); - var objectMapper = typeManager.getMapper(JSON_LD); + var objectMapper = jsonLdMapperProvider.get(); typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer()); typeTransformerRegistry.register(new JsonObjectToSelectionRequestTransformer()); 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..01bd274cf3a 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 @@ -21,11 +21,11 @@ import org.eclipse.edc.connector.api.signaling.transform.to.JsonObjectToDataFlowTerminateMessageTransformer; import org.eclipse.edc.connector.dataplane.api.controller.v1.DataPlaneSignalingApiController; import org.eclipse.edc.connector.dataplane.spi.manager.DataPlaneManager; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.transform.transformer.dspace.from.JsonObjectFromDataAddressDspaceTransformer; import org.eclipse.edc.transform.transformer.dspace.to.JsonObjectToDataAddressDspaceTransformer; @@ -35,7 +35,6 @@ import java.util.Map; import static org.eclipse.edc.connector.dataplane.api.DataPlaneSignalingApiExtension.NAME; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(NAME) public class DataPlaneSignalingApiExtension implements ServiceExtension { @@ -49,7 +48,7 @@ public class DataPlaneSignalingApiExtension implements ServiceExtension { @Inject private DataPlaneManager dataPlaneManager; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public String name() { @@ -59,7 +58,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { var factory = Json.createBuilderFactory(Map.of()); - var jsonLdMapper = typeManager.getMapper(JSON_LD); + var jsonLdMapper = jsonLdMapperProvider.get(); var signalingApiTypeTransformerRegistry = transformerRegistry.forContext("signaling-api"); signalingApiTypeTransformerRegistry.register(new JsonObjectToDataFlowStartMessageTransformer()); 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..920764b14b5 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 @@ -19,12 +19,12 @@ import org.eclipse.edc.connector.dataplane.spi.manager.DataPlaneManager; import org.eclipse.edc.http.spi.ControlApiHttpClient; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provider; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import java.util.Objects; @@ -35,7 +35,6 @@ import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX; import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; /** * This extension provides an implementation of {@link DataPlaneClient} compliant with the data plane signaling protocol @@ -48,7 +47,7 @@ public class DataPlaneSignalingClientExtension implements ServiceExtension { @Inject(required = false) private ControlApiHttpClient httpClient; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Inject private TypeTransformerRegistry transformerRegistry; @Inject @@ -74,7 +73,7 @@ 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); + var mapper = jsonLdMapperProvider.get(); 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"); 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..31281be54ba 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 @@ -19,19 +19,17 @@ import org.eclipse.edc.connector.api.signaling.transform.from.JsonObjectFromDataFlowSuspendMessageTransformer; import org.eclipse.edc.connector.api.signaling.transform.from.JsonObjectFromDataFlowTerminateMessageTransformer; import org.eclipse.edc.connector.api.signaling.transform.to.JsonObjectToDataFlowResponseMessageTransformer; +import org.eclipse.edc.jsonld.spi.JsonLdObjectMapperProvider; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.transform.transformer.dspace.from.JsonObjectFromDataAddressDspaceTransformer; import org.eclipse.edc.transform.transformer.dspace.to.JsonObjectToDataAddressDspaceTransformer; import java.util.Map; -import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; - /** * This extension registers all the transformers relevant for the data plane signaling protocol */ @@ -44,7 +42,7 @@ public class DataPlaneSignalingClientTransformExtension implements ServiceExtens private TypeTransformerRegistry transformerRegistry; @Inject - private TypeManager typeManager; + private JsonLdObjectMapperProvider jsonLdMapperProvider; @Override public String name() { @@ -53,7 +51,7 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var mapper = typeManager.getMapper(JSON_LD); + var mapper = jsonLdMapperProvider.get(); var factory = Json.createBuilderFactory(Map.of()); var signalingApiTransformerRegistry = transformerRegistry.forContext("signaling-api"); diff --git a/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/JsonLdObjectMapperProvider.java b/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/JsonLdObjectMapperProvider.java new file mode 100644 index 00000000000..fdd4ce0e501 --- /dev/null +++ b/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/JsonLdObjectMapperProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.edc.jsonld.spi; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.edc.runtime.metamodel.annotation.ExtensionPoint; + +/** + * Provides an {@link ObjectMapper} for JSON-LD processing. + */ +@FunctionalInterface +@ExtensionPoint +public interface JsonLdObjectMapperProvider { + + ObjectMapper get(); + +}