Search in sources :

Example 31 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl 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);
    }
}
Also used : ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) WSDLPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Example 32 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class GraphQLSchemaDefinition 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
 */
public String getGraphqlSchemaDefinition(APIIdentifier apiId, Registry registry) throws APIManagementException {
    String apiName = apiId.getApiName();
    String apiVersion = apiId.getVersion();
    String apiProviderName = apiId.getProviderName();
    APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(apiId.getUUID());
    String resourcePath;
    if (apiRevision != null && apiRevision.getApiUUID() != null) {
        resourcePath = APIUtil.getRevisionPath(apiRevision.getApiUUID(), apiRevision.getId());
    } else {
        resourcePath = APIUtil.getGraphqlDefinitionFilePath(apiName, apiVersion, apiProviderName);
    }
    String schemaDoc = null;
    String schemaName = apiId.getProviderName() + APIConstants.GRAPHQL_SCHEMA_PROVIDER_SEPERATOR + apiId.getApiName() + apiId.getVersion() + APIConstants.GRAPHQL_SCHEMA_FILE_EXTENSION;
    String schemaResourePath = resourcePath + schemaName;
    try {
        if (registry.resourceExists(schemaResourePath)) {
            Resource schemaResource = registry.get(schemaResourePath);
            schemaDoc = IOUtils.toString(schemaResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
        }
    } catch (RegistryException e) {
        String msg = "Error while getting schema file from the registry " + schemaResourePath;
        log.error(msg, e);
        throw new APIManagementException(msg, e);
    } catch (IOException e) {
        String error = "Error occurred while getting the content of schema: " + schemaName;
        log.error(error);
        throw new APIManagementException(error, e);
    }
    return schemaDoc;
}
Also used : APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.api.Resource) IOException(java.io.IOException) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 33 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class RegistryPersistenceImplTestCase method testGetWSDL.

@Test
public void testGetWSDL() throws Exception {
    Registry registry = Mockito.mock(Registry.class);
    GenericArtifact artifact = PersistenceHelper.getSampleAPIArtifact();
    String apiUUID = artifact.getId();
    Organization org = new Organization(SUPER_TENANT_DOMAIN);
    APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, artifact);
    String apiProviderName = artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
    apiProviderName = RegistryPersistenceUtil.replaceEmailDomain(apiProviderName);
    String apiName = artifact.getAttribute(APIConstants.API_OVERVIEW_NAME);
    String apiVersion = artifact.getAttribute(APIConstants.API_OVERVIEW_VERSION);
    String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiProviderName + RegistryConstants.PATH_SEPARATOR + apiName + RegistryConstants.PATH_SEPARATOR + apiVersion;
    String apiPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiProviderName + RegistryConstants.PATH_SEPARATOR + apiName + RegistryConstants.PATH_SEPARATOR + apiVersion + RegistryConstants.PATH_SEPARATOR + "api";
    PowerMockito.when(GovernanceUtils.getArtifactPath(registry, apiUUID)).thenReturn(apiPath);
    String wsdlResourcePath = artifactPath + RegistryConstants.PATH_SEPARATOR + RegistryPersistenceUtil.createWsdlFileName(apiProviderName, apiName, apiVersion);
    Mockito.when(registry.resourceExists(wsdlResourcePath)).thenReturn(true);
    Resource wsdlResource = Mockito.mock(Resource.class);
    Mockito.when(registry.get(wsdlResourcePath)).thenReturn(wsdlResource);
    apiPersistenceInstance.getWSDL(org, apiUUID);
    Mockito.verify(registry, times(1)).get(wsdlResourcePath);
    // WSDL zip test
    String wsdlResourcePathOld = APIConstants.API_WSDL_RESOURCE_LOCATION + RegistryPersistenceUtil.createWsdlFileName(apiProviderName, apiName, apiVersion);
    Mockito.when(registry.resourceExists(wsdlResourcePath)).thenReturn(false);
    Mockito.when(registry.resourceExists(wsdlResourcePathOld)).thenReturn(false);
    // zip location
    wsdlResourcePath = artifactPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_WSDL_ARCHIVE_LOCATION + apiProviderName + APIConstants.WSDL_PROVIDER_SEPERATOR + apiName + apiVersion + APIConstants.ZIP_FILE_EXTENSION;
    Mockito.when(registry.resourceExists(wsdlResourcePath)).thenReturn(true);
    Mockito.when(registry.get(wsdlResourcePath)).thenReturn(wsdlResource);
    apiPersistenceInstance.getWSDL(org, apiUUID);
    Mockito.verify(registry, times(1)).get(wsdlResourcePath);
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 34 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method getSOAPOperation.

