use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLArchiveInfo in project carbon-apimgt by wso2.
the class APIConsumerImpl method getWSDLDocument.
// Remove this method once the jaggery store app is removed.
@Deprecated
@Override
public String getWSDLDocument(String username, String tenantDomain, String resourceUrl, Map environmentDetails, Map apiDetails) throws APIManagementException {
if (username == null) {
username = APIConstants.END_USER_ANONYMOUS;
}
if (tenantDomain == null) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
Map<String, Object> docResourceMap = APIUtil.getDocument(username, resourceUrl, tenantDomain);
String wsdlContent = "";
if (log.isDebugEnabled()) {
log.debug("WSDL document resource availability: " + docResourceMap.isEmpty());
}
if (!docResourceMap.isEmpty()) {
try {
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy((InputStream) docResourceMap.get("Data"), arrayOutputStream);
String apiName = (String) apiDetails.get(API_NAME);
String apiVersion = (String) apiDetails.get(API_VERSION);
String apiProvider = (String) apiDetails.get(API_PROVIDER);
String environmentName = (String) environmentDetails.get(ENVIRONMENT_NAME);
String environmentType = (String) environmentDetails.get(ENVIRONMENT_TYPE);
if (log.isDebugEnabled()) {
log.debug("Published SOAP api gateway environment name: " + environmentName + " environment type: " + environmentType);
}
if (resourceUrl.endsWith(APIConstants.ZIP_FILE_EXTENSION)) {
WSDLArchiveInfo archiveInfo = APIMWSDLReader.extractAndValidateWSDLArchive((InputStream) docResourceMap.get("Data")).getWsdlArchiveInfo();
File folderToImport = new File(archiveInfo.getLocation() + File.separator + APIConstants.API_WSDL_EXTRACTED_DIRECTORY);
Collection<File> wsdlFiles = APIFileUtil.searchFilesWithMatchingExtension(folderToImport, APIFileUtil.WSDL_FILE_EXTENSION);
Collection<File> xsdFiles = APIFileUtil.searchFilesWithMatchingExtension(folderToImport, APIFileUtil.XSD_FILE_EXTENSION);
if (wsdlFiles != null) {
for (File foundWSDLFile : wsdlFiles) {
Path fileLocation = Paths.get(foundWSDLFile.getAbsolutePath());
byte[] updatedWSDLContent = this.getUpdatedWSDLByEnvironment(resourceUrl, Files.readAllBytes(fileLocation), environmentName, environmentType, apiName, apiVersion, apiProvider);
File updatedWSDLFile = new File(foundWSDLFile.getPath());
wsdlFiles.remove(foundWSDLFile);
FileUtils.writeByteArrayToFile(updatedWSDLFile, updatedWSDLContent);
wsdlFiles.add(updatedWSDLFile);
}
wsdlFiles.addAll(xsdFiles);
ZIPUtils.zipFiles(folderToImport.getCanonicalPath() + APIConstants.UPDATED_WSDL_ZIP, wsdlFiles);
wsdlContent = folderToImport.getCanonicalPath() + APIConstants.UPDATED_WSDL_ZIP;
}
} else {
arrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy((InputStream) docResourceMap.get("Data"), arrayOutputStream);
byte[] updatedWSDLContent = this.getUpdatedWSDLByEnvironment(resourceUrl, arrayOutputStream.toByteArray(), environmentName, environmentType, apiName, apiVersion, apiProvider);
wsdlContent = new String(updatedWSDLContent);
}
} catch (IOException e) {
handleException("Error occurred while copying wsdl content into byte array stream for resource: " + resourceUrl, e);
}
} else {
handleException("No wsdl resource found for resource path: " + resourceUrl);
}
JSONObject data = new JSONObject();
data.put(APIConstants.DOCUMENTATION_RESOURCE_MAP_CONTENT_TYPE, docResourceMap.get(APIConstants.DOCUMENTATION_RESOURCE_MAP_CONTENT_TYPE));
data.put(APIConstants.DOCUMENTATION_RESOURCE_MAP_NAME, docResourceMap.get(APIConstants.DOCUMENTATION_RESOURCE_MAP_NAME));
data.put(APIConstants.DOCUMENTATION_RESOURCE_MAP_DATA, wsdlContent);
if (log.isDebugEnabled()) {
log.debug("Updated wsdl content details for wsdl resource: " + docResourceMap.get("name") + " is " + data.toJSONString());
}
return data.toJSONString();
}
Aggregations