Search in sources :

Example 16 with APIMgtWSDLException

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

the class WSDLProcessFactory method getWSDLProcessorForPath.

/**
 * Returns the appropriate WSDL 1.1 or 2.0 processor based on the file path {@code wsdlPath}.
 *
 * @param wsdlPath File path containing WSDL files and dependant files
 * @return WSDL 1.1 or 2.0 processor for the provided content
 * @throws APIMgtWSDLException If an error occurs while determining the processor
 */
public WSDLProcessor getWSDLProcessorForPath(String wsdlPath) throws APIMgtWSDLException {
    for (String clazz : getWSDLProcessorClasses()) {
        WSDLProcessor processor;
        try {
            processor = (WSDLProcessor) Class.forName(clazz).newInstance();
            boolean canProcess = processor.initPath(wsdlPath);
            if (canProcess) {
                return processor;
            }
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new APIMgtWSDLException("Error while instantiating " + clazz, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
        }
    }
    // no processors found if this line reaches
    throw new APIMgtWSDLException("No WSDL processor found to process WSDL content", ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

Example 17 with APIMgtWSDLException

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

the class WSDL11ProcessorImpl method getWSDLByteArrayOutputStream.

/**
 * Retrieves a {@link ByteArrayOutputStream} for provided {@link Definition}.
 *
 * @param definition WSDL Definition
 * @return A {@link ByteArrayOutputStream} for provided {@link Definition}
 * @throws APIMgtWSDLException If an error occurs while creating {@link ByteArrayOutputStream}
 */
private ByteArrayOutputStream getWSDLByteArrayOutputStream(Definition definition) throws APIMgtWSDLException {
    WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        writer.writeWSDL(definition, byteArrayOutputStream);
    } catch (WSDLException e) {
        throw new APIMgtWSDLException("Error while stringifying WSDL definition", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    }
    return byteArrayOutputStream;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) WSDLWriter(javax.wsdl.xml.WSDLWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 18 with APIMgtWSDLException

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

the class WSDL11ProcessorImpl method getWsdlInfo.

@Override
public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
    WSDLInfo wsdlInfo = new WSDLInfo();
    Map<String, String> endpointsMap = getEndpoints();
    Set<WSDLOperation> operations = getHttpBindingOperations();
    wsdlInfo.setEndpoints(endpointsMap);
    wsdlInfo.setVersion(APIMgtConstants.WSDLConstants.WSDL_VERSION_11);
    if (!operations.isEmpty()) {
        wsdlInfo.setHasHttpBindingOperations(true);
        wsdlInfo.setHttpBindingOperations(operations);
    } else {
        wsdlInfo.setHasHttpBindingOperations(false);
    }
    wsdlInfo.setHasSoapBindingOperations(hasSoapBindingOperations());
    return wsdlInfo;
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.core.models.WSDLInfo) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation)

Example 19 with APIMgtWSDLException

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

the class WSDL11ProcessorImpl method getUpdatedWSDLPath.

/**
 * Updates the endpoints of all the WSDL files in the path based on the provided API (context) and Label (host).
 *
 * @param api   Provided API object
 * @param label Provided label object
 * @return Updated WSDL file path
 * @throws APIMgtWSDLException Error while updating WSDL files
 */
@Override
public String getUpdatedWSDLPath(API api, Label label) throws APIMgtWSDLException {
    if (label != null) {
        for (Map.Entry<String, Definition> entry : pathToDefinitionMap.entrySet()) {
            Definition definition = entry.getValue();
            if (log.isDebugEnabled()) {
                log.debug("Updating endpoints of WSDL: " + entry.getKey());
            }
            updateEndpoints(label.getAccessUrls(), api, definition);
            if (log.isDebugEnabled()) {
                log.debug("Successfully updated endpoints of WSDL: " + entry.getKey());
            }
            try (FileOutputStream wsdlFileOutputStream = new FileOutputStream(new File(entry.getKey()))) {
                WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
                writer.writeWSDL(definition, wsdlFileOutputStream);
            } catch (IOException | WSDLException e) {
                throw new APIMgtWSDLException("Failed to create WSDL archive for API:" + api.getName() + ":" + api.getVersion() + " for label " + label.getName(), ExceptionCodes.ERROR_WHILE_CREATING_WSDL_ARCHIVE);
            }
        }
    }
    return wsdlArchiveExtractedPath;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) FileOutputStream(java.io.FileOutputStream) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File)

Example 20 with APIMgtWSDLException

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

the class WSDL11ProcessorImpl method initPath.

/**
 * {@inheritDoc}
 * Will return true if all the provided WSDL files in the initialized path is of 1.1 and can be successfully
 * parsed by WSDL4J.
 */
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
    pathToDefinitionMap = new HashMap<>();
    wsdlArchiveExtractedPath = path;
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
    // switch off the verbose mode
    wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        File folderToImport = new File(path);
        Collection<File> foundWSDLFiles = APIFileUtils.searchFilesWithMatchingExtension(folderToImport, "wsdl");
        if (log.isDebugEnabled()) {
            log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
        }
        for (File file : foundWSDLFiles) {
            String absWSDLPath = file.getAbsolutePath();
            if (log.isDebugEnabled()) {
                log.debug("Processing WSDL file: " + absWSDLPath);
            }
            Definition definition = wsdlReader.readWSDL(null, absWSDLPath);
            pathToDefinitionMap.put(absWSDLPath, definition);
        }
        if (foundWSDLFiles.size() > 0) {
            canProcess = true;
        }
        if (log.isDebugEnabled()) {
            log.debug("Successfully processed all WSDL files in path " + path);
        }
    } catch (WSDLException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        canProcess = false;
    }
    return canProcess;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) File(java.io.File) WSDLReader(javax.wsdl.xml.WSDLReader)

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