Skip to content

Commit f57f43a

Browse files
committed
Update federated gw implementation to use new interface model
1 parent 522d8ed commit f57f43a

File tree

14 files changed

+228
-148
lines changed

14 files changed

+228
-148
lines changed

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/GatewayAgentConfiguration.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.wso2.carbon.apimgt.api.model;
2020

21+
import org.wso2.carbon.apimgt.api.APIManagementException;
22+
2123
import java.util.List;
2224

2325
/**
@@ -51,12 +53,12 @@ public interface GatewayAgentConfiguration {
5153
*
5254
* @return String Gateway Feature Catalog
5355
*/
54-
GatewayFeatureCatalog getGatewayFeatureCatalog();
56+
GatewayConfig getGatewayFeatureCatalog() throws APIManagementException;
5557

5658
/**
5759
* This method returns the default hostname template of the external gateway
5860
*
5961
* @return String default hostname template
6062
*/
61-
public String getDefaultHostnameTemplate();
63+
String getDefaultHostnameTemplate();
6264
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.apimgt.api.model;
20+
21+
import java.util.List;
22+
23+
public class GatewayConfig {
24+
private String gatewayType;
25+
private Object supportedFeatures;
26+
private List<String> supportedAPITypes;
27+
28+
public Object getSupportedFeatures() {
29+
return supportedFeatures;
30+
}
31+
32+
public void setSupportedFeatures(Object supportedFeatures) {
33+
this.supportedFeatures = supportedFeatures;
34+
}
35+
36+
public List<String> getSupportedAPITypes() {
37+
return supportedAPITypes;
38+
}
39+
40+
public void setSupportedAPITypes(List<String> supportedAPITypes) {
41+
this.supportedAPITypes = supportedAPITypes;
42+
}
43+
44+
public String getGatewayType() {
45+
return gatewayType;
46+
}
47+
48+
public void setGatewayType(String gatewayType) {
49+
this.gatewayType = gatewayType;
50+
}
51+
}

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.wso2.carbon.apimgt.api.model.ApplicationInfoKeyManager;
5353
import org.wso2.carbon.apimgt.api.model.ConfigurationDto;
5454
import org.wso2.carbon.apimgt.api.model.Environment;
55+
import org.wso2.carbon.apimgt.api.model.GatewayAgentConfiguration;
5556
import org.wso2.carbon.apimgt.api.model.KeyManagerApplicationUsages;
5657
import org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration;
5758
import org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration;
@@ -69,7 +70,6 @@
6970
import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO;
7071
import org.wso2.carbon.apimgt.impl.dao.LabelsDAO;
7172
import org.wso2.carbon.apimgt.impl.dao.constants.SQLConstants;
72-
import org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer;
7373
import org.wso2.carbon.apimgt.impl.dto.ThrottleProperties;
7474
import org.wso2.carbon.apimgt.impl.dto.WorkflowProperties;
7575
import org.wso2.carbon.apimgt.impl.factory.PersistenceFactory;
@@ -811,11 +811,11 @@ private void encryptGatewayConfigurationValues(Environment retrievedGatewayConfi
811811
Environment updatedGatewayConfigurationDto)
812812
throws APIManagementException {
813813

814-
ExternalGatewayDeployer gatewayDeployer = ServiceReferenceHolder.getInstance()
815-
.getExternalGatewayDeployer(updatedGatewayConfigurationDto.getGatewayType());
816-
if (gatewayDeployer != null) {
814+
GatewayAgentConfiguration gatewayConfiguration = ServiceReferenceHolder.getInstance()
815+
.getExternalGatewayConnectorConfiguration(updatedGatewayConfigurationDto.getGatewayType());
816+
if (gatewayConfiguration != null) {
817817
Map<String, String> additionalProperties = updatedGatewayConfigurationDto.getAdditionalProperties();
818-
for (ConfigurationDto configurationDto : gatewayDeployer.getConnectionConfigurations()) {
818+
for (ConfigurationDto configurationDto : gatewayConfiguration.getConnectionConfigurations()) {
819819
if (configurationDto.isMask()) {
820820
String value = additionalProperties.get(configurationDto.getName());
821821
if (APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD.equals(value)) {
@@ -1519,11 +1519,11 @@ private void maskValues(KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
15191519
}
15201520

15211521
private void maskValues(Environment environment) {
1522-
ExternalGatewayDeployer gatewayDeployer = ServiceReferenceHolder.getInstance()
1523-
.getExternalGatewayDeployer(environment.getGatewayType());
1522+
GatewayAgentConfiguration gatewayConfiguration = ServiceReferenceHolder.getInstance()
1523+
.getExternalGatewayConnectorConfiguration(environment.getGatewayType());
15241524

15251525
Map<String, String> additionalProperties = environment.getAdditionalProperties();
1526-
List<ConfigurationDto> connectionConfigurations = gatewayDeployer.getConnectionConfigurations();
1526+
List<ConfigurationDto> connectionConfigurations = gatewayConfiguration.getConnectionConfigurations();
15271527
for (ConfigurationDto connectionConfiguration : connectionConfigurations) {
15281528
if (connectionConfiguration.isMask()) {
15291529
additionalProperties.replace(connectionConfiguration.getName(),

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

+21-13
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
import org.wso2.carbon.apimgt.api.model.DocumentationContent;
6969
import org.wso2.carbon.apimgt.api.model.DocumentationType;
7070
import org.wso2.carbon.apimgt.api.model.Environment;
71+
import org.wso2.carbon.apimgt.api.model.GatewayAgentConfiguration;
72+
import org.wso2.carbon.apimgt.api.model.GatewayDeployer;
7173
import org.wso2.carbon.apimgt.api.model.Identifier;
7274
import org.wso2.carbon.apimgt.api.model.KeyManager;
7375
import org.wso2.carbon.apimgt.api.model.KeyManagerApplicationInfo;
@@ -89,7 +91,6 @@
8991
import org.wso2.carbon.apimgt.api.model.policy.PolicyConstants;
9092
import org.wso2.carbon.apimgt.api.model.webhooks.Subscription;
9193
import org.wso2.carbon.apimgt.api.model.webhooks.Topic;
92-
import org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer;
9394
import org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException;
9495
import org.wso2.carbon.apimgt.impl.dto.ai.ApiChatConfigurationDTO;
9596
import org.wso2.carbon.apimgt.impl.caching.CacheProvider;
@@ -3443,9 +3444,10 @@ private String getOpenAPIDefinitionForDeployment(API api, String environmentName
34433444
hostsWithSchemes = getHostWithSchemeMappingForEnvironment(api, apiTenantDomain, environmentName);
34443445

34453446
Environment environment = APIUtil.getEnvironments().get(environmentName);
3446-
Map<String, ExternalGatewayDeployer> externalGatewayDeployers = ServiceReferenceHolder.getInstance().getExternalGatewayDeployers();
3447-
ExternalGatewayDeployer gatewayDeployer = externalGatewayDeployers.get(environment.getGatewayType());
3448-
if (gatewayDeployer != null) {
3447+
Map<String, GatewayAgentConfiguration> gatewayConfigurations = ServiceReferenceHolder.getInstance()
3448+
.getExternalGatewayConnectorConfigurations();
3449+
GatewayAgentConfiguration gatewayConfiguration = gatewayConfigurations.get(environment.getGatewayType());
3450+
if (gatewayConfiguration != null) {
34493451
api.setContext("");
34503452
updatedDefinition = oasParser.getOASDefinitionForStore(api, definition, hostsWithSchemes, kmId);
34513453
} else {
@@ -3622,26 +3624,32 @@ private Map<String, String> getHostWithSchemeMappingForEnvironment(API api, Stri
36223624
}
36233625

36243626
VHost vhost = VHostUtils.getVhostFromEnvironment(environment, host);
3625-
Map<String, ExternalGatewayDeployer> externalGatewayDeployers = ServiceReferenceHolder.getInstance().getExternalGatewayDeployers();
3626-
ExternalGatewayDeployer gatewayDeployer = externalGatewayDeployers.get(environment.getGatewayType());
3627+
Map<String, GatewayAgentConfiguration> gatewayConfigurations =
3628+
ServiceReferenceHolder.getInstance().getExternalGatewayConnectorConfigurations();
3629+
GatewayAgentConfiguration gatewayConfiguration = gatewayConfigurations.get(environment.getGatewayType());
36273630
try {
3631+
boolean isExternalGateway = false;
3632+
GatewayDeployer gatewayDeployer = null;
3633+
if (gatewayConfiguration != null && StringUtils.isNotEmpty(gatewayConfiguration.getImplementation())) {
3634+
gatewayDeployer = (GatewayDeployer) Class.forName(
3635+
gatewayConfiguration.getImplementation()).getDeclaredConstructor().newInstance();
3636+
isExternalGateway = true;
3637+
}
3638+
36283639
if (StringUtils.containsIgnoreCase(api.getTransports(), APIConstants.HTTP_PROTOCOL)
36293640
&& vhost.getHttpPort() != -1) {
3630-
String httpUrl = gatewayDeployer != null ?
3631-
gatewayDeployer.getAPIExecutionURL(vhost.getHttpUrl(), environment,
3632-
APIUtil.getApiExternalApiMappingReferenceByApiId(api.getUuid(), environment.getUuid())) :
3641+
String httpUrl = isExternalGateway ? gatewayDeployer.getAPIExecutionURL(api.getUuid()) :
36333642
vhost.getHttpUrl();
36343643
hostsWithSchemes.put(APIConstants.HTTP_PROTOCOL, httpUrl);
36353644
}
36363645
if (StringUtils.containsIgnoreCase(api.getTransports(), APIConstants.HTTPS_PROTOCOL)
36373646
&& vhost.getHttpsPort() != -1) {
3638-
String httpsUrl = gatewayDeployer != null ?
3639-
gatewayDeployer.getAPIExecutionURL(vhost.getHttpsUrl(), environment,
3640-
APIUtil.getApiExternalApiMappingReferenceByApiId(api.getUuid(), environment.getUuid())) :
3647+
String httpsUrl = isExternalGateway ? gatewayDeployer.getAPIExecutionURL(api.getUuid()) :
36413648
vhost.getHttpsUrl();
36423649
hostsWithSchemes.put(APIConstants.HTTPS_PROTOCOL, httpsUrl);
36433650
}
3644-
} catch (DeployerException e) {
3651+
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException
3652+
| InvocationTargetException e) {
36453653
throw new APIManagementException(e.getMessage());
36463654
}
36473655
}

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

+20-13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
import org.wso2.carbon.apimgt.api.model.BlockConditionsDTO;
7474
import org.wso2.carbon.apimgt.api.model.Comment;
7575
import org.wso2.carbon.apimgt.api.model.CommentList;
76+
import org.wso2.carbon.apimgt.api.model.GatewayAPIValidationResult;
77+
import org.wso2.carbon.apimgt.api.model.GatewayAgentConfiguration;
78+
import org.wso2.carbon.apimgt.api.model.GatewayDeployer;
7679
import org.wso2.carbon.apimgt.api.model.LLMProvider;
7780
import org.wso2.carbon.apimgt.api.model.Label;
7881
import org.wso2.carbon.apimgt.api.model.SequenceBackendData;
@@ -221,6 +224,7 @@
221224
import java.io.File;
222225
import java.io.IOException;
223226
import java.io.InputStream;
227+
import java.lang.reflect.InvocationTargetException;
224228
import java.net.MalformedURLException;
225229
import java.net.URI;
226230
import java.net.URISyntaxException;
@@ -2090,26 +2094,29 @@ private void validateAndSetAPISecurity(API api) {
20902094
*/
20912095
private static void validateApiWithFederatedGateway(API api) throws APIManagementException {
20922096

2093-
ExternalGatewayDeployer deployer =
2094-
ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(api.getGatewayType());
2095-
if (deployer != null) {
2096-
List<String> errorList = null;
2097-
try {
2097+
try {
2098+
GatewayAgentConfiguration gatewayConfiguration = ServiceReferenceHolder.getInstance().
2099+
getExternalGatewayConnectorConfiguration(api.getGatewayType());
2100+
GatewayDeployer deployer = (GatewayDeployer) Class.forName(gatewayConfiguration.getImplementation())
2101+
.getDeclaredConstructor().newInstance();
2102+
if (deployer != null) {
2103+
GatewayAPIValidationResult errorList = null;
20982104
errorList = deployer.validateApi(api);
2099-
if (!errorList.isEmpty()) {
2105+
if (!errorList.getErrors().isEmpty()) {
21002106
throw new APIManagementException(
21012107
"Error occurred while validating the API with the federated gateway: "
2102-
+ api.getGatewayType(),
2108+
+ api.getGatewayType(),
21032109
ExceptionCodes.from(ExceptionCodes.FEDERATED_GATEWAY_VALIDATION_FAILED,
21042110
api.getGatewayType(), errorList.toString()));
21052111
}
2106-
} catch (DeployerException e) {
2107-
throw new APIManagementException(
2108-
"Error occurred while validating the API with the federated gateway: "
2109-
+ api.getGatewayType(), e,
2110-
ExceptionCodes.from(ExceptionCodes.FEDERATED_GATEWAY_VALIDATION_FAILED,
2111-
api.getGatewayType()));
21122112
}
2113+
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |
2114+
IllegalAccessException | InvocationTargetException e) {
2115+
throw new APIManagementException(
2116+
"Error occurred while validating the API with the federated gateway: "
2117+
+ api.getGatewayType(), e,
2118+
ExceptionCodes.from(ExceptionCodes.FEDERATED_GATEWAY_VALIDATION_FAILED,
2119+
api.getGatewayType()));
21132120
}
21142121
}
21152122

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponent.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.wso2.carbon.apimgt.api.APIMgtInternalException;
4141
import org.wso2.carbon.apimgt.api.LLMProviderService;
4242
import org.wso2.carbon.apimgt.api.OrganizationResolver;
43+
import org.wso2.carbon.apimgt.api.model.GatewayAgentConfiguration;
4344
import org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration;
4445
import org.wso2.carbon.apimgt.api.model.WorkflowTaskService;
4546
import org.wso2.carbon.apimgt.api.quotalimiter.ResourceQuotaLimiter;
@@ -59,7 +60,6 @@
5960
import org.wso2.carbon.apimgt.impl.config.APIMConfigService;
6061
import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO;
6162
import org.wso2.carbon.apimgt.impl.ExternalEnvironment;
62-
import org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer;
6363
import org.wso2.carbon.apimgt.impl.dto.EventHubConfigurationDto;
6464
import org.wso2.carbon.apimgt.impl.dto.ThrottleProperties;
6565
import org.wso2.carbon.apimgt.impl.factory.SQLConstantManagerFactory;
@@ -816,18 +816,18 @@ protected void removeNotifiers(Notifier notifier) {
816816
}
817817

818818
@Reference(
819-
name = "externalGatewayDeployer.component",
820-
service = ExternalGatewayDeployer.class,
819+
name = "external.gateway.connector.service",
820+
service = GatewayAgentConfiguration.class,
821821
cardinality = ReferenceCardinality.MULTIPLE,
822822
policy = ReferencePolicy.DYNAMIC,
823-
unbind = "removeExternalGatewayDeployers")
824-
protected void addExternalGatewayDeployer(ExternalGatewayDeployer deployer) {
825-
ServiceReferenceHolder.getInstance().addExternalGatewayDeployer(deployer.getType(), deployer);
823+
unbind = "removeExternalGatewayConnectorConfigurations")
824+
protected void addExternalGatewayConnectorConfiguration(GatewayAgentConfiguration gatewayConfiguration) {
825+
ServiceReferenceHolder.getInstance().addExternalGatewayConnectorConfiguration(gatewayConfiguration.getType(), gatewayConfiguration);
826826
}
827827

828-
protected void removeExternalGatewayDeployers(ExternalGatewayDeployer deployer) {
828+
protected void removeExternalGatewayConnectorConfigurations(GatewayAgentConfiguration gatewayConfiguration) {
829829

830-
ServiceReferenceHolder.getInstance().removeExternalGatewayDeployer(deployer.getType());
830+
ServiceReferenceHolder.getInstance().removeExternalGatewayConnectorConfiguration(gatewayConfiguration.getType());
831831
}
832832

833833
@Reference(

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/internal/ServiceReferenceHolder.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.wso2.carbon.apimgt.api.APIDefinition;
2020
import org.wso2.carbon.apimgt.api.LLMProviderService;
2121
import org.wso2.carbon.apimgt.api.OrganizationResolver;
22+
import org.wso2.carbon.apimgt.api.model.GatewayAgentConfiguration;
2223
import org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration;
2324
import org.wso2.carbon.apimgt.api.model.WorkflowTaskService;
2425
import org.wso2.carbon.apimgt.api.quotalimiter.ResourceQuotaLimiter;
@@ -28,7 +29,6 @@
2829
import org.wso2.carbon.apimgt.impl.ExternalEnvironment;
2930
import org.wso2.carbon.apimgt.impl.config.APIMConfigService;
3031
import org.wso2.carbon.apimgt.impl.config.APIMConfigServiceImpl;
31-
import org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer;
3232
import org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.ArtifactSaver;
3333
import org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.GatewayArtifactGenerator;
3434
import org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI;
@@ -75,7 +75,7 @@ public class ServiceReferenceHolder {
7575
private ResourceQuotaLimiter resourceQuotaLimiter;
7676
private EventPublisherFactory eventPublisherFactory;
7777
private APIMConfigService apimConfigService;
78-
private Map<String, ExternalGatewayDeployer> externalGatewayDeployers = new HashMap<>();
78+
private Map<String, GatewayAgentConfiguration> gatewayConnectorConfigurationMap = new HashMap<>();
7979
private Map<String, ExternalEnvironment> externalEnvironmentsMap = new HashMap<>();
8080
private Map<String, APIDefinition> apiDefinitionMap = new HashMap<>();
8181
private WorkflowTaskService workflowTaskService;
@@ -324,24 +324,24 @@ public APIMConfigService getApimConfigService() {
324324
}
325325

326326

327-
public void addExternalGatewayDeployer(String type, ExternalGatewayDeployer deployer) {
327+
public void addExternalGatewayConnectorConfiguration(String type, GatewayAgentConfiguration gatewayConfiguration) {
328328

329-
externalGatewayDeployers.put(type, deployer);
329+
gatewayConnectorConfigurationMap.put(type, gatewayConfiguration);
330330
}
331331

332-
public void removeExternalGatewayDeployer(String type) {
332+
public void removeExternalGatewayConnectorConfiguration(String type) {
333333

334-
externalGatewayDeployers.remove(type);
334+
gatewayConnectorConfigurationMap.remove(type);
335335
}
336336

337-
public ExternalGatewayDeployer getExternalGatewayDeployer(String type) {
337+
public GatewayAgentConfiguration getExternalGatewayConnectorConfiguration(String type) {
338338

339-
return externalGatewayDeployers.get(type);
339+
return gatewayConnectorConfigurationMap.get(type);
340340
}
341341

342-
public Map<String, ExternalGatewayDeployer> getExternalGatewayDeployers() {
342+
public Map<String, GatewayAgentConfiguration> getExternalGatewayConnectorConfigurations() {
343343

344-
return externalGatewayDeployers;
344+
return gatewayConnectorConfigurationMap;
345345
}
346346

347347
public void addExternalEnvironment(String type, ExternalEnvironment externalEnvironment) {

0 commit comments

Comments
 (0)