|
111 | 111 | import org.wso2.carbon.apimgt.api.model.DocumentationType;
|
112 | 112 | import org.wso2.carbon.apimgt.api.model.EndpointSecurity;
|
113 | 113 | import org.wso2.carbon.apimgt.api.model.Environment;
|
| 114 | +import org.wso2.carbon.apimgt.api.model.GatewayAPIValidationResult; |
114 | 115 | import org.wso2.carbon.apimgt.api.model.GatewayAgentConfiguration;
|
115 | 116 | import org.wso2.carbon.apimgt.api.model.GatewayConfiguration;
|
| 117 | +import org.wso2.carbon.apimgt.api.model.GatewayDeployer; |
116 | 118 | import org.wso2.carbon.apimgt.api.model.GatewayPortalConfiguration;
|
117 | 119 | import org.wso2.carbon.apimgt.api.model.GatewayFeatureCatalog;
|
118 | 120 | import org.wso2.carbon.apimgt.api.model.Identifier;
|
|
160 | 162 | import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
161 | 163 | import org.wso2.carbon.apimgt.impl.APIType;
|
162 | 164 | import org.wso2.carbon.apimgt.impl.ExternalEnvironment;
|
| 165 | +import org.wso2.carbon.apimgt.impl.ExternalGatewayAPIValidationException; |
163 | 166 | import org.wso2.carbon.apimgt.impl.IDPConfiguration;
|
164 | 167 | import org.wso2.carbon.apimgt.impl.PasswordResolverFactory;
|
165 | 168 | import org.wso2.carbon.apimgt.impl.RESTAPICacheConfiguration;
|
|
252 | 255 | import java.io.InputStreamReader;
|
253 | 256 | import java.io.StringWriter;
|
254 | 257 | import java.io.UnsupportedEncodingException;
|
| 258 | +import java.lang.reflect.InvocationTargetException; |
255 | 259 | import java.lang.reflect.Type;
|
256 | 260 | import java.math.BigDecimal;
|
257 | 261 | import java.math.BigInteger;
|
@@ -11437,4 +11441,36 @@ public static String getOrganizationHandle(String name) {
|
11437 | 11441 | sanatizedName = sanatizedName.toLowerCase(Locale.ENGLISH).replaceAll("^-+|-+$", "");
|
11438 | 11442 | return sanatizedName;
|
11439 | 11443 | }
|
| 11444 | + |
| 11445 | + /** |
| 11446 | + * Validate Api with the federated gateways |
| 11447 | + * |
| 11448 | + * @param api API Object |
| 11449 | + */ |
| 11450 | + public static void validateApiWithFederatedGateway(API api) throws APIManagementException { |
| 11451 | + |
| 11452 | + try { |
| 11453 | + GatewayAgentConfiguration gatewayConfiguration = org.wso2.carbon.apimgt.impl.internal. |
| 11454 | + ServiceReferenceHolder.getInstance(). |
| 11455 | + getExternalGatewayConnectorConfiguration(api.getGatewayType()); |
| 11456 | + GatewayDeployer deployer = (GatewayDeployer) Class.forName(gatewayConfiguration.getImplementation()) |
| 11457 | + .getDeclaredConstructor().newInstance(); |
| 11458 | + if (deployer != null) { |
| 11459 | + GatewayAPIValidationResult errorList = null; |
| 11460 | + errorList = deployer.validateApi(api); |
| 11461 | + if (!errorList.getErrors().isEmpty()) { |
| 11462 | + throw new ExternalGatewayAPIValidationException( |
| 11463 | + "Error occurred while validating the API with the federated gateway: " |
| 11464 | + + api.getGatewayType(), |
| 11465 | + ExceptionCodes.from(ExceptionCodes.FEDERATED_GATEWAY_VALIDATION_FAILED, |
| 11466 | + api.getGatewayType(), errorList.toString())); |
| 11467 | + } |
| 11468 | + } |
| 11469 | + } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | |
| 11470 | + IllegalAccessException | InvocationTargetException e) { |
| 11471 | + throw new APIManagementException( |
| 11472 | + "Error occurred while validating the API with the federated gateway: " |
| 11473 | + + api.getGatewayType(), e); |
| 11474 | + } |
| 11475 | + } |
11440 | 11476 | }
|
0 commit comments