diff --git a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/InMemoryAPIDeployer.java b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/InMemoryAPIDeployer.java index 7cb4200c1feb..768ee1bee2db 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/InMemoryAPIDeployer.java +++ b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/InMemoryAPIDeployer.java @@ -329,6 +329,8 @@ private void unDeployAPI(APIGatewayAdmin apiGatewayAdmin, DeployAPIInGatewayEven gatewayAPIDTO); GatewayUtils.setEndpointsToBeRemoved(apiProductIdentifier, associatedApi.getUuid(), gatewayAPIDTO); + GatewayUtils.setCustomBackendToBeRemoved(apiProductIdentifier, associatedApi.getUuid(), + gatewayAPIDTO); } } else { API api = new API(new APIIdentifier(gatewayEvent.getProvider(), gatewayEvent.getName(), diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java index 1506e56d8e28..371a2cc3af8e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java @@ -10029,7 +10029,10 @@ public static void loadCommonOperationPolicies(String organization) { */ public static InputStream getCustomBackendSequence(String extractedFolderPath, String customBackendFileName, String fileExtension) throws APIManagementException { - String fileName = extractedFolderPath + File.separator + customBackendFileName + fileExtension; + if (!StringUtils.isEmpty(customBackendFileName) && !customBackendFileName.contains(fileExtension)) { + customBackendFileName = customBackendFileName + fileExtension; + } + String fileName = extractedFolderPath + File.separator + customBackendFileName; InputStream inputStream = null; if (checkFileExistence(fileName)) { try { @@ -10091,7 +10094,10 @@ public static String getCustomBackendSequenceFromFile(String extractedFolderPath String customBackendContent = null; try { - String fileName = extractedFolderPath + File.separator + sequenceName + fileExtension; + if(!StringUtils.isEmpty(sequenceName) && !sequenceName.contains(".xml")) { + sequenceName = sequenceName + fileExtension; + } + String fileName = extractedFolderPath + File.separator + sequenceName; if (checkFileExistence(fileName)) { if (log.isDebugEnabled()) { log.debug("Found policy definition file " + fileName); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayUtils.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayUtils.java index 62dc26ca8544..bb1f8537a997 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayUtils.java @@ -56,6 +56,17 @@ public static void setCustomBackendToBeRemoved(GatewayAPIDTO gatewayAPIDTO) { addStringToList(productionBackend, gatewayAPIDTO.getSequencesToBeRemove())); } + public static void setCustomBackendToBeRemoved(APIProductIdentifier apiProductIdentifier, String apiUUID, + GatewayAPIDTO gatewayAPIDTO) { + String sandBoxBackend = APIUtil.getCustomBackendName(apiProductIdentifier.getUUID().concat("-" + apiUUID), + APIConstants.API_KEY_TYPE_SANDBOX); + gatewayAPIDTO.setSequencesToBeRemove(addStringToList(sandBoxBackend, gatewayAPIDTO.getSequencesToBeRemove())); + String productionBackend = APIUtil.getCustomBackendName(apiProductIdentifier.getUUID().concat("-" + apiUUID), + APIConstants.API_KEY_TYPE_PRODUCTION); + gatewayAPIDTO.setSequencesToBeRemove( + addStringToList(productionBackend, gatewayAPIDTO.getSequencesToBeRemove())); + } + public static String[] addStringToList(String key, String[] keys) { if (keys == null) { diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/SynapsePolicyAggregator.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/SynapsePolicyAggregator.java index c235b7d9d64d..c204989287fb 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/SynapsePolicyAggregator.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/SynapsePolicyAggregator.java @@ -107,13 +107,30 @@ public static String generatePolicySequenceForUriTemplateSet(Set ur } } - public static String generateBackendSequenceForCustomSequence(String sequenceName, String pathToArchive, + public static String generateSequenceBackendForAPIProducts(String seqName, String prodSeq, String pathToArchive, String endpointType) throws APIManagementException, IOException { Map configMap = new HashMap<>(); String customBackendTemplate = FileUtil.readFileToString(CUSTOM_BACKEND_SEQUENCE_TEMPLATE_LOCATION) .replace("\\", ""); - configMap.put("sequence_name", sequenceName); - String sanitizedSequence = renderCustomBackendSequence(sequenceName, pathToArchive); + // change sequence name from the upper function + configMap.put("sequence_name", prodSeq); + String sanitizedSequence = renderCustomBackendSequence(seqName, pathToArchive); + if (sanitizedSequence == null) { + return null; + } + configMap.put("custom_sequence", sanitizedSequence); + configMap.put("endpoint_type", endpointType); + return renderPolicyTemplate(customBackendTemplate, configMap); + } + + public static String generateBackendSequenceForCustomSequence(String fileName, String pathToArchive, + String endpointType, String apiSeqName) throws APIManagementException, IOException { + Map configMap = new HashMap<>(); + String customBackendTemplate = FileUtil.readFileToString(CUSTOM_BACKEND_SEQUENCE_TEMPLATE_LOCATION) + .replace("\\", ""); + // change sequence name from the upper function + configMap.put("sequence_name", apiSeqName); + String sanitizedSequence = renderCustomBackendSequence(fileName, pathToArchive); if (sanitizedSequence == null) { return null; } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java index 7dbd08d86dde..4df0dddb1f88 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java @@ -45,11 +45,13 @@ import org.wso2.carbon.apimgt.api.model.APIProductResource; import org.wso2.carbon.apimgt.api.model.CORSConfiguration; import org.wso2.carbon.apimgt.api.model.Environment; +import org.wso2.carbon.apimgt.api.model.SequenceBackendData; import org.wso2.carbon.apimgt.api.model.URITemplate; import org.wso2.carbon.apimgt.api.model.WebSocketTopicMappingConfiguration; import org.wso2.carbon.apimgt.common.gateway.graphql.GraphQLSchemaDefinitionUtil; import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.apimgt.impl.certificatemgt.exceptions.CertificateManagementException; +import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO; import org.wso2.carbon.apimgt.impl.definitions.GraphQLSchemaDefinition; import org.wso2.carbon.apimgt.impl.dto.SoapToRestMediationDto; import org.wso2.carbon.apimgt.impl.importexport.ImportExportConstants; @@ -91,6 +93,7 @@ public class TemplateBuilderUtil { private static final String ENDPOINT_SANDBOX = "_SANDBOX_"; private static final Log log = LogFactory.getLog(TemplateBuilderUtil.class); + private static final ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); public static APITemplateBuilderImpl getAPITemplateBuilder(API api, String tenantDomain, List clientCertificateDTOSProduction, @@ -522,14 +525,30 @@ public static GatewayAPIDTO retrieveGatewayAPIDto(API api, Environment environme String policyDirectory = extractedFolderPath + File.separator + ImportExportConstants.CUSTOM_BACKEND_DIRECTORY; String seqName = APIUtil.getCustomBackendName(api.getUuid(), APIConstants.API_KEY_TYPE_SANDBOX); - if (APIUtil.checkFileExistence(policyDirectory + File.separator + seqName - + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML)) { - endpointConfig.put("sandbox", seqName); + SequenceBackendData seqData = apiMgtDAO.getCustomBackendByAPIUUID(api.getUuid(), + APIConstants.API_KEY_TYPE_SANDBOX); + if (seqData != null) { + String name = seqData.getName(); + if (!StringUtils.isEmpty(name) && !name.contains( + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML)) { + name = name + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML; + } + if (APIUtil.checkFileExistence(policyDirectory + File.separator + name)) { + endpointConfig.put("sandbox", seqName); + } } + seqName = APIUtil.getCustomBackendName(api.getUuid(), APIConstants.API_KEY_TYPE_PRODUCTION); - if (APIUtil.checkFileExistence(policyDirectory + File.separator + seqName - + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML)) { - endpointConfig.put("production", seqName); + seqData = apiMgtDAO.getCustomBackendByAPIUUID(api.getUuid(), APIConstants.API_KEY_TYPE_PRODUCTION); + if (seqData != null) { + String name = seqData.getName(); + if (!StringUtils.isEmpty(name) && !name.contains( + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML)) { + name = name + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML; + } + if (APIUtil.checkFileExistence(policyDirectory + File.separator + name)) { + endpointConfig.put("production", seqName); + } } api.setEndpointConfig(objectMapper.writeValueAsString(endpointConfig)); } @@ -729,16 +748,15 @@ private static void setCustomSequencesToBeAdded(APIProduct apiProduct, API api, JsonObject endpointConfigMap = JsonParser.parseString(api.getEndpointConfig()).getAsJsonObject(); if (endpointConfigMap != null && APIConstants.ENDPOINT_TYPE_SEQUENCE.equals( - endpointConfigMap.get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString()) && ( - APIConstants.API_TYPE_HTTP.equals(api.getType()) || APIConstants.API_TYPE_SOAPTOREST.equals( - api.getType()))) { - GatewayContentDTO gatewayCustomBackendSequenceDTO = retrieveCustomBackendSequence(api, - APIConstants.API_KEY_TYPE_SANDBOX, extractedPath); + endpointConfigMap.get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString()) + && APIConstants.API_TYPE_HTTP.equals(api.getType())) { + GatewayContentDTO gatewayCustomBackendSequenceDTO = retrieveSequenceBackendForAPIProduct(api, + apiProduct, APIConstants.API_KEY_TYPE_SANDBOX, extractedPath); if (gatewayCustomBackendSequenceDTO != null) { gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayCustomBackendSequenceDTO, gatewayAPIDTO.getSequenceToBeAdd())); } - gatewayCustomBackendSequenceDTO = retrieveCustomBackendSequence(api, + gatewayCustomBackendSequenceDTO = retrieveSequenceBackendForAPIProduct(api, apiProduct, APIConstants.API_KEY_TYPE_PRODUCTION, extractedPath); if (gatewayCustomBackendSequenceDTO != null) { gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayCustomBackendSequenceDTO, @@ -1442,32 +1460,74 @@ private static GatewayContentDTO retrieveOperationPolicySequence(String pathToAc return null; } - private static GatewayContentDTO retrieveCustomBackendSequence(API api, String endpointType, String pathToAchieve) - throws APIManagementException { + private static GatewayContentDTO retrieveSequenceBackendForAPIProduct(API api, APIProduct apiProduct, + String endpointType, String pathToAchieve) throws APIManagementException { GatewayContentDTO customBackendSequenceContentDto = new GatewayContentDTO(); - String customSequence = null; - String seqExt = APIUtil.getCustomBackendName(api.getUuid(), endpointType); - try { - customSequence = SynapsePolicyAggregator.generateBackendSequenceForCustomSequence(seqExt, pathToAchieve, + SequenceBackendData data = apiMgtDAO.getCustomBackendByAPIUUID(api.getUuid(), endpointType); + if (data != null) { + String seqExt = data.getName(); + if (!StringUtils.isEmpty(seqExt) && seqExt.contains(".xml")) { + seqExt = seqExt + ".xml"; + } + String prodSeqExt = APIUtil.getCustomBackendName(apiProduct.getUuid().concat("-" + api.getUuid()), endpointType); - } catch (IOException e) { - throw new APIManagementException(e); + try { + customSequence = SynapsePolicyAggregator.generateSequenceBackendForAPIProducts(seqExt, prodSeqExt, + pathToAchieve, endpointType); + } catch (IOException e) { + throw new APIManagementException(e); + } + + if (StringUtils.isNotEmpty(customSequence)) { + try { + OMElement omElement = APIUtil.buildOMElement(new ByteArrayInputStream(customSequence.getBytes())); + if (omElement != null) { + if (omElement.getAttribute(new QName("name")) != null) { + omElement.getAttribute(new QName("name")).setAttributeValue(prodSeqExt); + } + customBackendSequenceContentDto.setName(prodSeqExt); + customBackendSequenceContentDto.setContent(APIUtil.convertOMtoString(omElement)); + return customBackendSequenceContentDto; + } + } catch (Exception e) { + throw new APIManagementException(e); + } + } } - if (StringUtils.isNotEmpty(customSequence)) { + return null; + } + + private static GatewayContentDTO retrieveCustomBackendSequence(API api, String endpointType, String pathToAchieve) + throws APIManagementException { + GatewayContentDTO customBackendSequenceContentDto = new GatewayContentDTO(); + String customSequence = null; + SequenceBackendData data = apiMgtDAO.getCustomBackendByAPIUUID(api.getUuid(), endpointType); + if (data != null) { + String seqExt = data.getName(); + String apiSeqName = APIUtil.getCustomBackendName(api.getUuid(), endpointType); try { - OMElement omElement = APIUtil.buildOMElement(new ByteArrayInputStream(customSequence.getBytes())); - if (omElement != null) { - if (omElement.getAttribute(new QName("name")) != null) { - omElement.getAttribute(new QName("name")).setAttributeValue(seqExt); + customSequence = SynapsePolicyAggregator.generateBackendSequenceForCustomSequence(seqExt, pathToAchieve, + endpointType, apiSeqName); + } catch (IOException e) { + throw new APIManagementException(e); + } + + if (StringUtils.isNotEmpty(customSequence)) { + try { + OMElement omElement = APIUtil.buildOMElement(new ByteArrayInputStream(customSequence.getBytes())); + if (omElement != null) { + if (omElement.getAttribute(new QName("name")) != null) { + omElement.getAttribute(new QName("name")).setAttributeValue(apiSeqName); + } + customBackendSequenceContentDto.setName(apiSeqName); + customBackendSequenceContentDto.setContent(APIUtil.convertOMtoString(omElement)); + return customBackendSequenceContentDto; } - customBackendSequenceContentDto.setName(seqExt); - customBackendSequenceContentDto.setContent(APIUtil.convertOMtoString(omElement)); - return customBackendSequenceContentDto; + } catch (Exception e) { + throw new APIManagementException(e); } - } catch (Exception e) { - throw new APIManagementException(e); } } return null; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java index c4c0849a926d..b35d2a235eea 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java @@ -224,30 +224,24 @@ public static File exportApi(APIProvider apiProvider, APIIdentifier apiIdentifie if (APIConstants.ENDPOINT_TYPE_SEQUENCE.equals( endpointConfig.get(API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString()) && StringUtils.equals( apiDtoToReturn.getType().toString().toLowerCase(), APIConstants.API_TYPE_HTTP.toLowerCase())) { - String sandSequenceName = null; - String prodSequenceName = null; - if (endpointConfig.get("sandbox") != null) { - sandSequenceName = endpointConfig.get("sandbox").getAsString(); - } else { - sandSequenceName = apiProvider.getCustomBackendSequenceOfAPIByUUID(currentApiUuid, - APIConstants.API_KEY_TYPE_SANDBOX); - } - if (endpointConfig.get("production") != null) { - prodSequenceName = endpointConfig.get("production").getAsString(); - } else { - prodSequenceName = apiProvider.getCustomBackendSequenceOfAPIByUUID(currentApiUuid, - APIConstants.API_KEY_TYPE_PRODUCTION); - } if (apiDtoToReturn.getEndpointConfig() != null) { Map endpointConf = (Map) apiDtoToReturn.getEndpointConfig(); if (endpointConf != null && APIConstants.ENDPOINT_TYPE_SEQUENCE.equals( endpointConf.get(API_ENDPOINT_CONFIG_PROTOCOL_TYPE))) { - endpointConf.put("sandbox", sandSequenceName); - endpointConf.put("production", prodSequenceName); + SequenceBackendData sqData = apiProvider.getCustomBackendByAPIUUID(currentApiUuid, + APIConstants.API_KEY_TYPE_SANDBOX); + if (sqData != null) { + endpointConf.put("sandbox", sqData.getName()); + } + sqData = apiProvider.getCustomBackendByAPIUUID(currentApiUuid, + APIConstants.API_KEY_TYPE_PRODUCTION); + if (sqData != null) { + endpointConf.put("production", sqData.getName()); + } apiDtoToReturn.setEndpointConfig(endpointConf); } } - addCustomBackendToArchive(archivePath, apiProvider, currentApiUuid, sandSequenceName, prodSequenceName); + addCustomBackendToArchive(archivePath, apiProvider, currentApiUuid); } } @@ -663,8 +657,8 @@ public static void addEndpointCertificatesToArchive(String archivePath, APIDTO a } } - public static void addCustomBackendToArchive(String archivePath, APIProvider apiProvider, String apiUUID, - String prodBackendName, String sandBackendName) throws APIManagementException { + public static void addCustomBackendToArchive(String archivePath, APIProvider apiProvider, String apiUUID) + throws APIManagementException { try { CommonUtil.createDirectory(archivePath + File.separator + ImportExportConstants.CUSTOM_BACKEND_DIRECTORY); @@ -672,20 +666,14 @@ public static void addCustomBackendToArchive(String archivePath, APIProvider api SequenceBackendData data = apiProvider.getCustomBackendByAPIUUID(apiUUID, APIConstants.API_KEY_TYPE_PRODUCTION); if (data != null) { - String seqName = prodBackendName; - if (StringUtils.isEmpty(seqName)) { - seqName = APIUtil.getCustomBackendName(apiUUID, APIConstants.API_KEY_TYPE_PRODUCTION); - } + String seqName = data.getName(); exportCustomBackend(seqName, data.getSequence(), archivePath); } // Add sandbox Backend Sequences data = apiProvider.getCustomBackendByAPIUUID(apiUUID, APIConstants.API_KEY_TYPE_SANDBOX); if (data != null) { - String seqName = sandBackendName; - if (StringUtils.isEmpty(seqName)) { - seqName = APIUtil.getCustomBackendName(apiUUID, APIConstants.API_KEY_TYPE_SANDBOX); - } + String seqName = data.getName(); exportCustomBackend(seqName, data.getSequence(), archivePath); } @@ -813,10 +801,14 @@ public static void exportPolicyData(String policyFileName, OperationPolicyData p */ public static void exportCustomBackend(String customBackendFileName, String sequence, String archivePath) throws APIImportExportException, IOException { + if (!StringUtils.isEmpty(customBackendFileName) && !customBackendFileName.contains( + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML)) { + customBackendFileName = customBackendFileName + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML; + } String customBackendName = archivePath + File.separator + ImportExportConstants.CUSTOM_BACKEND_DIRECTORY + File.separator + customBackendFileName; - CommonUtil.writeFile(customBackendName + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML, sequence); + CommonUtil.writeFile(customBackendName, sequence); } /** diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java index d76ce0f024f1..252165dd0654 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java @@ -702,15 +702,23 @@ public static void updateAPIWithCustomBackend(API api, String extractedFolderPat String seqFile = endpointConfig.get("sandbox").getAsString(); String seqId = UUID.randomUUID().toString(); InputStream seq = APIUtil.getCustomBackendSequence(customBackendDir, seqFile, ".xml"); - apiProvider.updateCustomBackend(api.getUuid(), APIConstants.API_KEY_TYPE_SANDBOX, seq, - seqFile + ".xml", seqId); + if (!StringUtils.isEmpty(seqFile) && !seqFile.contains( + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML)) { + seqFile = seqFile + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML; + } + apiProvider.updateCustomBackend(api.getUuid(), APIConstants.API_KEY_TYPE_SANDBOX, seq, seqFile, + seqId); } if (endpointConfig.get("production") != null) { String seqFile = endpointConfig.get("production").getAsString(); String seqId = UUID.randomUUID().toString(); InputStream seq = APIUtil.getCustomBackendSequence(customBackendDir, seqFile, ".xml"); - apiProvider.updateCustomBackend(api.getUuid(), APIConstants.API_KEY_TYPE_PRODUCTION, seq, - seqFile + ".xml", seqId); + if (!StringUtils.isEmpty(seqFile) && !seqFile.contains( + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML)) { + seqFile = seqFile + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML; + } + apiProvider.updateCustomBackend(api.getUuid(), APIConstants.API_KEY_TYPE_PRODUCTION, seq, seqFile, + seqId); } } }