Search in sources :

Example 6 with Description

use of org.geotoolkit.wps.xml.v200.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 7 with Description

use of org.geotoolkit.wps.xml.v200.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 8 with Description

use of org.geotoolkit.wps.xml.v200.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)

Example 9 with Description

use of org.geotoolkit.wps.xml.v200.Description in project axis-axis2-java-core by apache.

the class WSDL20ToAxisServiceBuilder method setup.

/**
 * contains all code which gathers non-wsdlService specific information from the
 * wsdl.
 * <p/>
 * After all the setup completes successfully, the setupComplete field is
 * set so that any subsequent calls to setup() will result in a no-op. Note
 * that subclass WSDL20ToAllAxisServicesBuilder will call populateService
 * for each endpoint in the WSDL. Separating the non-wsdlService specific
 * information here allows WSDL20ToAllAxisServicesBuilder to only do this
 * work 1 time per WSDL, instead of for each endpoint on each wsdlService.
 *
 * @throws AxisFault - Thrown in case the necessary resources are not available in the WSDL
 * @throws WSDLException - Thrown in case Woden throws an exception
 */
protected void setup() throws AxisFault, WSDLException {
    if (setupComplete) {
        // already setup, just do nothing and return
        return;
    }
    try {
        if (description == null) {
            Description description;
            DescriptionElement descriptionElement;
            if (wsdlURI != null && !"".equals(wsdlURI)) {
                description = readInTheWSDLFile(wsdlURI);
                descriptionElement = description.toElement();
            } else if (in != null) {
                description = readInTheWSDLFile(in);
                descriptionElement = description.toElement();
            } else {
                throw new AxisFault("No resources found to read the wsdl");
            }
            savedTargetNamespace = descriptionElement.getTargetNamespace().toString();
            namespacemap = descriptionElement.getDeclaredNamespaces();
            this.description = description;
        }
        // Create the namespacemap
        stringBasedNamespaceMap = new NamespaceMap();
        for (int i = 0; i < namespacemap.length; i++) {
            NamespaceDeclaration namespaceDeclaration = namespacemap[i];
            stringBasedNamespaceMap.put(namespaceDeclaration.getPrefix(), namespaceDeclaration.getNamespaceURI().toString());
        }
        DescriptionElement descriptionElement = description.toElement();
        createNamespaceMap(descriptionElement);
        setupComplete = true;
    } catch (AxisFault e) {
        // just rethrow AxisFaults
        throw e;
    } catch (WSDLException e) {
        // Preserve the WSDLException
        throw e;
    } catch (Exception e) {
        throw AxisFault.makeFault(e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Description(org.apache.woden.wsdl20.Description) WSDLException(org.apache.woden.WSDLException) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) DescriptionElement(org.apache.woden.wsdl20.xml.DescriptionElement) Endpoint(org.apache.woden.wsdl20.Endpoint) NamespaceDeclaration(org.apache.woden.types.NamespaceDeclaration) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WSDLException(org.apache.woden.WSDLException)

Example 10 with Description

use of org.geotoolkit.wps.xml.v200.Description in project axis-axis2-java-core by apache.

the class AxisService method createClientSideAxisService.

// #######################################################################################
// APIs to create AxisService
// 
/**
 * To create a AxisService for a given WSDL and the created client is most
 * suitable for client side invocation not for server side invocation. Since
 * all the soap action and wsa action is added to operations
 *
 * @param wsdlURL
 *            location of the WSDL
 * @param wsdlServiceName
 *            name of the service to be invoke , if it is null then the
 *            first one will be selected if there are more than one
 * @param portName
 *            name of the port , if there are more than one , if it is null
 *            then the first one in the iterator will be selected
 * @param options
 *            Service client options, to set the target EPR
 * @return AxisService , the created service will be return
 */
public static AxisService createClientSideAxisService(URL wsdlURL, QName wsdlServiceName, String portName, Options options) throws AxisFault {
    try {
        InputStream in = wsdlURL.openConnection().getInputStream();
        Document doc = XMLUtils.newDocument(in);
        String namespaceURI = doc.getDocumentElement().getNamespaceURI();
        if (Constants.NS_URI_WSDL11.equals(namespaceURI)) {
            WSDLReader reader = WSDLUtil.newWSDLReaderWithPopulatedExtensionRegistry();
            reader.setFeature("javax.wsdl.importDocuments", true);
            Definition wsdlDefinition = reader.readWSDL(getBaseURI(wsdlURL.toString()), doc);
            if (wsdlDefinition != null) {
                wsdlDefinition.setDocumentBaseURI(getDocumentURI(wsdlURL.toString()));
            }
            return createClientSideAxisService(wsdlDefinition, wsdlServiceName, portName, options);
        } else if (Constants.NS_URI_WSDL20.equals(namespaceURI)) {
            org.apache.woden.WSDLReader reader = org.apache.woden.WSDLFactory.newInstance().newWSDLReader();
            WSDLSource source = reader.createWSDLSource();
            source.setSource(doc);
            source.setBaseURI(wsdlURL.toURI());
            Description description = reader.readWSDL(source);
            return createClientSideAxisService(description, wsdlServiceName, portName, options);
        } else {
            throw new AxisFault("No namespace found : Invalid WSDL");
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw AxisFault.makeFault(e);
    } catch (ParserConfigurationException e) {
        log.error(e.getMessage(), e);
        throw AxisFault.makeFault(e);
    } catch (SAXException e) {
        log.error(e.getMessage(), e);
        throw AxisFault.makeFault(e);
    } catch (WSDLException e) {
        log.error(e.getMessage(), e);
        throw AxisFault.makeFault(e);
    } catch (org.apache.woden.WSDLException e) {
        log.error(e.getMessage(), e);
        throw AxisFault.makeFault(e);
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
        throw AxisFault.makeFault(e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Description(org.apache.woden.wsdl20.Description) WSDLException(javax.wsdl.WSDLException) InputStream(java.io.InputStream) Definition(javax.wsdl.Definition) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) WSDLSource(org.apache.woden.WSDLSource) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WSDLReader(javax.wsdl.xml.WSDLReader)

Aggregations

Description (org.apache.woden.wsdl20.Description)10 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 WSDLException (org.apache.woden.WSDLException)5 File (java.io.File)4 URISyntaxException (java.net.URISyntaxException)3 Map (java.util.Map)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 SAXException (org.xml.sax.SAXException)3 FileOutputStream (java.io.FileOutputStream)2 WSDLException (javax.wsdl.WSDLException)2 AxisFault (org.apache.axis2.AxisFault)2 WSDLReader (org.apache.woden.WSDLReader)2 WSDLSource (org.apache.woden.WSDLSource)2 WSDLWriter (org.apache.woden.WSDLWriter)2 ProcessOfferings (org.geotoolkit.wps.xml.v200.ProcessOfferings)2 Document (org.w3c.dom.Document)2 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)2 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)2 InputStream (java.io.InputStream)1