use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetAPIWSDL.
@Test(description = "Retrieve a WSDL of an API")
public void testGetAPIWSDL() throws APIManagementException, IOException {
API api = SampleTestObjectCreator.createDefaultAPI().build();
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
Mockito.when(apiDAO.getWSDL(api.getId())).thenReturn(new String(SampleTestObjectCreator.createDefaultWSDL11Content()));
String updatedWSDL = apiPublisher.getAPIWSDL(api.getId());
Assert.assertNotNull(updatedWSDL);
Assert.assertTrue(updatedWSDL.contains(SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER));
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL11ProcessorImplTestCase method testSingleWSDL.
@Test
public void testSingleWSDL() throws Exception {
WSDL11ProcessorImpl wsdl11Processor = new WSDL11ProcessorImpl();
byte[] wsdlContentBytes = SampleTestObjectCreator.createDefaultWSDL11Content();
wsdl11Processor.init(wsdlContentBytes);
Assert.assertTrue(wsdl11Processor.canProcess());
assertDefaultSingleWSDLContent(wsdl11Processor.getWsdlInfo(), SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER, null);
// validate the content from getWSDL() after initializing the WSDL processor
byte[] originalWsdlContentFromProcessor = wsdl11Processor.getWSDL();
WSDL11ProcessorImpl wsdl11Processor2 = new WSDL11ProcessorImpl();
wsdl11Processor2.init(originalWsdlContentFromProcessor);
Assert.assertTrue(wsdl11Processor2.canProcess());
assertDefaultSingleWSDLContent(wsdl11Processor2.getWsdlInfo(), SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER, null);
// validate the content after updating endpoints using an API and Label
API api = SampleTestObjectCreator.createDefaultAPI().build();
Label label = SampleTestObjectCreator.createLabel(SAMPLE_LABEL_NAME, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
byte[] updatedWSDLWithEndpoint = wsdl11Processor.getUpdatedWSDL(api, label);
// validate the content of wsdl11Processor's WSDL Info content after updating its endpoints
assertDefaultSingleWSDLContent(wsdl11Processor.getWsdlInfo(), UPDATED_ENDPOINT_API_LABEL, SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER);
// validate the content of wsdl11Processor's returned WSDL content after updating its endpoints
WSDL11ProcessorImpl wsdl11Processor3 = new WSDL11ProcessorImpl();
wsdl11Processor3.init(updatedWSDLWithEndpoint);
Assert.assertTrue(wsdl11Processor3.canProcess());
assertDefaultSingleWSDLContent(wsdl11Processor3.getWsdlInfo(), UPDATED_ENDPOINT_API_LABEL, SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER);
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL20ProcessorImplTestCase method testSingleWSDL.
@Test
public void testSingleWSDL() throws Exception {
WSDL20ProcessorImpl wsdl20Processor = new WSDL20ProcessorImpl();
byte[] wsdlContentBytes = SampleTestObjectCreator.createDefaultWSDL20Content();
wsdl20Processor.init(wsdlContentBytes);
Assert.assertTrue(wsdl20Processor.canProcess());
assertDefaultSingleWSDLContent(wsdl20Processor.getWsdlInfo(), ORIGINAL_ENDPOINT_MY_SERVICE, null);
// validate the content from getWSDL() after initializing the WSDL processor
byte[] originalWsdlContentFromProcessor = wsdl20Processor.getWSDL();
WSDL20ProcessorImpl wsdl20Processor2 = new WSDL20ProcessorImpl();
wsdl20Processor2.init(originalWsdlContentFromProcessor);
Assert.assertTrue(wsdl20Processor2.canProcess());
assertDefaultSingleWSDLContent(wsdl20Processor2.getWsdlInfo(), ORIGINAL_ENDPOINT_MY_SERVICE, null);
// validate the content after updating endpoints using an API and Label
API api = SampleTestObjectCreator.createDefaultAPI().build();
Label label = SampleTestObjectCreator.createLabel(SAMPLE_LABEL_NAME, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
byte[] updatedWSDLWithEndpoint = wsdl20Processor.getUpdatedWSDL(api, label);
// validate the content of wsdl20Processor's WSDL Info content after updating its endpoints
assertDefaultSingleWSDLContent(wsdl20Processor.getWsdlInfo(), UPDATED_ENDPOINT_API_LABEL, ORIGINAL_ENDPOINT_MY_SERVICE);
// validate the content of wsdl20Processor's returned WSDL content after updating its endpoints
WSDL20ProcessorImpl wsdl20Processor3 = new WSDL20ProcessorImpl();
wsdl20Processor3.init(updatedWSDLWithEndpoint);
Assert.assertTrue(wsdl20Processor3.canProcess());
assertDefaultSingleWSDLContent(wsdl20Processor3.getWsdlInfo(), UPDATED_ENDPOINT_API_LABEL, ORIGINAL_ENDPOINT_MY_SERVICE);
}
use of org.wso2.carbon.apimgt.api.model.Wsdl 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.Wsdl 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