use of org.wso2.carbon.apimgt.api.model.Identifier in project ballerina by ballerina-lang.
the class IdentifierLiteralServiceTest method testIdentifierLiteralsInPayload.
@Test(description = "Test identifier literals payload", enabled = false)
public void testIdentifierLiteralsInPayload() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/identifierLiteral/resource2", "GET");
HTTPCarbonMessage response = Services.invokeNew(application, cMsg);
Assert.assertNotNull(response);
String payload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(payload, "hello");
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getApiSpecificMediationPolicy.
/**
* Returns Mediation policy specify by given identifier
*
* @param identifier API or Product identifier
* @param apiResourcePath registry path to the API resource
* @param mediationPolicyId mediation policy identifier
* @return Mediation object contains details of the mediation policy or null
*/
@Override
public Mediation getApiSpecificMediationPolicy(Identifier identifier, String apiResourcePath, String mediationPolicyId) throws APIManagementException {
// Get registry resource correspond to given policy identifier
Resource mediationResource = getApiSpecificMediationResourceFromUuid(identifier, mediationPolicyId, apiResourcePath);
Mediation mediation = null;
if (mediationResource != null) {
try {
// Get mediation policy config content
String contentString = IOUtils.toString(mediationResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
// Extracting name specified in the mediation config
OMElement omElement = AXIOMUtil.stringToOM(contentString);
OMAttribute attribute = omElement.getAttribute(new QName("name"));
String mediationPolicyName = attribute.getAttributeValue();
mediation = new Mediation();
mediation.setUuid(mediationResource.getUUID());
mediation.setName(mediationPolicyName);
// Extracting mediation policy type from registry path
String resourcePath = mediationResource.getPath();
String[] path = resourcePath.split(RegistryConstants.PATH_SEPARATOR);
String resourceType = path[(path.length - 2)];
mediation.setType(resourceType);
mediation.setConfig(contentString);
} catch (XMLStreamException e) {
String errorMsg = "Error occurred while getting omElement out of mediation content";
throw new APIManagementException(errorMsg, e);
} catch (IOException e) {
String errorMsg = "Error occurred while converting content stream into string ";
throw new APIManagementException(errorMsg, e);
} catch (RegistryException e) {
String errorMsg = "Error occurred while accessing content stream of mediation" + " policy";
throw new APIManagementException(errorMsg, e);
}
}
return mediation;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAllDocumentation.
public List<Documentation> getAllDocumentation(Identifier id) throws APIManagementException {
List<Documentation> documentationList = new ArrayList<Documentation>();
String docArtifactKeyType = StringUtils.EMPTY;
docArtifactKeyType = APIConstants.DOCUMENTATION_KEY;
String apiOrAPIProductDocPath;
APIRevision apiRevision = apiMgtDAO.checkAPIUUIDIsARevisionUUID(id.getUUID());
if (apiRevision != null && apiRevision.getApiUUID() != null) {
apiOrAPIProductDocPath = APIUtil.getAPIOrAPIProductRevisionDocPath(apiRevision.getApiUUID(), apiRevision.getId());
} else {
apiOrAPIProductDocPath = APIUtil.getAPIOrAPIProductDocPath(id);
}
String pathToContent = apiOrAPIProductDocPath + APIConstants.INLINE_DOCUMENT_CONTENT_DIR;
String pathToDocFile = apiOrAPIProductDocPath + APIConstants.DOCUMENT_FILE_DIR;
try {
if (registry.resourceExists(apiOrAPIProductDocPath)) {
Resource resource = registry.get(apiOrAPIProductDocPath);
if (resource instanceof org.wso2.carbon.registry.core.Collection) {
List<String> docPaths = getDocPaths((org.wso2.carbon.registry.core.Collection) resource, apiOrAPIProductDocPath);
for (String docPath : docPaths) {
if (!(docPath.equalsIgnoreCase(pathToContent) || docPath.equalsIgnoreCase(pathToDocFile))) {
Resource docResource = registry.get(docPath);
GenericArtifactManager artifactManager = getAPIGenericArtifactManager(registry, docArtifactKeyType);
GenericArtifact docArtifact = artifactManager.getGenericArtifact(docResource.getUUID());
Documentation doc = APIUtil.getDocumentation(docArtifact);
Date contentLastModifiedDate;
Date docLastModifiedDate = docResource.getLastModified();
if (Documentation.DocumentSourceType.INLINE.equals(doc.getSourceType()) || Documentation.DocumentSourceType.MARKDOWN.equals(doc.getSourceType())) {
String contentPath = StringUtils.EMPTY;
if (id instanceof APIIdentifier) {
contentPath = APIUtil.getAPIDocContentPath((APIIdentifier) id, doc.getName());
} else if (id instanceof APIProductIdentifier) {
contentPath = APIUtil.getProductDocContentPath((APIProductIdentifier) id, doc.getName());
}
contentLastModifiedDate = registry.get(contentPath).getLastModified();
doc.setLastUpdated((contentLastModifiedDate.after(docLastModifiedDate) ? contentLastModifiedDate : docLastModifiedDate));
} else {
doc.setLastUpdated(docLastModifiedDate);
}
documentationList.add(doc);
}
}
}
}
} catch (RegistryException e) {
String msg = "Failed to get documentations for api/product " + id.getName();
throw new APIManagementException(msg, e);
}
return documentationList;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getWSDL.
/**
* Returns the wsdl content in registry specified by the wsdl name
*
* @param apiId Api Identifier
* @return wsdl content matching name if exist else null
*/
@Override
public ResourceFile getWSDL(APIIdentifier apiId) throws APIManagementException {
String apiPath = APIUtil.getAPIPath(apiId);
int prependIndex = apiPath.indexOf(apiId.getVersion()) + apiId.getVersion().length();
String apiSourcePath = apiPath.substring(0, prependIndex);
String wsdlResourcePath = apiSourcePath + RegistryConstants.PATH_SEPARATOR + APIUtil.createWsdlFileName(apiId.getProviderName(), apiId.getApiName(), apiId.getVersion());
String wsdlResourcePathOld = APIConstants.API_WSDL_RESOURCE_LOCATION + APIUtil.createWsdlFileName(apiId.getProviderName(), apiId.getApiName(), apiId.getVersion());
String tenantDomain = getTenantDomain(apiId);
boolean isTenantFlowStarted = false;
try {
Registry registry;
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
isTenantFlowStarted = true;
startTenantFlow(tenantDomain);
int id = getTenantManager().getTenantId(tenantDomain);
registry = getRegistryService().getGovernanceSystemRegistry(id);
} else {
if (this.tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(this.tenantDomain)) {
registry = getRegistryService().getGovernanceUserRegistry(apiId.getProviderName(), MultitenantConstants.SUPER_TENANT_ID);
} else {
registry = this.registry;
}
}
if (registry.resourceExists(wsdlResourcePath)) {
Resource resource = registry.get(wsdlResourcePath);
return new ResourceFile(resource.getContentStream(), resource.getMediaType());
} else if (registry.resourceExists(wsdlResourcePathOld)) {
Resource resource = registry.get(wsdlResourcePathOld);
return new ResourceFile(resource.getContentStream(), resource.getMediaType());
} else {
wsdlResourcePath = apiSourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_WSDL_ARCHIVE_LOCATION + apiId.getProviderName() + APIConstants.WSDL_PROVIDER_SEPERATOR + apiId.getApiName() + apiId.getVersion() + APIConstants.ZIP_FILE_EXTENSION;
wsdlResourcePathOld = APIConstants.API_WSDL_RESOURCE_LOCATION + APIConstants.API_WSDL_ARCHIVE_LOCATION + apiId.getProviderName() + APIConstants.WSDL_PROVIDER_SEPERATOR + apiId.getApiName() + apiId.getVersion() + APIConstants.ZIP_FILE_EXTENSION;
if (registry.resourceExists(wsdlResourcePath)) {
Resource resource = registry.get(wsdlResourcePath);
return new ResourceFile(resource.getContentStream(), resource.getMediaType());
} else if (registry.resourceExists(wsdlResourcePathOld)) {
Resource resource = registry.get(wsdlResourcePathOld);
return new ResourceFile(resource.getContentStream(), resource.getMediaType());
} else {
throw new APIManagementException("No WSDL found for the API: " + apiId, ExceptionCodes.from(ExceptionCodes.NO_WSDL_AVAILABLE_FOR_API, apiId.getApiName(), apiId.getVersion()));
}
}
} catch (RegistryException | org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Error while getting wsdl file from the registry for API: " + apiId.toString();
throw new APIManagementException(msg, e);
} finally {
if (isTenantFlowStarted) {
endTenantFlow();
}
}
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getGraphqlSchemaDefinition.
/**
* Returns the graphQL content in registry specified by the wsdl name
*
* @param apiId Api Identifier
* @return graphQL content matching name if exist else null
*/
@Override
public String getGraphqlSchemaDefinition(APIIdentifier apiId) throws APIManagementException {
String apiTenantDomain = getTenantDomain(apiId);
String schema;
try {
Registry registryType;
// Tenant store anonymous mode if current tenant and the required tenant is not matching
if (this.tenantDomain == null || isTenantDomainNotMatching(apiTenantDomain)) {
int tenantId = getTenantManager().getTenantId(apiTenantDomain);
registryType = getRegistryService().getGovernanceUserRegistry(CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME, tenantId);
} else {
registryType = registry;
}
schema = schemaDef.getGraphqlSchemaDefinition(apiId, registryType);
} catch (org.wso2.carbon.user.api.UserStoreException | RegistryException e) {
String msg = "Failed to get graphql schema definition of Graphql API : " + apiId;
throw new APIManagementException(msg, e);
}
return schema;
}
Aggregations