Search in sources :

Example 1 with Description

use of org.apache.woden.wsdl20.Description in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method getEndpoints.

/**
 * Get endpoints defined in the provided WSDL description.
 *
 * @param description WSDL 2.0 description
 * @return a Map of endpoint names and their URIs.
 * @throws APIMgtWSDLException if error occurs while reading endpoints
 */
private Map<String, String> getEndpoints(Description description) throws APIMgtWSDLException {
    Service[] services = description.getServices();
    Map<String, String> serviceEndpointMap = new HashMap<>();
    for (Service service : services) {
        Endpoint[] endpoints = service.getEndpoints();
        for (Endpoint endpoint : endpoints) {
            serviceEndpointMap.put(endpoint.getName().toString(), endpoint.getAddress().toString());
        }
    }
    return serviceEndpointMap;
}
Also used : Endpoint(org.apache.woden.wsdl20.Endpoint) HashMap(java.util.HashMap) Service(org.apache.woden.wsdl20.Service)

Example 2 with Description

use of org.apache.woden.wsdl20.Description in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method getEndpoints.

/**
 * Get endpoints defined in WSDL file(s).
 *
 * @return a Map of endpoint names and their URIs.
 * @throws APIMgtWSDLException if error occurs while reading endpoints
 */
private Map<String, String> getEndpoints() throws APIMgtWSDLException {
    if (wsdlDescription != null) {
        return getEndpoints(wsdlDescription);
    } else {
        Map<String, String> allEndpointsOfAllWSDLs = new HashMap<>();
        for (Description description : pathToDescriptionMap.values()) {
            Map<String, String> wsdlEndpoints = getEndpoints(description);
            allEndpointsOfAllWSDLs.putAll(wsdlEndpoints);
        }
        return allEndpointsOfAllWSDLs;
    }
}
Also used : Description(org.apache.woden.wsdl20.Description) HashMap(java.util.HashMap)

Example 3 with Description

use of org.apache.woden.wsdl20.Description in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl 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, Description> entry : pathToDescriptionMap.entrySet()) {
            Description description = entry.getValue();
            if (log.isDebugEnabled()) {
                log.debug("Updating endpoints of WSDL: " + entry.getKey());
            }
            updateEndpoints(label.getAccessUrls(), api, description);
            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(description.toElement(), 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 : Description(org.apache.woden.wsdl20.Description) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) FileOutputStream(java.io.FileOutputStream) WSDLWriter(org.apache.woden.WSDLWriter) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Example 4 with Description

use of org.apache.woden.wsdl20.Description in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method initPath.

/**
 * {@inheritDoc}
 * Will return true if all the provided WSDL files in the initialized path is of 2.0 and can be successfully
 * parsed by woden.
 */
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
    pathToDescriptionMap = new HashMap<>();
    wsdlArchiveExtractedPath = path;
    try {
        WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
        reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
        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) {
            if (log.isDebugEnabled()) {
                log.debug("Processing WSDL file: " + file.getAbsolutePath());
            }
            Description description = reader.readWSDL(file.getAbsolutePath());
            pathToDescriptionMap.put(file.getAbsolutePath(), description);
        }
        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 : Description(org.apache.woden.wsdl20.Description) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) File(java.io.File) WSDLReader(org.apache.woden.WSDLReader)

Aggregations

HashMap (java.util.HashMap)3 Description (org.apache.woden.wsdl20.Description)3 File (java.io.File)2 WSDLException (org.apache.woden.WSDLException)2 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Map (java.util.Map)1 WSDLReader (org.apache.woden.WSDLReader)1 WSDLWriter (org.apache.woden.WSDLWriter)1 Endpoint (org.apache.woden.wsdl20.Endpoint)1 Service (org.apache.woden.wsdl20.Service)1