Search in sources :

Example 11 with WSDLProcessor

use of org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor in project carbon-apimgt by wso2.

the class WSDLProcessFactoryTestcase method testGetWSDLProcessorForContent.

@Test
public void testGetWSDLProcessorForContent() throws Exception {
    byte[] wsdl11Content = SampleTestObjectCreator.createDefaultWSDL11Content();
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdl11Content);
    Assert.assertTrue(processor instanceof WSDL11ProcessorImpl);
    byte[] wsdl20Content = SampleTestObjectCreator.createDefaultWSDL20Content();
    processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdl20Content);
    Assert.assertTrue(processor instanceof WSDL20ProcessorImpl);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) Test(org.testng.annotations.Test)

Example 12 with WSDLProcessor

use of org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor in project carbon-apimgt by wso2.

the class WSDLProcessFactoryTestcase method testGetWSDLProcessorForPath.

@Test
public void testGetWSDLProcessorForPath() throws Exception {
    String extractedLocation = SampleTestObjectCreator.createDefaultWSDL11Archive();
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
    Assert.assertTrue(processor instanceof WSDL11ProcessorImpl);
    extractedLocation = SampleTestObjectCreator.createDefaultWSDL20Archive();
    processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
    Assert.assertTrue(processor instanceof WSDL20ProcessorImpl);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) Test(org.testng.annotations.Test)

Example 13 with WSDLProcessor

use of org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor in project carbon-apimgt by wso2.

the class APIPublisherImpl method addAPIFromWSDLURL.

@Override
public String addAPIFromWSDLURL(API.APIBuilder apiBuilder, String wsdlUrl, boolean isHttpBinding) throws APIManagementException {
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlUrl);
    if (!processor.canProcess()) {
        throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
    }
    apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(processor.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
    String uuid = addAPI(apiBuilder);
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the API. uuid: " + uuid);
    }
    byte[] wsdlContentBytes = processor.getWSDL();
    getApiDAO().addOrUpdateWSDL(uuid, wsdlContentBytes, getUsername());
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the content of WSDL URL to database. WSDL URL: " + wsdlUrl);
    }
    if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(processor.getWsdlInfo().getVersion())) {
        log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
    }
    return uuid;
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

Example 14 with WSDLProcessor

use of org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor in project carbon-apimgt by wso2.

the class APIStoreImpl method getAPIWSDLArchive.

@Override
public WSDLArchiveInfo getAPIWSDLArchive(String apiId, String labelName) throws APIMgtDAOException, APIMgtWSDLException, APINotFoundException, LabelException {
    API api = getApiDAO().getAPI(apiId);
    if (api == null) {
        throw new APINotFoundException("API with id " + apiId + " not found.", ExceptionCodes.API_NOT_FOUND);
    }
    // api.getLabels() should not be null and the labels should contain labelName
    if ((api.getLabels() == null || !api.getLabels().contains(labelName))) {
        throw new LabelException("API with id " + apiId + " does not contain label " + labelName, ExceptionCodes.LABEL_NOT_FOUND_IN_API);
    }
    try (InputStream wsdlZipInputStream = getApiDAO().getWSDLArchive(apiId)) {
        String rootPath = System.getProperty(APIMgtConstants.JAVA_IO_TMPDIR) + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVES_FOLDERNAME + File.separator + UUID.randomUUID().toString();
        String archivePath = rootPath + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVE_FILENAME;
        String extractedLocation = APIFileUtils.extractUploadedArchive(wsdlZipInputStream, APIMgtConstants.WSDLConstants.EXTRACTED_WSDL_ARCHIVE_FOLDERNAME, archivePath, rootPath);
        if (log.isDebugEnabled()) {
            log.debug("Successfully extracted WSDL archive in path: " + extractedLocation);
        }
        Label label = getLabelDAO().getLabelByName(labelName);
        WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
        String wsdlPath = processor.getUpdatedWSDLPath(api, label);
        if (log.isDebugEnabled()) {
            log.debug("Successfully updated WSDLs in path [" + extractedLocation + "] with endpoints of label: " + labelName + " and context of API " + api.getContext());
        }
        String wsdlArchiveProcessedFileName = api.getProvider() + "-" + api.getName() + "-" + api.getVersion() + "-" + labelName + "-wsdl";
        APIFileUtils.archiveDirectory(wsdlPath, rootPath, wsdlArchiveProcessedFileName);
        if (log.isDebugEnabled()) {
            log.debug("Successfully archived WSDL files: " + wsdlPath);
        }
        WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo(rootPath, wsdlArchiveProcessedFileName + ".zip");
        archiveInfo.setWsdlInfo(processor.getWsdlInfo());
        return archiveInfo;
    } catch (IOException e) {
        throw new APIMgtWSDLException(e);
    }
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Label(org.wso2.carbon.apimgt.core.models.Label) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) IOException(java.io.IOException) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) APINotFoundException(org.wso2.carbon.apimgt.core.exception.APINotFoundException)

Example 15 with WSDLProcessor

use of org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor in project carbon-apimgt by wso2.

the class APIStoreImpl method getAPIWSDL.

@Override
public String getAPIWSDL(String apiId, String labelName) throws APIMgtDAOException, APIMgtWSDLException, APINotFoundException, LabelException {
    API api = getApiDAO().getAPI(apiId);
    if (api == null) {
        throw new APINotFoundException("API with id " + apiId + " not found.", ExceptionCodes.API_NOT_FOUND);
    }
    // api.getLabels() should not be null and the labels should contain labelName
    if ((api.getLabels() == null || !api.getLabels().contains(labelName))) {
        throw new LabelException("API with id " + apiId + " does not contain label " + labelName, ExceptionCodes.LABEL_NOT_FOUND_IN_API);
    }
    String wsdl = getApiDAO().getWSDL(apiId);
    Label label = getLabelDAO().getLabelByName(labelName);
    if (!StringUtils.isEmpty(wsdl)) {
        WSDLProcessor processor;
        try {
            processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdl.getBytes(APIMgtConstants.ENCODING_UTF_8));
            return new String(processor.getUpdatedWSDL(api, label), APIMgtConstants.ENCODING_UTF_8);
        } catch (UnsupportedEncodingException e) {
            throw new APIMgtWSDLException("WSDL content is not in utf-8 encoding", e, ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
        }
    }
    return null;
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) Label(org.wso2.carbon.apimgt.core.models.Label) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) APINotFoundException(org.wso2.carbon.apimgt.core.exception.APINotFoundException)

Aggregations

WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)8 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 WSDLProcessor (org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor)8 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 WSDLValidationResponse (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 WSDLArchiveInfo (org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo)3 WSDL11ProcessorImpl (org.wso2.carbon.apimgt.impl.wsdl.WSDL11ProcessorImpl)3 WSDL20ProcessorImpl (org.wso2.carbon.apimgt.impl.wsdl.WSDL20ProcessorImpl)3 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Test (org.testng.annotations.Test)2 ResourceFile (org.wso2.carbon.apimgt.api.model.ResourceFile)2 APINotFoundException (org.wso2.carbon.apimgt.core.exception.APINotFoundException)2 LabelException (org.wso2.carbon.apimgt.core.exception.LabelException)2 API (org.wso2.carbon.apimgt.core.models.API)2 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)2