use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class PublisherCommonUtils method addWsdl.
/**
* Add WSDL file of an API.
*
* @param fileContentType Content type of the file
* @param fileInputStream Input Stream
* @param api API to which the WSDL belongs to
* @param apiProvider API Provider
* @param tenantDomain Tenant domain of the API
* @throws APIManagementException If an error occurs while adding the WSDL resource
*/
public static void addWsdl(String fileContentType, InputStream fileInputStream, API api, APIProvider apiProvider, String tenantDomain) throws APIManagementException {
ResourceFile wsdlResource;
if (APIConstants.APPLICATION_ZIP.equals(fileContentType) || APIConstants.APPLICATION_X_ZIP_COMPRESSED.equals(fileContentType)) {
wsdlResource = new ResourceFile(fileInputStream, APIConstants.APPLICATION_ZIP);
} else {
wsdlResource = new ResourceFile(fileInputStream, fileContentType);
}
api.setWsdlResource(wsdlResource);
apiProvider.addWSDLResource(api.getUuid(), wsdlResource, null, tenantDomain);
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method importSOAPToRESTAPI.
/**
* Import an API from WSDL as a SOAP-to-REST API
*
* @param fileInputStream file data as input stream
* @param fileDetail file details
* @param url URL of the WSDL
* @param apiToAdd API object to be added to the system (which is not added yet)
* @param organization Organization Identifier
* @return API added api
*/
private API importSOAPToRESTAPI(InputStream fileInputStream, Attachment fileDetail, String url, String wsdlArchiveExtractedPath, API apiToAdd, String organization) throws APIManagementException {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
// adding the api
API createdApi = apiProvider.addAPI(apiToAdd);
String swaggerStr = "";
if (StringUtils.isNotBlank(url)) {
swaggerStr = SOAPOperationBindingUtils.getSoapOperationMappingForUrl(url);
} else if (fileInputStream != null) {
String filename = fileDetail.getContentDisposition().getFilename();
if (filename.endsWith(".zip")) {
swaggerStr = SOAPOperationBindingUtils.getSoapOperationMapping(wsdlArchiveExtractedPath);
} else if (filename.endsWith(".wsdl")) {
byte[] wsdlContent = APIUtil.toByteArray(fileInputStream);
swaggerStr = SOAPOperationBindingUtils.getSoapOperationMapping(wsdlContent);
} else {
throw new APIManagementException(ExceptionCodes.UNSUPPORTED_WSDL_FILE_EXTENSION);
}
}
String updatedSwagger = updateSwagger(createdApi.getUUID(), swaggerStr, organization);
return PublisherCommonUtils.updateAPIBySettingGenerateSequencesFromSwagger(updatedSwagger, createdApi, apiProvider, organization);
} catch (FaultGatewaysException | IOException e) {
throw new APIManagementException("Error while importing WSDL to create a SOAP-to-REST API", e);
}
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method exportAPI.
/**
* Exports an API from API Manager for a given API using the ApiId. ID. Meta information, API icon, documentation,
* WSDL and sequences are exported. This service generates a zipped archive which contains all the above mentioned
* resources for a given API.
*
* @param apiId UUID of an API
* @param name Name of the API that needs to be exported
* @param version Version of the API that needs to be exported
* @param providerName Provider name of the API that needs to be exported
* @param format Format of output documents. Can be YAML or JSON
* @param preserveStatus Preserve API status on export
* @return
*/
@Override
public Response exportAPI(String apiId, String name, String version, String revisionNum, String providerName, String format, Boolean preserveStatus, Boolean exportLatestRevision, MessageContext messageContext) throws APIManagementException {
// If not specified status is preserved by default
preserveStatus = preserveStatus == null || preserveStatus;
// Default export format is YAML
ExportFormat exportFormat = StringUtils.isNotEmpty(format) ? ExportFormat.valueOf(format.toUpperCase()) : ExportFormat.YAML;
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
ImportExportAPI importExportAPI = APIImportExportUtil.getImportExportAPI();
File file = importExportAPI.exportAPI(apiId, name, version, revisionNum, providerName, preserveStatus, exportFormat, Boolean.TRUE, Boolean.FALSE, exportLatestRevision, StringUtils.EMPTY, organization);
return Response.ok(file).header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"").build();
} catch (APIImportExportException e) {
throw new APIManagementException("Error while exporting " + RestApiConstants.RESOURCE_API, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIMappingUtil method getWsdlInfoDTO.
/**
* Retrieves the WSDL info from the API model.
*
* @param model API
* @return WSDL info
*/
public static WSDLInfoDTO getWsdlInfoDTO(API model) {
if (model.getWsdlUrl() == null) {
return null;
}
String wsdlRegistryUri = model.getWsdlUrl().toLowerCase();
WSDLInfoDTO wsdlInfoDTO = new WSDLInfoDTO();
if (wsdlRegistryUri.endsWith(APIConstants.ZIP_FILE_EXTENSION)) {
wsdlInfoDTO.setType(WSDLInfoDTO.TypeEnum.ZIP);
} else if (wsdlRegistryUri.endsWith(APIConstants.WSDL_EXTENSION)) {
wsdlInfoDTO.setType(WSDLInfoDTO.TypeEnum.WSDL);
} else {
log.warn("Unrecognized WSDL type in WSDL url: " + model.getWsdlUrl());
}
return wsdlInfoDTO;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class ExportUtils method addWSDLtoArchive.
/**
* Retrieve WSDL for the exporting API and store it in the archive directory.
*
* @param archivePath File path to export the WSDL
* @param apiIdentifier ID of the requesting API
* @throws APIImportExportException If an error occurs while retrieving WSDL from the registry or
* storing in the archive directory
*/
public static void addWSDLtoArchive(String archivePath, APIIdentifier apiIdentifier, APIProvider apiProvider) throws APIImportExportException {
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
String wsdlPath = APIConstants.API_WSDL_RESOURCE_LOCATION + apiIdentifier.getProviderName() + "--" + apiIdentifier.getApiName() + apiIdentifier.getVersion() + APIConstants.WSDL_FILE_EXTENSION;
try {
ResourceFile wsdlResource = apiProvider.getWSDL(apiIdentifier.getUUID(), tenantDomain);
if (wsdlResource != null) {
CommonUtil.createDirectory(archivePath + File.separator + "WSDL");
try (InputStream wsdlStream = wsdlResource.getContent();
OutputStream outputStream = new FileOutputStream(archivePath + File.separator + "WSDL" + File.separator + apiIdentifier.getApiName() + "-" + apiIdentifier.getVersion() + APIConstants.WSDL_FILE_EXTENSION)) {
IOUtils.copy(wsdlStream, outputStream);
if (log.isDebugEnabled()) {
log.debug("WSDL file: " + wsdlPath + " retrieved successfully");
}
}
} else if (log.isDebugEnabled()) {
log.debug("WSDL resource does not exists in path: " + wsdlPath + ". Skipping WSDL export.");
}
} catch (IOException | APIManagementException e) {
throw new APIImportExportException("I/O error while writing WSDL: " + wsdlPath + " to file", e);
}
}
Aggregations