Search in sources :

Example 26 with Wsdl

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));
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 27 with Wsdl

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);
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) API(org.wso2.carbon.apimgt.core.models.API) Test(org.testng.annotations.Test)

Example 28 with Wsdl

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);
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) API(org.wso2.carbon.apimgt.core.models.API) Test(org.testng.annotations.Test)

Example 29 with Wsdl

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();
        }
    }
}
Also used : ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) UserStoreException(org.wso2.carbon.user.core.UserStoreException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 30 with Wsdl

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)64 IOException (java.io.IOException)42 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)33 Test (org.junit.Test)30 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 API (org.wso2.carbon.apimgt.core.models.API)28 File (java.io.File)27 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)23 FileInputStream (java.io.FileInputStream)23 InputStream (java.io.InputStream)22 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)22 WSDLException (javax.wsdl.WSDLException)21 HashMap (java.util.HashMap)20 Resource (org.wso2.carbon.registry.core.Resource)20 MalformedURLException (java.net.MalformedURLException)18 Map (java.util.Map)16 Response (javax.ws.rs.core.Response)16 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)16 SAXException (org.xml.sax.SAXException)16