use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-apimgt by wso2.
the class AbstractAPIManager method getWsdlById.
/**
* Return Wsdl specify by identifier
*
* @param wsdlId uuid of the wsdl resource
* @return A Wsdl object related to the given identifier or null
* @throws APIManagementException If failed to get specified wsdl
*/
@Override
public Wsdl getWsdlById(String wsdlId) throws APIManagementException {
Wsdl wsdl = null;
// Get registry resource correspond to identifier
Resource wsdlResource = this.getWsdlResourceFromUuid(wsdlId);
if (wsdlResource != null) {
try {
// extracting content stream of wsdl in to string
String contentString = IOUtils.toString(wsdlResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
wsdl = new Wsdl();
String resourcePath = wsdlResource.getPath();
String wsdlName = resourcePath.substring(resourcePath.lastIndexOf("/") + 1);
wsdl.setUuid(wsdlResource.getUUID());
wsdl.setName(wsdlName);
wsdl.setConfig(contentString);
} catch (RegistryException e) {
log.error("Error occurred while getting content stream of the wsdl " + wsdlResource.getPath(), e);
} catch (IOException e) {
log.error("Error occurred while converting content stream of wsdl " + wsdlResource.getPath() + " into string ", e);
}
}
return wsdl;
}
use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-apimgt by wso2.
the class AbstractAPIManager method getGlobalMediationPolicy.
/**
* Return mediation policy corresponds to the given identifier
*
* @param mediationPolicyId uuid of the registry resource
* @return Mediation object related to the given identifier or null
* @throws APIManagementException If failed to get specified mediation policy
*/
@Override
public Mediation getGlobalMediationPolicy(String mediationPolicyId) throws APIManagementException {
Mediation mediation = null;
// Get registry resource correspond to identifier
Resource mediationResource = this.getCustomMediationResourceFromUuid(mediationPolicyId);
if (mediationResource != null) {
// Get mediation config details
try {
// extracting content stream of mediation policy in to string
String contentString = IOUtils.toString(mediationResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
// Get policy name from the mediation config
OMElement omElement = AXIOMUtil.stringToOM(contentString);
OMAttribute attribute = omElement.getAttribute(new QName(PolicyConstants.MEDIATION_NAME_ATTRIBUTE));
String mediationPolicyName = attribute.getAttributeValue();
mediation = new Mediation();
mediation.setUuid(mediationResource.getUUID());
mediation.setName(mediationPolicyName);
String resourcePath = mediationResource.getPath();
// Extracting mediation type from the registry resource path
String[] path = resourcePath.split(RegistryConstants.PATH_SEPARATOR);
String resourceType = path[(path.length - 2)];
mediation.setType(resourceType);
mediation.setConfig(contentString);
} catch (RegistryException e) {
log.error("Error occurred while getting content stream of the ,mediation policy ", e);
} catch (IOException e) {
log.error("Error occurred while converting content stream of mediation policy " + "into string ", e);
} catch (XMLStreamException e) {
log.error("Error occurred while getting omElement out of mediation content ", e);
}
}
return mediation;
}
use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-apimgt by wso2.
the class AbstractAPIManager method updateWsdl.
/**
* Update a existing wsdl in the path specified
*
* @param resourcePath Registry path of the resource
* @param wsdlDefinition wsdl content
*/
@Override
public void updateWsdl(String resourcePath, String wsdlDefinition) throws APIManagementException {
try {
Resource resource = registry.get(resourcePath);
resource.setContent(wsdlDefinition);
registry.put(resourcePath, resource);
} catch (RegistryException e) {
String msg = "Error while updating the existing wsdl ";
throw new APIManagementException(msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAPIDefinitionOfAPIProduct.
@Override
public String getAPIDefinitionOfAPIProduct(APIProduct product) throws APIManagementException {
String resourcePath = APIUtil.getAPIProductOpenAPIDefinitionFilePath(product.getId());
JSONParser parser = new JSONParser();
String apiDocContent = null;
try {
if (registry.resourceExists(resourcePath + APIConstants.API_OAS_DEFINITION_RESOURCE_NAME)) {
Resource apiDocResource = registry.get(resourcePath + APIConstants.API_OAS_DEFINITION_RESOURCE_NAME);
apiDocContent = new String((byte[]) apiDocResource.getContent(), Charset.defaultCharset());
parser.parse(apiDocContent);
} else {
if (log.isDebugEnabled()) {
log.debug("Resource " + APIConstants.API_OAS_DEFINITION_RESOURCE_NAME + " not found at " + resourcePath);
}
}
} catch (RegistryException e) {
handleException("Error while retrieving OpenAPI v2.0 or v3.0.0 Definition for " + product.getId().getName() + '-' + product.getId().getProviderName(), e);
} catch (ParseException e) {
handleException("Error while parsing OpenAPI v2.0 or v3.0.0 Definition for " + product.getId().getName() + '-' + product.getId().getProviderName() + " in " + resourcePath, e);
}
return apiDocContent;
}
use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-apimgt by wso2.
the class AbstractAPIManager method getDocPaths.
/**
* Get API Documents within the provided registry collection
* In case the document names contained '/' character, need to get only leaf node documents within them
*
* @param docCollection registry collection
* @param apiOrAPIProductDocPath base api/api product document path
* @return
* @throws APIManagementException
*/
private List<String> getDocPaths(org.wso2.carbon.registry.core.Collection docCollection, String apiOrAPIProductDocPath) throws APIManagementException {
List<String> docPaths = new ArrayList<>();
String pathToContent = apiOrAPIProductDocPath + APIConstants.INLINE_DOCUMENT_CONTENT_DIR;
String pathToDocFile = apiOrAPIProductDocPath + APIConstants.DOCUMENT_FILE_DIR;
try {
String[] resourcePaths = docCollection.getChildren();
for (String resourcePath : resourcePaths) {
if (!(resourcePath.equals(pathToContent) || resourcePath.equals(pathToDocFile))) {
Resource resource = registry.get(resourcePath);
if (resource instanceof org.wso2.carbon.registry.core.Collection) {
docPaths.addAll(getDocPaths((org.wso2.carbon.registry.core.Collection) resource, apiOrAPIProductDocPath));
} else {
docPaths.add(resourcePath);
}
}
}
} catch (RegistryException e) {
String msg = "Failed to get documents for api/product";
throw new APIManagementException(msg, e);
}
return docPaths;
}
Aggregations