use of org.wso2.carbon.apimgt.api.model.ResourceFile in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPIThumbnail.
/**
* Retrieves the thumbnail image of an API specified by API identifier
*
* @param apiId API Id
* @param ifNoneMatch If-None-Match header value
* @param messageContext If-Modified-Since header value
* @return Thumbnail image of the API
*/
@Override
public Response getAPIThumbnail(String apiId, String ifNoneMatch, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// this will fail if user does not have access to the API or the API does not exist
// APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId, tenantDomain);
ResourceFile thumbnailResource = apiProvider.getIcon(apiId, organization);
if (thumbnailResource != null) {
return Response.ok(thumbnailResource.getContent(), MediaType.valueOf(thumbnailResource.getContentType())).build();
} else {
return Response.noContent().build();
}
} catch (APIManagementException e) {
// existence of the resource
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving thumbnail of API : " + apiId, e, log);
} else {
String errorMessage = "Error while retrieving thumbnail of API : " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.ResourceFile in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getWSDLOfAPI.
/**
* Retrieve the WSDL of an API
*
* @param apiId UUID of the API
* @param ifNoneMatch If-None-Match header value
* @return the WSDL of the API (can be a file or zip archive)
* @throws APIManagementException when error occurred while trying to retrieve the WSDL
*/
@Override
public Response getWSDLOfAPI(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// this will fail if user does not have access to the API or the API does not exist
// APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId, organization);
ResourceFile resource = apiProvider.getWSDL(apiId, organization);
return RestApiUtil.getResponseFromResourceFile(resource.getName(), resource);
} catch (APIManagementException e) {
// to expose the existence of the resource
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving wsdl of API: " + apiId, e, log);
} else {
throw e;
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.ResourceFile in project carbon-apimgt by wso2.
the class PublisherCommonUtils method addDocumentationContentForFile.
/**
* Add documentation content of files.
*
* @param inputStream Input Stream
* @param mediaType Media type of the document
* @param filename File name
* @param apiProvider API Provider
* @param apiId API/API Product UUID
* @param documentId Document ID
* @param organization organization of the API
* @throws APIManagementException If an error occurs while adding the documentation file
*/
public static void addDocumentationContentForFile(InputStream inputStream, String mediaType, String filename, APIProvider apiProvider, String apiId, String documentId, String organization) throws APIManagementException {
DocumentationContent content = new DocumentationContent();
ResourceFile resourceFile = new ResourceFile(inputStream, mediaType);
resourceFile.setName(filename);
content.setResourceFile(resourceFile);
content.setSourceType(DocumentationContent.ContentSourceType.FILE);
apiProvider.addDocumentationContent(apiId, documentId, organization, content);
}
use of org.wso2.carbon.apimgt.api.model.ResourceFile 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.ResourceFile 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