2323import org .eclipse .edc .api .auth .spi .AuthenticationService ;
2424import org .eclipse .edc .api .auth .spi .registry .ApiAuthenticationRegistry ;
2525import org .eclipse .edc .connector .dataplane .spi .pipeline .PipelineService ;
26+ import org .eclipse .edc .runtime .metamodel .annotation .Configuration ;
2627import org .eclipse .edc .runtime .metamodel .annotation .Extension ;
2728import org .eclipse .edc .runtime .metamodel .annotation .Inject ;
2829import org .eclipse .edc .runtime .metamodel .annotation .Setting ;
30+ import org .eclipse .edc .runtime .metamodel .annotation .Settings ;
2931import org .eclipse .edc .spi .monitor .Monitor ;
3032import org .eclipse .edc .spi .security .Vault ;
3133import org .eclipse .edc .spi .system .ServiceExtension ;
3234import org .eclipse .edc .spi .system .ServiceExtensionContext ;
33- import org .eclipse .edc .web .spi .WebServer ;
3435import org .eclipse .edc .web .spi .WebService ;
35- import org .eclipse .edc .web .spi .configuration .WebServiceConfigurer ;
36- import org .eclipse .edc .web .spi .configuration .WebServiceSettings ;
36+ import org .eclipse .edc .web .spi .configuration .PortMapping ;
37+ import org .eclipse .edc .web .spi .configuration .PortMappingRegistry ;
3738import org .eclipse .tractusx .edc .dataplane .proxy .consumer .api .asset .ClientErrorExceptionMapper ;
3839import org .eclipse .tractusx .edc .dataplane .proxy .consumer .api .asset .ConsumerAssetRequestController ;
3940import org .eclipse .tractusx .edc .edr .spi .service .EdrService ;
5051 */
5152@ Extension (value = DataPlaneProxyConsumerApiExtension .NAME )
5253public class DataPlaneProxyConsumerApiExtension implements ServiceExtension {
53- public static final int DEFAULT_THREAD_POOL = 10 ;
54+
55+ public static final String NAME = "Data Plane Proxy Consumer API" ;
56+ private static final String PROXY = "proxy" ;
57+ private static final int DEFAULT_PROXY_PORT = 8186 ;
58+ private static final String DEFAULT_PROXY_PATH = "/proxy" ;
59+ private static final int DEFAULT_THREAD_POOL = 10 ;
60+
5461 @ Setting ("Vault alias for the Consumer Proxy API key" )
5562 public static final String AUTH_SETTING_CONSUMER_PROXY_APIKEY_ALIAS = "tx.edc.dpf.consumer.proxy.auth.apikey.alias" ;
5663 @ Setting ("API key for the Consumer Proxy API" )
5764 public static final String AUTH_SETTING_CONSUMER_PROXY_APIKEY = "tx.edc.dpf.consumer.proxy.auth.apikey" ;
58- static final String NAME = "Data Plane Proxy Consumer API" ;
59- private static final int DEFAULT_PROXY_PORT = 8186 ;
60- private static final String CONSUMER_API_ALIAS = "consumer.api" ;
61- private static final String CONSUMER_CONTEXT_PATH = "/proxy" ;
62- private static final String CONSUMER_CONFIG_KEY = "web.http.proxy" ;
65+
6366 @ Setting (value = "Data plane proxy API consumer port" , type = "int" )
6467 private static final String CONSUMER_PORT = "tx.edc.dpf.consumer.proxy.port" ;
6568 @ Deprecated (since = "0.7.1" )
@@ -72,29 +75,24 @@ public class DataPlaneProxyConsumerApiExtension implements ServiceExtension {
7275 private static final String AUTH_SETTING_APIKEY_ALIAS_DEPRECATED = "edc.api.auth.key.alias" ;
7376 @ Deprecated (since = "0.7.1" )
7477 private static final String AUTH_SETTING_APIKEY_DEPRECATED = "edc.api.auth.key" ;
75- @ Inject
76- private WebService webService ;
7778
78- @ Inject
79- private WebServer webServer ;
79+ @ Configuration
80+ private DataPlaneProxyConsumerApiConfiguration apiConfiguration ;
8081
82+ @ Inject
83+ private WebService webService ;
8184 @ Inject
8285 private PipelineService pipelineService ;
83-
8486 @ Inject
8587 private EdrService edrService ;
86-
87- @ Inject
88- private WebServiceConfigurer configurer ;
89-
9088 @ Inject
9189 private Vault vault ;
92-
9390 @ Inject
9491 private ApiAuthenticationRegistry apiAuthenticationRegistry ;
95-
9692 @ Inject
9793 private Monitor monitor ;
94+ @ Inject
95+ private PortMappingRegistry portMappingRegistry ;
9896
9997 private ExecutorService executorService ;
10098
@@ -105,22 +103,22 @@ public String name() {
105103
106104 @ Override
107105 public void initialize (ServiceExtensionContext context ) {
106+ // when deprecated port will be purged, just assign `apiConfiguration.port()` to `port`
108107 var port = propertyCompatibility (context , CONSUMER_PORT , CONSUMER_PORT_DEPRECATED , DEFAULT_PROXY_PORT );
109- var config = context .getConfig (CONSUMER_CONFIG_KEY );
110-
111- configurer .configure (config , webServer , createApiContext (port ));
108+ var portMapping = new PortMapping (PROXY , port , apiConfiguration .path ());
109+ portMappingRegistry .register (portMapping );
112110
113111 var poolSize = propertyCompatibility (context , THREAD_POOL_SIZE , THREAD_POOL_SIZE_DEPRECATED , DEFAULT_THREAD_POOL );
114112 executorService = newFixedThreadPool (poolSize );
115113
116114 var authenticationService = createAuthenticationService (context );
117- apiAuthenticationRegistry .register (CONSUMER_API_ALIAS , authenticationService );
115+ apiAuthenticationRegistry .register (PROXY , authenticationService );
118116
119- var authenticationFilter = new AuthenticationRequestFilter (apiAuthenticationRegistry , CONSUMER_API_ALIAS );
120- webService .registerResource (CONSUMER_API_ALIAS , authenticationFilter );
117+ var authenticationFilter = new AuthenticationRequestFilter (apiAuthenticationRegistry , PROXY );
118+ webService .registerResource (PROXY , authenticationFilter );
121119
122- webService .registerResource (CONSUMER_API_ALIAS , new ClientErrorExceptionMapper ());
123- webService .registerResource (CONSUMER_API_ALIAS , new ConsumerAssetRequestController (edrService , pipelineService , executorService , monitor ));
120+ webService .registerResource (PROXY , new ClientErrorExceptionMapper ());
121+ webService .registerResource (PROXY , new ConsumerAssetRequestController (edrService , pipelineService , executorService , monitor ));
124122 }
125123
126124 @ Override
@@ -138,14 +136,14 @@ private AuthenticationService createAuthenticationService(ServiceExtensionContex
138136 return new TokenBasedAuthenticationService (context .getMonitor ().withPrefix ("ConsumerProxyAPI" ), apiKey );
139137 }
140138
141- private WebServiceSettings createApiContext ( int port ) {
142- return WebServiceSettings . Builder . newInstance ()
143- . apiConfigKey ( CONSUMER_CONFIG_KEY )
144- . contextAlias ( CONSUMER_API_ALIAS )
145- . defaultPath ( CONSUMER_CONTEXT_PATH )
146- . defaultPort ( port )
147- . name ( NAME )
148- . build ();
139+ @ Settings
140+ record DataPlaneProxyConsumerApiConfiguration (
141+ @ Setting ( key = "web.http." + PROXY + ".port" , description = "Port for " + PROXY + " api context" , defaultValue = DEFAULT_PROXY_PORT + "" )
142+ int port ,
143+ @ Setting ( key = "web.http." + PROXY + ".path" , description = "Path for " + PROXY + " api context" , defaultValue = DEFAULT_PROXY_PATH )
144+ String path
145+ ) {
146+
149147 }
150148
151149}
0 commit comments