Skip to content

Commit 564d627

Browse files
authored
refactor: cleanup API config (#4216)
1 parent 968f138 commit 564d627

File tree

103 files changed

+502
-735
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+502
-735
lines changed

data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@
2424
import org.eclipse.edc.protocol.dsp.catalog.http.api.decorator.Base64continuationTokenSerDes;
2525
import org.eclipse.edc.protocol.dsp.catalog.http.api.decorator.ContinuationTokenManagerImpl;
2626
import org.eclipse.edc.protocol.dsp.catalog.http.api.validation.CatalogRequestMessageValidator;
27-
import org.eclipse.edc.protocol.dsp.http.spi.configuration.DspApiConfiguration;
2827
import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler;
2928
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
3029
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
30+
import org.eclipse.edc.spi.protocol.ProtocolWebhook;
3131
import org.eclipse.edc.spi.query.CriterionOperatorRegistry;
3232
import org.eclipse.edc.spi.system.ServiceExtension;
3333
import org.eclipse.edc.spi.system.ServiceExtensionContext;
3434
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
3535
import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
3636
import org.eclipse.edc.web.spi.WebService;
37+
import org.eclipse.edc.web.spi.configuration.ApiContext;
3738

3839
import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE;
3940
import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1;
@@ -49,7 +50,7 @@ public class DspCatalogApiExtension implements ServiceExtension {
4950
@Inject
5051
private WebService webService;
5152
@Inject
52-
private DspApiConfiguration apiConfiguration;
53+
private ProtocolWebhook protocolWebhook;
5354
@Inject
5455
private CatalogProtocolService service;
5556
@Inject
@@ -78,12 +79,12 @@ public void initialize(ServiceExtensionContext context) {
7879

7980
var continuationTokenSerDes = new Base64continuationTokenSerDes(typeTransformerRegistry.forContext("dsp-api"), jsonLd);
8081
var catalogPaginationResponseDecoratorFactory = new ContinuationTokenManagerImpl(continuationTokenSerDes, context.getMonitor());
81-
webService.registerResource(apiConfiguration.getContextAlias(), new DspCatalogApiController(service, dspRequestHandler, catalogPaginationResponseDecoratorFactory));
82-
webService.registerResource(apiConfiguration.getContextAlias(), new DspCatalogApiController20241(service, dspRequestHandler, catalogPaginationResponseDecoratorFactory));
82+
webService.registerResource(ApiContext.PROTOCOL, new DspCatalogApiController(service, dspRequestHandler, catalogPaginationResponseDecoratorFactory));
83+
webService.registerResource(ApiContext.PROTOCOL, new DspCatalogApiController20241(service, dspRequestHandler, catalogPaginationResponseDecoratorFactory));
8384

8485
dataServiceRegistry.register(DataService.Builder.newInstance()
8586
.endpointDescription("dspace:connector")
86-
.endpointUrl(apiConfiguration.getDspCallbackAddress())
87+
.endpointUrl(protocolWebhook.url())
8788
.build());
8889

8990
versionRegistry.register(V_2024_1);

data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
import org.eclipse.edc.jsonld.spi.JsonLd;
2323
import org.eclipse.edc.policy.model.AtomicConstraint;
2424
import org.eclipse.edc.policy.model.LiteralExpression;
25-
import org.eclipse.edc.protocol.dsp.http.spi.configuration.DspApiConfiguration;
2625
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
2726
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
2827
import org.eclipse.edc.runtime.metamodel.annotation.Provides;
28+
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
29+
import org.eclipse.edc.runtime.metamodel.annotation.SettingContext;
2930
import org.eclipse.edc.spi.agent.ParticipantIdMapper;
3031
import org.eclipse.edc.spi.protocol.ProtocolWebhook;
32+
import org.eclipse.edc.spi.system.Hostname;
3133
import org.eclipse.edc.spi.system.ServiceExtension;
3234
import org.eclipse.edc.spi.system.ServiceExtensionContext;
3335
import org.eclipse.edc.spi.types.TypeManager;
@@ -43,11 +45,13 @@
4345
import org.eclipse.edc.web.jersey.providers.jsonld.ObjectMapperProvider;
4446
import org.eclipse.edc.web.spi.WebServer;
4547
import org.eclipse.edc.web.spi.WebService;
48+
import org.eclipse.edc.web.spi.configuration.ApiContext;
4649
import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer;
4750
import org.eclipse.edc.web.spi.configuration.WebServiceSettings;
4851

4952
import java.util.Map;
5053

54+
import static java.lang.String.format;
5155
import static org.eclipse.edc.jsonld.spi.Namespaces.DCAT_PREFIX;
5256
import static org.eclipse.edc.jsonld.spi.Namespaces.DCAT_SCHEMA;
5357
import static org.eclipse.edc.jsonld.spi.Namespaces.DCT_PREFIX;
@@ -60,32 +64,28 @@
6064
import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD;
6165

6266
/**
63-
* Provides the configuration for the Dataspace Protocol API context. Creates the API context
64-
* using {@link #DEFAULT_PROTOCOL_PORT} and {@link #DEFAULT_PROTOCOL_API_PATH}, if no respective
65-
* settings are provided. Configures the API context to allow Jakarta JSON-API types as endpoint
66-
* parameters.
67+
* Configure 'protocol' api context.
6768
*/
6869
@Extension(value = DspApiConfigurationExtension.NAME)
69-
@Provides({ DspApiConfiguration.class, ProtocolWebhook.class })
70+
@Provides(ProtocolWebhook.class)
7071
public class DspApiConfigurationExtension implements ServiceExtension {
7172

7273
public static final String NAME = "Dataspace Protocol API Configuration Extension";
7374

74-
public static final String CONTEXT_ALIAS = "protocol";
75-
76-
public static final String DEFAULT_DSP_CALLBACK_ADDRESS = "http://localhost:8282/api/v1/dsp";
75+
@Setting(value = "Configures endpoint for reaching the Protocol API.", defaultValue = "<hostname:protocol.port/protocol.path>")
7776
public static final String DSP_CALLBACK_ADDRESS = "edc.dsp.callback.address";
7877

79-
public static final int DEFAULT_PROTOCOL_PORT = 8282;
80-
public static final String DEFAULT_PROTOCOL_API_PATH = "/api/v1/dsp";
78+
@SettingContext("Protocol API context setting key")
79+
private static final String PROTOCOL_CONFIG_KEY = "web.http." + ApiContext.PROTOCOL;
8180

8281
public static final WebServiceSettings SETTINGS = WebServiceSettings.Builder.newInstance()
83-
.apiConfigKey("web.http.protocol")
84-
.contextAlias(CONTEXT_ALIAS)
85-
.defaultPath(DEFAULT_PROTOCOL_API_PATH)
86-
.defaultPort(DEFAULT_PROTOCOL_PORT)
82+
.apiConfigKey(PROTOCOL_CONFIG_KEY)
83+
.contextAlias(ApiContext.PROTOCOL)
84+
.defaultPath("/api/v1/dsp")
85+
.defaultPort(8282)
8786
.name("Protocol API")
8887
.build();
88+
8989
@Inject
9090
private TypeManager typeManager;
9191
@Inject
@@ -100,6 +100,8 @@ public class DspApiConfigurationExtension implements ServiceExtension {
100100
private TypeTransformerRegistry transformerRegistry;
101101
@Inject
102102
private ParticipantIdMapper participantIdMapper;
103+
@Inject
104+
private Hostname hostname;
103105

104106
@Override
105107
public String name() {
@@ -108,22 +110,21 @@ public String name() {
108110

109111
@Override
110112
public void initialize(ServiceExtensionContext context) {
111-
var config = configurator.configure(context, webServer, SETTINGS);
112-
var dspWebhookAddress = context.getSetting(DSP_CALLBACK_ADDRESS, DEFAULT_DSP_CALLBACK_ADDRESS);
113-
context.registerService(DspApiConfiguration.class, new DspApiConfiguration(config.getContextAlias(), dspWebhookAddress));
113+
var contextConfig = context.getConfig(PROTOCOL_CONFIG_KEY);
114+
var apiConfiguration = configurator.configure(contextConfig, webServer, SETTINGS);
115+
var dspWebhookAddress = context.getSetting(DSP_CALLBACK_ADDRESS, format("http://%s:%s%s", hostname.get(), apiConfiguration.getPort(), apiConfiguration.getPath()));
114116
context.registerService(ProtocolWebhook.class, () -> dspWebhookAddress);
115117

116118
var jsonLdMapper = typeManager.getMapper(JSON_LD);
117119

118-
119120
// registers ns for DSP scope
120121
jsonLd.registerNamespace(DCAT_PREFIX, DCAT_SCHEMA, DSP_SCOPE);
121122
jsonLd.registerNamespace(DCT_PREFIX, DCT_SCHEMA, DSP_SCOPE);
122123
jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, DSP_SCOPE);
123124
jsonLd.registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, DSP_SCOPE);
124125

125-
webService.registerResource(config.getContextAlias(), new ObjectMapperProvider(jsonLdMapper));
126-
webService.registerResource(config.getContextAlias(), new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE));
126+
webService.registerResource(ApiContext.PROTOCOL, new ObjectMapperProvider(jsonLdMapper));
127+
webService.registerResource(ApiContext.PROTOCOL, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE));
127128

128129
registerTransformers();
129130
}

data-protocols/dsp/dsp-http-api-configuration/src/test/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtensionTest.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
package org.eclipse.edc.protocol.dsp.http.api.configuration;
1616

1717
import org.eclipse.edc.junit.extensions.DependencyInjectionExtension;
18-
import org.eclipse.edc.protocol.dsp.http.spi.configuration.DspApiConfiguration;
18+
import org.eclipse.edc.spi.protocol.ProtocolWebhook;
19+
import org.eclipse.edc.spi.system.Hostname;
1920
import org.eclipse.edc.spi.system.ServiceExtensionContext;
21+
import org.eclipse.edc.spi.system.configuration.Config;
2022
import org.eclipse.edc.spi.system.configuration.ConfigFactory;
2123
import org.eclipse.edc.spi.types.TypeManager;
2224
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
2325
import org.eclipse.edc.web.jersey.providers.jsonld.JerseyJsonLdInterceptor;
2426
import org.eclipse.edc.web.jersey.providers.jsonld.ObjectMapperProvider;
2527
import org.eclipse.edc.web.spi.WebServer;
2628
import org.eclipse.edc.web.spi.WebService;
29+
import org.eclipse.edc.web.spi.configuration.ApiContext;
2730
import org.eclipse.edc.web.spi.configuration.WebServiceConfiguration;
2831
import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer;
2932
import org.junit.jupiter.api.BeforeEach;
@@ -33,8 +36,6 @@
3336
import java.util.Map;
3437

3538
import static org.assertj.core.api.Assertions.assertThat;
36-
import static org.eclipse.edc.protocol.dsp.http.api.configuration.DspApiConfigurationExtension.CONTEXT_ALIAS;
37-
import static org.eclipse.edc.protocol.dsp.http.api.configuration.DspApiConfigurationExtension.DEFAULT_DSP_CALLBACK_ADDRESS;
3839
import static org.eclipse.edc.protocol.dsp.http.api.configuration.DspApiConfigurationExtension.DSP_CALLBACK_ADDRESS;
3940
import static org.eclipse.edc.protocol.dsp.http.api.configuration.DspApiConfigurationExtension.SETTINGS;
4041
import static org.mockito.ArgumentMatchers.any;
@@ -58,55 +59,50 @@ void setUp(ServiceExtensionContext context) {
5859
context.registerService(WebService.class, webService);
5960
context.registerService(WebServiceConfigurer.class, configurer);
6061
context.registerService(TypeManager.class, typeManager);
62+
context.registerService(Hostname.class, () -> "hostname");
6163
TypeTransformerRegistry typeTransformerRegistry = mock();
6264
when(typeTransformerRegistry.forContext(any())).thenReturn(mock());
6365
context.registerService(TypeTransformerRegistry.class, typeTransformerRegistry);
6466

6567
var webServiceConfiguration = WebServiceConfiguration.Builder.newInstance()
66-
.contextAlias(CONTEXT_ALIAS)
6768
.path("/path")
6869
.port(1234)
6970
.build();
70-
when(configurer.configure(any(), any(), any())).thenReturn(webServiceConfiguration);
71+
when(configurer.configure(any(Config.class), any(), any())).thenReturn(webServiceConfiguration);
7172
when(typeManager.getMapper(any())).thenReturn(mock());
7273
}
7374

7475
@Test
75-
void initialize_noSettingsProvided_useDspDefault(DspApiConfigurationExtension extension, ServiceExtensionContext context) {
76+
void shouldComposeProtocolWebhook_whenNotConfigured(DspApiConfigurationExtension extension, ServiceExtensionContext context) {
7677
when(context.getConfig()).thenReturn(ConfigFactory.empty());
77-
when(context.getSetting(DSP_CALLBACK_ADDRESS, DEFAULT_DSP_CALLBACK_ADDRESS)).thenReturn(DEFAULT_DSP_CALLBACK_ADDRESS);
7878

7979
extension.initialize(context);
8080

81-
verify(configurer).configure(context, webServer, SETTINGS);
82-
var apiConfig = context.getService(DspApiConfiguration.class);
83-
assertThat(apiConfig.getContextAlias()).isEqualTo(CONTEXT_ALIAS);
84-
assertThat(apiConfig.getDspCallbackAddress()).isEqualTo(DEFAULT_DSP_CALLBACK_ADDRESS);
81+
verify(configurer).configure(any(Config.class), eq(webServer), eq(SETTINGS));
82+
assertThat(context.getService(ProtocolWebhook.class).url()).isEqualTo("http://hostname:1234/path");
8583
}
8684

8785
@Test
88-
void initialize_settingsProvided_useSettings(DspApiConfigurationExtension extension, ServiceExtensionContext context) {
86+
void shouldUseConfiguredProtocolWebhook(DspApiConfigurationExtension extension, ServiceExtensionContext context) {
8987
var webhookAddress = "http://webhook";
9088
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of(
9189
"web.http.protocol.port", String.valueOf(1234),
9290
"web.http.protocol.path", "/path"))
9391
);
94-
when(context.getSetting(DSP_CALLBACK_ADDRESS, DEFAULT_DSP_CALLBACK_ADDRESS)).thenReturn(webhookAddress);
92+
when(context.getSetting(eq(DSP_CALLBACK_ADDRESS), any())).thenReturn(webhookAddress);
9593

9694
extension.initialize(context);
9795

98-
verify(configurer).configure(context, webServer, SETTINGS);
99-
var apiConfig = context.getService(DspApiConfiguration.class);
100-
assertThat(apiConfig.getContextAlias()).isEqualTo(CONTEXT_ALIAS);
101-
assertThat(apiConfig.getDspCallbackAddress()).isEqualTo(webhookAddress);
96+
verify(configurer).configure(any(Config.class), eq(webServer), eq(SETTINGS));
97+
assertThat(context.getService(ProtocolWebhook.class).url()).isEqualTo("http://webhook");
10298
}
10399

104100
@Test
105101
void initialize_shouldRegisterWebServiceProviders(DspApiConfigurationExtension extension, ServiceExtensionContext context) {
106102
extension.initialize(context);
107103

108-
verify(webService).registerResource(eq(CONTEXT_ALIAS), isA(ObjectMapperProvider.class));
109-
verify(webService).registerResource(eq(CONTEXT_ALIAS), isA(JerseyJsonLdInterceptor.class));
104+
verify(webService).registerResource(eq(ApiContext.PROTOCOL), isA(ObjectMapperProvider.class));
105+
verify(webService).registerResource(eq(ApiContext.PROTOCOL), isA(JerseyJsonLdInterceptor.class));
110106
}
111107

112108
}

data-protocols/dsp/dsp-http-spi/src/main/java/org/eclipse/edc/protocol/dsp/http/spi/configuration/DspApiConfiguration.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import org.eclipse.edc.connector.controlplane.services.spi.contractnegotiation.ContractNegotiationProtocolService;
1818
import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry;
19-
import org.eclipse.edc.protocol.dsp.http.spi.configuration.DspApiConfiguration;
2019
import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler;
2120
import org.eclipse.edc.protocol.dsp.negotiation.http.api.controller.DspNegotiationApiController;
2221
import org.eclipse.edc.protocol.dsp.negotiation.http.api.controller.DspNegotiationApiController20241;
@@ -32,6 +31,7 @@
3231
import org.eclipse.edc.spi.system.ServiceExtensionContext;
3332
import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
3433
import org.eclipse.edc.web.spi.WebService;
34+
import org.eclipse.edc.web.spi.configuration.ApiContext;
3535

3636
import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE;
3737
import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_AGREEMENT_VERIFICATION_MESSAGE;
@@ -52,8 +52,6 @@ public class DspNegotiationApiExtension implements ServiceExtension {
5252
@Inject
5353
private WebService webService;
5454
@Inject
55-
private DspApiConfiguration apiConfiguration;
56-
@Inject
5755
private ContractNegotiationProtocolService protocolService;
5856
@Inject
5957
private JsonObjectValidatorRegistry validatorRegistry;
@@ -76,8 +74,8 @@ public void initialize(ServiceExtensionContext context) {
7674
validatorRegistry.register(DSPACE_TYPE_CONTRACT_AGREEMENT_VERIFICATION_MESSAGE, ContractAgreementVerificationMessageValidator.instance());
7775
validatorRegistry.register(DSPACE_TYPE_CONTRACT_NEGOTIATION_TERMINATION_MESSAGE, ContractNegotiationTerminationMessageValidator.instance());
7876

79-
webService.registerResource(apiConfiguration.getContextAlias(), new DspNegotiationApiController(protocolService, dspRequestHandler));
80-
webService.registerResource(apiConfiguration.getContextAlias(), new DspNegotiationApiController20241(protocolService, dspRequestHandler));
77+
webService.registerResource(ApiContext.PROTOCOL, new DspNegotiationApiController(protocolService, dspRequestHandler));
78+
webService.registerResource(ApiContext.PROTOCOL, new DspNegotiationApiController20241(protocolService, dspRequestHandler));
8179

8280
versionRegistry.register(V_2024_1);
8381
}

data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry;
1818
import org.eclipse.edc.connector.controlplane.services.spi.transferprocess.TransferProcessProtocolService;
19-
import org.eclipse.edc.protocol.dsp.http.spi.configuration.DspApiConfiguration;
2019
import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler;
2120
import org.eclipse.edc.protocol.dsp.transferprocess.http.api.controller.DspTransferProcessApiController;
2221
import org.eclipse.edc.protocol.dsp.transferprocess.http.api.controller.DspTransferProcessApiController20241;
@@ -30,6 +29,7 @@
3029
import org.eclipse.edc.spi.system.ServiceExtensionContext;
3130
import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
3231
import org.eclipse.edc.web.spi.WebService;
32+
import org.eclipse.edc.web.spi.configuration.ApiContext;
3333

3434
import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_COMPLETION_MESSAGE;
3535
import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_REQUEST_MESSAGE;
@@ -45,8 +45,6 @@ public class DspTransferProcessApiExtension implements ServiceExtension {
4545

4646
public static final String NAME = "Dataspace Protocol: TransferProcess API Extension";
4747
@Inject
48-
private DspApiConfiguration config;
49-
@Inject
5048
private WebService webService;
5149
@Inject
5250
private TransferProcessProtocolService transferProcessProtocolService;
@@ -64,8 +62,8 @@ public void initialize(ServiceExtensionContext context) {
6462
validatorRegistry.register(DSPACE_TYPE_TRANSFER_COMPLETION_MESSAGE, TransferCompletionMessageValidator.instance());
6563
validatorRegistry.register(DSPACE_TYPE_TRANSFER_TERMINATION_MESSAGE, TransferTerminationMessageValidator.instance());
6664

67-
webService.registerResource(config.getContextAlias(), new DspTransferProcessApiController(transferProcessProtocolService, dspRequestHandler));
68-
webService.registerResource(config.getContextAlias(), new DspTransferProcessApiController20241(transferProcessProtocolService, dspRequestHandler));
65+
webService.registerResource(ApiContext.PROTOCOL, new DspTransferProcessApiController(transferProcessProtocolService, dspRequestHandler));
66+
webService.registerResource(ApiContext.PROTOCOL, new DspTransferProcessApiController20241(transferProcessProtocolService, dspRequestHandler));
6967

7068
versionRegistry.register(V_2024_1);
7169
}

0 commit comments

Comments
 (0)