Search in sources :

Example 1 with WSDLReaderImpl

use of com.ibm.wsdl.xml.WSDLReaderImpl in project carbon-apimgt by wso2.

the class APIMWSDLReader method updateWSDL.

/**
 * Update WSDL 1.0 service definitions saved in registry
 *
 * @param wsdl 	byte array of registry content
 * @param api 	API object
 * @return 		the OMElemnt of the new WSDL content
 * @throws APIManagementException
 */
public OMElement updateWSDL(byte[] wsdl, API api) throws APIManagementException {
    try {
        // Generate wsdl document from registry data
        WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
        // switch off the verbose mode
        wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
        wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
        if (wsdlReader instanceof WSDLReaderImpl) {
            ((WSDLReaderImpl) wsdlReader).setIgnoreSchemaContent(true);
        }
        Definition wsdlDefinition = wsdlReader.readWSDL(null, getSecuredParsedDocumentFromContent(wsdl));
        // Update transports
        setServiceDefinition(wsdlDefinition, api);
        WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        writer.writeWSDL(wsdlDefinition, byteArrayOutputStream);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        return APIUtil.buildOMElement(byteArrayInputStream);
    } catch (Exception e) {
        String msg = " Error occurs when updating WSDL ";
        log.error(msg);
        throw new APIManagementException(msg, e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ByteArrayInputStream(java.io.ByteArrayInputStream) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WSDLReader(javax.wsdl.xml.WSDLReader) WSDLReaderImpl(com.ibm.wsdl.xml.WSDLReaderImpl) APIUtil.handleException(org.wso2.carbon.apimgt.impl.utils.APIUtil.handleException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) WSDLException(javax.wsdl.WSDLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 2 with WSDLReaderImpl

use of com.ibm.wsdl.xml.WSDLReaderImpl in project carbon-apimgt by wso2.

the class APIMWSDLReader method readWSDLFile.

/**
 * Create the WSDL definition <javax.wsdl.Definition> from the baseURI of
 * the WSDL
 *
 * @return {@link Definition} - WSDL4j definition constructed form the wsdl
 *         original baseuri
 * @throws APIManagementException
 * @throws WSDLException
 */
@Deprecated
private Definition readWSDLFile() throws APIManagementException, WSDLException {
    WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
    // switch off the verbose mode
    reader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    reader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    if (reader instanceof WSDLReaderImpl) {
        ((WSDLReaderImpl) reader).setIgnoreSchemaContent(true);
    }
    if (log.isDebugEnabled()) {
        log.debug("Reading  the WSDL. Base uri is " + baseURI);
    }
    return reader.readWSDL(null, getSecuredParsedDocumentFromURL(baseURI));
}
Also used : WSDLReader(javax.wsdl.xml.WSDLReader) WSDLReaderImpl(com.ibm.wsdl.xml.WSDLReaderImpl)

Example 3 with WSDLReaderImpl

use of com.ibm.wsdl.xml.WSDLReaderImpl in project carbon-apimgt by wso2.

the class APIMWSDLReader method getWSDLDefinitionFromByteContent.

/**
 * Returns WSDL definition from a byte content of the WSDL
 *
 * @param wsdl byte content of the WSDL document
 * @return {@link Definition} - WSDL4j definition constructed form the wsdl
 * @throws APIManagementException
 */
public Definition getWSDLDefinitionFromByteContent(byte[] wsdl, boolean readDependencies) throws APIManagementException {
    try {
        WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
        // switch off the verbose mode
        wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
        wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
        if (!readDependencies) {
            if (wsdlReader instanceof WSDLReaderImpl) {
                ((WSDLReaderImpl) wsdlReader).setIgnoreSchemaContent(true);
            }
        }
        return wsdlReader.readWSDL(null, getSecuredParsedDocumentFromContent(wsdl));
    } catch (Exception e) {
        String msg = " Error occurs when updating WSDL ";
        throw new APIManagementException(msg, e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) WSDLReader(javax.wsdl.xml.WSDLReader) WSDLReaderImpl(com.ibm.wsdl.xml.WSDLReaderImpl) APIUtil.handleException(org.wso2.carbon.apimgt.impl.utils.APIUtil.handleException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) WSDLException(javax.wsdl.WSDLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Aggregations

WSDLReaderImpl (com.ibm.wsdl.xml.WSDLReaderImpl)3 WSDLReader (javax.wsdl.xml.WSDLReader)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 WSDLException (javax.wsdl.WSDLException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIUtil.handleException (org.wso2.carbon.apimgt.impl.utils.APIUtil.handleException)2 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)2 SAXException (org.xml.sax.SAXException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Definition (javax.wsdl.Definition)1 WSDLWriter (javax.wsdl.xml.WSDLWriter)1