/**
 * Retrieves WSDL operation given the soap binding operation
 *
 * @param bindingOperation {@link BindingOperation} object
 * @return a set of {@link WSDLOperation} defined in the provided Binding
 */
private WSDLSOAPOperation getSOAPOperation(BindingOperation bindingOperation) throws APIMgtWSDLException {
    WSDLSOAPOperation wsdlOperation = null;
    for (Object boExtElement : bindingOperation.getExtensibilityElements()) {
        if (boExtElement instanceof SOAPOperation) {
            SOAPOperation soapOperation = (SOAPOperation) boExtElement;
            wsdlOperation = new WSDLSOAPOperation();
            wsdlOperation.setName(bindingOperation.getName());
            wsdlOperation.setSoapAction(soapOperation.getSoapActionURI());
            wsdlOperation.setTargetNamespace(getTargetNamespace(bindingOperation));
            wsdlOperation.setStyle(soapOperation.getStyle());
            wsdlOperation.setInputParameterModel(getSoapInputParameterModel(bindingOperation));
            wsdlOperation.setOutputParameterModel(getSoapOutputParameterModel(bindingOperation));
            wsdlOperation.setMessageType(getSoapMessageType(bindingOperation));
        } else if (boExtElement instanceof SOAP12Operation) {
            SOAP12Operation soapOperation = (SOAP12Operation) boExtElement;
            wsdlOperation = new WSDLSOAPOperation();
            wsdlOperation.setName(bindingOperation.getName());
            wsdlOperation.setSoapAction(soapOperation.getSoapActionURI());
            wsdlOperation.setTargetNamespace(getTargetNamespace(bindingOperation));
            wsdlOperation.setStyle(soapOperation.getStyle());
            wsdlOperation.setInputParameterModel(getSoapInputParameterModel(bindingOperation));
            wsdlOperation.setOutputParameterModel(getSoapOutputParameterModel(bindingOperation));
            wsdlOperation.setMessageType(getSoapMessageType(bindingOperation));
        }
    }
    return wsdlOperation;
}
Also used : WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)

Example 35 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method getWsdlInfo.

public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
    WSDLInfo wsdlInfo = new WSDLInfo();
    if (wsdlDefinition != null) {
        Set<WSDLSOAPOperation> soapOperations = getSoapBindingOperations(wsdlDefinition);
        wsdlInfo.setVersion(WSDL_VERSION_11);
        if (!soapOperations.isEmpty()) {
            wsdlInfo.setHasSoapBindingOperations(true);
            wsdlInfo.setSoapBindingOperations(soapOperations);
        } else {
            wsdlInfo.setHasSoapBindingOperations(false);
        }
        wsdlInfo.setHasSoapBindingOperations(hasSoapBindingOperations());
        wsdlInfo.setHasSoap12BindingOperations(hasSoap12BindingOperations());
        if (parameterModelMap.size() > 0) {
            wsdlInfo.setParameterModelMap(parameterModelMap);
        }
    } else {
        throw new APIMgtWSDLException("WSDL Definition is not initialized.");
    }
    return wsdlInfo;
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)

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