use of org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException in project carbon-apimgt by wso2.
the class AbstractAPIManager method getWSDL.
@Override
public ResourceFile getWSDL(String apiId, String organization) throws APIManagementException {
try {
org.wso2.carbon.apimgt.persistence.dto.ResourceFile resource = apiPersistenceInstance.getWSDL(new Organization(organization), apiId);
if (resource != null) {
ResourceFile resourceFile = new ResourceFile(resource.getContent(), resource.getContentType());
resourceFile.setName(resource.getName());
return resourceFile;
} else {
String msg = "Failed to get WSDL. Artifact corresponding to artifactId " + apiId + " does not exist";
throw new APIMgtResourceNotFoundException(msg);
}
} catch (WSDLPersistenceException e) {
throw new APIManagementException("Error while retrieving wsdl resource for api " + apiId, e);
}
}
use of org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceImpl method getWSDL.
@Override
public ResourceFile getWSDL(Organization org, String apiId) throws WSDLPersistenceException {
boolean isTenantFlowStarted = false;
try {
String tenantDomain = org.getName();
RegistryHolder holder = getRegistry(tenantDomain);
Registry registry = holder.getRegistry();
isTenantFlowStarted = holder.isTenantFlowStarted();
GenericArtifact apiArtifact = getAPIArtifact(apiId, registry);
if (apiArtifact == null) {
return null;
}
String apiProviderName = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
apiProviderName = RegistryPersistenceUtil.replaceEmailDomain(apiProviderName);
String apiName = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME);
String apiVersion = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION);
String apiPath = GovernanceUtils.getArtifactPath(registry, apiId);
int prependIndex = apiPath.lastIndexOf("/api");
String apiSourcePath = apiPath.substring(0, prependIndex);
String wsdlResourcePath = apiSourcePath + RegistryConstants.PATH_SEPARATOR + RegistryPersistenceUtil.createWsdlFileName(apiProviderName, apiName, apiVersion);
String wsdlResourcePathOld = APIConstants.API_WSDL_RESOURCE_LOCATION + RegistryPersistenceUtil.createWsdlFileName(apiProviderName, apiName, apiVersion);
String resourceFileName = apiProviderName + "-" + apiName + "-" + apiVersion;
if (registry.resourceExists(wsdlResourcePath)) {
Resource resource = registry.get(wsdlResourcePath);
ResourceFile returnResource = new ResourceFile(resource.getContentStream(), resource.getMediaType());
returnResource.setName(resourceFileName);
return returnResource;
} else if (registry.resourceExists(wsdlResourcePathOld)) {
Resource resource = registry.get(wsdlResourcePathOld);
ResourceFile returnResource = new ResourceFile(resource.getContentStream(), resource.getMediaType());
returnResource.setName(resourceFileName);
return returnResource;
} else {
wsdlResourcePath = apiSourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_WSDL_ARCHIVE_LOCATION + apiProviderName + APIConstants.WSDL_PROVIDER_SEPERATOR + apiName + apiVersion + APIConstants.ZIP_FILE_EXTENSION;
wsdlResourcePathOld = APIConstants.API_WSDL_RESOURCE_LOCATION + APIConstants.API_WSDL_ARCHIVE_LOCATION + apiProviderName + APIConstants.WSDL_PROVIDER_SEPERATOR + apiName + apiVersion + APIConstants.ZIP_FILE_EXTENSION;
if (registry.resourceExists(wsdlResourcePath)) {
Resource resource = registry.get(wsdlResourcePath);
ResourceFile returnResource = new ResourceFile(resource.getContentStream(), resource.getMediaType());
returnResource.setName(resourceFileName);
return returnResource;
} else if (registry.resourceExists(wsdlResourcePathOld)) {
Resource resource = registry.get(wsdlResourcePathOld);
ResourceFile returnResource = new ResourceFile(resource.getContentStream(), resource.getMediaType());
returnResource.setName(resourceFileName);
return returnResource;
} else {
throw new WSDLPersistenceException("No WSDL found for the API: " + apiId, ExceptionCodes.from(ExceptionCodes.NO_WSDL_AVAILABLE_FOR_API, apiName, apiVersion));
}
}
} catch (RegistryException | APIPersistenceException e) {
String msg = "Error while getting wsdl file from the registry for API: " + apiId.toString();
throw new WSDLPersistenceException(msg, e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
}
use of org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException in project carbon-apimgt by wso2.
the class APIProviderImpl method addWSDLResource.
@Override
public void addWSDLResource(String apiId, ResourceFile resource, String url, String organization) throws APIManagementException {
if (!StringUtils.isEmpty(url)) {
URL wsdlUrl;
try {
wsdlUrl = new URL(url);
} catch (MalformedURLException e) {
throw new APIManagementException("Invalid/Malformed WSDL URL : " + url, e, ExceptionCodes.INVALID_WSDL_URL_EXCEPTION);
}
// Get the WSDL 1.1 or 2.0 processor and process the content based on the version
WSDLProcessor wsdlProcessor = APIMWSDLReader.getWSDLProcessorForUrl(wsdlUrl);
InputStream wsdlContent = wsdlProcessor.getWSDL();
// wsdlResource.setContentStream(wsdlContent);
org.wso2.carbon.apimgt.persistence.dto.ResourceFile wsdlResourceFile = new org.wso2.carbon.apimgt.persistence.dto.ResourceFile(wsdlContent, null);
try {
apiPersistenceInstance.saveWSDL(new Organization(organization), apiId, wsdlResourceFile);
} catch (WSDLPersistenceException e) {
throw new APIManagementException("Error while adding WSDL to api " + apiId, e);
}
} else if (resource != null) {
org.wso2.carbon.apimgt.persistence.dto.ResourceFile wsdlResourceFile = new org.wso2.carbon.apimgt.persistence.dto.ResourceFile(resource.getContent(), resource.getContentType());
try {
apiPersistenceInstance.saveWSDL(new Organization(organization), apiId, wsdlResourceFile);
} catch (WSDLPersistenceException e) {
throw new APIManagementException("Error while adding WSDL to api " + apiId, e);
}
}
}
use of org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceImpl method saveWSDL.
@Override
public void saveWSDL(Organization org, String apiId, ResourceFile wsdlResourceFile) throws WSDLPersistenceException {
boolean isTenantFlowStarted = false;
try {
String tenantDomain = org.getName();
RegistryHolder holder = getRegistry(tenantDomain);
Registry registry = holder.getRegistry();
isTenantFlowStarted = holder.isTenantFlowStarted();
GenericArtifactManager apiArtifactManager = RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY);
GenericArtifact apiArtifact = apiArtifactManager.getGenericArtifact(apiId);
String apiProviderName = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
apiProviderName = RegistryPersistenceUtil.replaceEmailDomain(apiProviderName);
String apiName = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME);
String apiVersion = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION);
String apiSourcePath = RegistryPersistenceUtil.getAPIBasePath(apiProviderName, apiName, apiVersion);
String wsdlResourcePath = null;
boolean isZip = false;
String wsdlResourcePathArchive = apiSourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_WSDL_ARCHIVE_LOCATION + apiProviderName + APIConstants.WSDL_PROVIDER_SEPERATOR + apiName + apiVersion + APIConstants.ZIP_FILE_EXTENSION;
String wsdlResourcePathFile = apiSourcePath + RegistryConstants.PATH_SEPARATOR + RegistryPersistenceUtil.createWsdlFileName(apiProviderName, apiName, apiVersion);
if (APIConstants.APPLICATION_ZIP.equals(wsdlResourceFile.getContentType())) {
wsdlResourcePath = wsdlResourcePathArchive;
isZip = true;
} else {
wsdlResourcePath = wsdlResourcePathFile;
}
String visibility = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VISIBILITY);
String visibleRolesList = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VISIBLE_ROLES);
Resource wsdlResource = registry.newResource();
;
wsdlResource.setContentStream(wsdlResourceFile.getContent());
if (wsdlResourceFile.getContentType() != null) {
wsdlResource.setMediaType(wsdlResourceFile.getContentType());
}
registry.put(wsdlResourcePath, wsdlResource);
// set the anonymous role for wsld resource to avoid basicauth security.
String[] visibleRoles = null;
if (visibleRolesList != null) {
visibleRoles = visibleRolesList.split(",");
}
RegistryPersistenceUtil.setResourcePermissions(apiProviderName, visibility, visibleRoles, wsdlResourcePath);
if (isZip) {
// Delete any WSDL file if exists
if (registry.resourceExists(wsdlResourcePathFile)) {
registry.delete(wsdlResourcePathFile);
}
} else {
// Delete any WSDL archives if exists
if (registry.resourceExists(wsdlResourcePathArchive)) {
registry.delete(wsdlResourcePathArchive);
}
}
String absoluteWSDLResourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + wsdlResourcePath;
String wsdlRegistryPath;
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) {
wsdlRegistryPath = RegistryConstants.PATH_SEPARATOR + "registry" + RegistryConstants.PATH_SEPARATOR + "resource" + absoluteWSDLResourcePath;
} else {
wsdlRegistryPath = "/t/" + tenantDomain + RegistryConstants.PATH_SEPARATOR + "registry" + RegistryConstants.PATH_SEPARATOR + "resource" + absoluteWSDLResourcePath;
}
apiArtifact.setAttribute(APIConstants.API_OVERVIEW_WSDL, wsdlRegistryPath);
apiArtifactManager.updateGenericArtifact(apiArtifact);
} catch (APIPersistenceException | APIManagementException | RegistryException e) {
throw new WSDLPersistenceException("Error while saving the wsdl for api " + apiId, e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
}
Aggregations