Search in sources :

Example 6 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class APIPublisherImpl method extractAndValidateWSDLArchive.

@Override
public WSDLArchiveInfo extractAndValidateWSDLArchive(InputStream inputStream) throws APIMgtDAOException, APIMgtWSDLException {
    String path = System.getProperty(APIMgtConstants.JAVA_IO_TMPDIR) + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVES_FOLDERNAME + File.separator + UUID.randomUUID().toString();
    String archivePath = path + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVE_FILENAME;
    String extractedLocation = APIFileUtils.extractUploadedArchive(inputStream, APIMgtConstants.WSDLConstants.EXTRACTED_WSDL_ARCHIVE_FOLDERNAME, archivePath, path);
    if (log.isDebugEnabled()) {
        log.debug("Successfully extracted WSDL archive. Location: " + extractedLocation);
    }
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
    if (!processor.canProcess()) {
        throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
    }
    WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo(path, APIMgtConstants.WSDLConstants.WSDL_ARCHIVE_FILENAME);
    archiveInfo.setWsdlInfo(processor.getWsdlInfo());
    return archiveInfo;
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo)

Example 7 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class APIPublisherImpl method addAPIFromWSDLArchive.

@Override
public String addAPIFromWSDLArchive(API.APIBuilder apiBuilder, InputStream inputStream, boolean isHttpBinding) throws APIManagementException {
    WSDLArchiveInfo archiveInfo = extractAndValidateWSDLArchive(inputStream);
    if (log.isDebugEnabled()) {
        log.debug("Successfully extracted and validated WSDL file. Location: " + archiveInfo.getAbsoluteFilePath());
    }
    apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(archiveInfo.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
    String uuid = addAPI(apiBuilder);
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the API. uuid: " + uuid);
    }
    try (InputStream fileInputStream = new FileInputStream(archiveInfo.getAbsoluteFilePath())) {
        getApiDAO().addOrUpdateWSDLArchive(uuid, fileInputStream, getUsername());
        if (log.isDebugEnabled()) {
            log.debug("Successfully added/updated the WSDL archive. uuid: " + uuid);
        }
        if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(archiveInfo.getWsdlInfo().getVersion())) {
            log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
        }
        return uuid;
    } catch (IOException e) {
        throw new APIMgtWSDLException("Unable to process WSDL archive at " + archiveInfo.getAbsoluteFilePath(), e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    } finally {
        try {
            APIFileUtils.deleteDirectory(archiveInfo.getLocation());
        } catch (APIMgtDAOException e) {
            // This is not a blocker. Give a warning and continue
            log.warn("Error occured while deleting processed WSDL artifacts folder : " + archiveInfo.getLocation());
        }
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 8 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class APIPublisherImpl method addAPIFromWSDLFile.

@Override
public String addAPIFromWSDLFile(API.APIBuilder apiBuilder, InputStream inputStream, boolean isHttpBinding) throws APIManagementException {
    byte[] wsdlContent;
    try {
        wsdlContent = IOUtils.toByteArray(inputStream);
    } catch (IOException e) {
        throw new APIMgtWSDLException("Error while converting input stream to byte array", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    }
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
    apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(processor.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
    if (!processor.canProcess()) {
        throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
    }
    String uuid = addAPI(apiBuilder);
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the API. uuid: " + uuid);
    }
    getApiDAO().addOrUpdateWSDL(uuid, wsdlContent, getUsername());
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the WSDL file to database. API uuid: " + uuid);
    }
    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) IOException(java.io.IOException)

Example 9 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method updateEndpoints.

/**
 * Updates the endpoints of the {@code definition} based on the provided {@code endpointURLs} and {@code api}.
 *
 * @param endpointURLs Endpoint URIs
 * @param api          Provided API object
 * @param definition   WSDL Definition
 * @throws APIMgtWSDLException If an error occurred while updating endpoints
 */
private void updateEndpoints(List<String> endpointURLs, API api, Definition definition) throws APIMgtWSDLException {
    String context = api.getContext().startsWith("/") ? api.getContext() : "/" + api.getContext();
    String selectedUrl;
    try {
        selectedUrl = APIMWSDLUtils.getSelectedEndpoint(endpointURLs) + context;
        if (log.isDebugEnabled()) {
            log.debug("Selected URL for updating endpoints of WSDL:" + selectedUrl);
        }
    } catch (MalformedURLException e) {
        throw new APIMgtWSDLException("Error while selecting endpoints for WSDL", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    }
    if (!StringUtils.isBlank(selectedUrl)) {
        updateEndpoints(selectedUrl, definition);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

Example 10 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method getWsdlInfo.

@Override
public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
    Map<String, String> endpointsMap = getEndpoints();
    WSDLInfo wsdlInfo = new WSDLInfo();
    wsdlInfo.setEndpoints(endpointsMap);
    wsdlInfo.setVersion(APIMgtConstants.WSDLConstants.WSDL_VERSION_20);
    return wsdlInfo;
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.core.models.WSDLInfo)

Aggregations

APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)24 IOException (java.io.IOException)9 WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)8 File (java.io.File)6 InputStream (java.io.InputStream)5 FileInputStream (java.io.FileInputStream)4 WSDLException (javax.wsdl.WSDLException)4 WSDLException (org.apache.woden.WSDLException)4 WSDLArchiveInfo (org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 API (org.wso2.carbon.apimgt.core.models.API)3 FileOutputStream (java.io.FileOutputStream)2 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Definition (javax.wsdl.Definition)2