Search in sources :

Example 1 with WSDLSource

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

the class WSDL20ProcessorImpl method init.

/**
 * {@inheritDoc}
 * Will return true if the provided WSDL is of 2.0 and can be successfully parsed by woden library.
 */
@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
        reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
        Document dom = builder.parse(new ByteArrayInputStream(wsdlContent));
        Element domElement = dom.getDocumentElement();
        WSDLSource wsdlSource = reader.createWSDLSource();
        wsdlSource.setSource(domElement);
        wsdlDescription = reader.readWSDL(wsdlSource);
        canProcess = true;
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } catch (WSDLException | ParserConfigurationException | SAXException | IOException 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 : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) EndpointElement(org.apache.woden.wsdl20.xml.EndpointElement) Element(org.w3c.dom.Element) WSDLSource(org.apache.woden.WSDLSource) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) WSDLReader(org.apache.woden.WSDLReader) SAXException(org.xml.sax.SAXException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 WSDLException (org.apache.woden.WSDLException)1 WSDLReader (org.apache.woden.WSDLReader)1 WSDLSource (org.apache.woden.WSDLSource)1 EndpointElement (org.apache.woden.wsdl20.xml.EndpointElement)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)1 SAXException (org.xml.sax.SAXException)1