Skip to content

Commit

Permalink
fix: add deterministic ObjectMapper for JSON-LD
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Jan 17, 2025
1 parent 65a9f3f commit 9d224fa
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -81,9 +80,9 @@ public class DspCatalogApiExtension implements ServiceExtension {
@Inject
private Monitor monitor;
@Inject
private TypeManager typeManager;
@Inject
private JsonLd jsonLd;
@Inject
private JsonLdObjectMapperProvider objectMapperProvider;

@Override
public String name() {
Expand All @@ -92,7 +91,7 @@ public String name() {

@Override
public void initialize(ServiceExtensionContext context) {
var jsonLdMapper = typeManager.getMapper(JSON_LD);
var jsonLdMapper = objectMapperProvider.get();
registerValidators(DSP_NAMESPACE_V_08);
registerValidators(DSP_NAMESPACE_V_2024_1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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}.
Expand All @@ -53,7 +52,7 @@ public class DspCatalogTransformExtension implements ServiceExtension {
private TypeTransformerRegistry registry;

@Inject
private TypeManager typeManager;
private JsonLdObjectMapperProvider objectMapperProvider;

@Inject
private ParticipantIdMapper participantIdMapper;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -91,7 +90,7 @@ public class DspApiConfigurationExtension implements ServiceExtension {
private DspApiConfiguration apiConfiguration;

@Inject
private TypeManager typeManager;
private JsonLdObjectMapperProvider mapperProvider;
@Inject
private WebService webService;
@Inject
Expand All @@ -118,21 +117,20 @@ 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);
registerNamespaces(DSP_SCOPE_V_2024_1, DSP_NAMESPACE_V_2024_1);

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -90,7 +89,7 @@ public class DspHttpCoreExtension implements ServiceExtension {
@Inject
private TypeTransformerRegistry transformerRegistry;
@Inject
private TypeManager typeManager;
private JsonLdObjectMapperProvider mapperProvider;
@Inject
private JsonLd jsonLdService;
@Inject(required = false)
Expand Down Expand Up @@ -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(), mapperProvider.get(), jsonLdService, dspProtocolParser(), DSP_SCOPE);
}

@Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -74,7 +73,7 @@ public class DspNegotiationApiExtension implements ServiceExtension {
private JsonLd jsonLd;

@Inject
private TypeManager typeManager;
private JsonLdObjectMapperProvider mapperProvider;

@Override
public String name() {
Expand All @@ -83,7 +82,7 @@ public String name() {

@Override
public void initialize(ServiceExtensionContext context) {
var jsonLdMapper = typeManager.getMapper(JSON_LD);
var jsonLdMapper = mapperProvider.get();

registerValidators(DSP_NAMESPACE_V_08);
registerValidators(DSP_NAMESPACE_V_2024_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -49,7 +48,7 @@ public class DspNegotiationHttpDispatcherExtension implements ServiceExtension {
private JsonLdRemoteMessageSerializer remoteMessageSerializer;

@Inject
private TypeManager typeManager;
private JsonLdObjectMapperProvider mapperProvider;

@Inject
private DspProtocolTypeTransformerRegistry dspTransformerRegistry;
Expand All @@ -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, mapperProvider.get(), jsonLd, dspTransformerRegistry);

messageDispatcher.registerMessage(
ContractAgreementMessage.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -67,11 +66,11 @@ public class DspTransferProcessApiExtension implements ServiceExtension {
@Inject
private JsonLd jsonLd;
@Inject
private TypeManager typeManager;
private JsonLdObjectMapperProvider mapperProvider;

@Override
public void initialize(ServiceExtensionContext context) {
var jsonLdMapper = typeManager.getMapper(JSON_LD);
var jsonLdMapper = mapperProvider.get();

registerValidators(DSP_NAMESPACE_V_08);
registerValidators(DSP_NAMESPACE_V_2024_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;


/**
Expand All @@ -59,7 +58,7 @@ public class DspTransferProcessDispatcherExtension implements ServiceExtension {
private JsonLdRemoteMessageSerializer remoteMessageSerializer;

@Inject
private TypeManager typeManager;
private JsonLdObjectMapperProvider mapperProvider;

@Inject
private DspProtocolTypeTransformerRegistry dspTransformerRegistry;
Expand All @@ -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, mapperProvider.get(), jsonLd, dspTransformerRegistry)
);
messageDispatcher.registerMessage(
TransferCompletionMessage.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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}.
Expand All @@ -63,7 +62,7 @@ public class DspTransferProcessTransformExtension implements ServiceExtension {
private TypeTransformerRegistry registry;

@Inject
private TypeManager typeManager;
private JsonLdObjectMapperProvider mapperProvider;

@Override
public String name() {
Expand All @@ -72,7 +71,7 @@ public String name() {

@Override
public void initialize(ServiceExtensionContext context) {
var objectMapper = typeManager.getMapper(JSON_LD);
var objectMapper = mapperProvider.get();

registerV08transformers();
registerV2024transformers();
Expand Down
Loading

0 comments on commit 9d224fa

Please sign in to comment.