Search in sources :

Example 61 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class APIMWSDLReader method setServiceDefinition.

/**
 * Clear the actual service Endpoint and use Gateway Endpoint instead of the
 * actual Endpoint.
 *
 * @param definition
 *            - {@link Definition} - WSDL4j wsdl definition
 * @throws APIManagementException
 */
private void setServiceDefinition(Definition definition, API api) throws APIManagementException {
    Map serviceMap = definition.getAllServices();
    Iterator serviceItr = serviceMap.entrySet().iterator();
    URL addressURI;
    try {
        while (serviceItr.hasNext()) {
            Map.Entry svcEntry = (Map.Entry) serviceItr.next();
            Service svc = (Service) svcEntry.getValue();
            Map portMap = svc.getPorts();
            for (Object o : portMap.entrySet()) {
                Map.Entry portEntry = (Map.Entry) o;
                Port port = (Port) portEntry.getValue();
                List<ExtensibilityElement> extensibilityElementList = port.getExtensibilityElements();
                for (ExtensibilityElement extensibilityElement : extensibilityElementList) {
                    addressURI = new URL(getAddressUrl(extensibilityElement));
                    String endpointTransport = determineURLTransport(addressURI.getProtocol(), api.getTransports());
                    setAddressUrl(extensibilityElement, endpointTransport, api);
                }
            }
        }
    } catch (Exception e) {
        String errorMsg = "Error occurred while getting the wsdl address location";
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e);
    }
}
Also used : Port(javax.wsdl.Port) Service(javax.wsdl.Service) URL(java.net.URL) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) 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) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Iterator(java.util.Iterator) Map(java.util.Map)

Example 62 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class APIMWSDLReader method isWSDL2BaseURI.

/**
 * Given a URL, this method checks if the underlying document is a WSDL2
 *
 * @return true if the underlying document is a WSDL2
 * @throws APIManagementException if error occurred while checking whether baseURI is WSDL2.0
 */
@Deprecated
public boolean isWSDL2BaseURI() throws APIManagementException {
    URL wsdl;
    boolean isWsdl2 = false;
    BufferedReader in = null;
    try {
        wsdl = new URL(baseURI);
        in = new BufferedReader(new InputStreamReader(wsdl.openStream(), Charset.defaultCharset()));
        String inputLine;
        StringBuilder urlContent = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
            urlContent.append(inputLine);
            isWsdl2 = urlContent.indexOf(WSDL20_NAMESPACE) > 0;
        }
    } catch (MalformedURLException e) {
        throw new APIManagementException("Malformed URL encountered", e);
    } catch (IOException e) {
        throw new APIManagementException("Error Reading Input from Stream from " + baseURI, e);
    } finally {
        IOUtils.closeQuietly(in);
    }
    try {
        if (isWsdl2) {
            readAndValidateWSDL20();
        }
    } catch (org.apache.woden.WSDLException e) {
        throw new APIManagementException("Error while reading WSDL Document from " + baseURI, e);
    }
    return isWsdl2;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStreamReader(java.io.InputStreamReader) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URL(java.net.URL)

Example 63 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class APIMWSDLReader method getSecuredParsedDocumentFromContent.

/**
 * Returns an "XXE safe" built DOM XML object by reading the content from the byte array.
 *
 * @param content xml content
 * @return an "XXE safe" built DOM XML object by reading the content from the byte array
 * @throws APIManagementException When error occurred while reading from the byte array
 */
@Deprecated
private Document getSecuredParsedDocumentFromContent(byte[] content) throws APIManagementException {
    String errorMsg = "Error while reading WSDL document";
    InputStream inputStream = null;
    try {
        DocumentBuilderFactory factory = getSecuredDocumentBuilder();
        DocumentBuilder builder = factory.newDocumentBuilder();
        inputStream = new ByteArrayInputStream(content);
        return builder.parse(inputStream);
    } catch (ParserConfigurationException e) {
        throw new APIManagementException(errorMsg, e);
    } catch (IOException e) {
        throw new APIManagementException(errorMsg, e);
    } catch (SAXException e) {
        throw new APIManagementException(errorMsg, e);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 64 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class APIMWSDLReader method getWSDLSOAPOperationExtractor.

/**
 * Returns a WSDL11SOAPOperationExtractor for the WSDL byte content {@code content}. Only WSDL 1.1 is supported.
 *
 * @param content WSDL byte[] content
 * @return WSDL11SOAPOperationExtractor for the provided URL
 * @throws APIManagementException If an error occurs while determining the processor
 */
public static WSDL11SOAPOperationExtractor getWSDLSOAPOperationExtractor(byte[] content) throws APIManagementException {
    WSDL11SOAPOperationExtractor processor = new WSDL11SOAPOperationExtractor();
    processor.init(content);
    return processor;
}
Also used : WSDL11SOAPOperationExtractor(org.wso2.carbon.apimgt.impl.wsdl.WSDL11SOAPOperationExtractor)

Example 65 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.

the class APIMWSDLReader method getWSDLSOAPOperationExtractorForUrl.

/**
 * Returns a WSDL11SOAPOperationExtractor for the url {@code url}. Only WSDL 1.1 is supported.
 *
 * @param url WSDL url
 * @return WSDL11SOAPOperationExtractor for the provided URL
 * @throws APIManagementException If an error occurs while determining the processor
 */
public static WSDL11SOAPOperationExtractor getWSDLSOAPOperationExtractorForUrl(URL url) throws APIManagementException {
    WSDL11SOAPOperationExtractor processor = new WSDL11SOAPOperationExtractor();
    processor.init(url);
    return processor;
}
Also used : WSDL11SOAPOperationExtractor(org.wso2.carbon.apimgt.impl.wsdl.WSDL11SOAPOperationExtractor)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)64 IOException (java.io.IOException)42 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)33 Test (org.junit.Test)30 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 API (org.wso2.carbon.apimgt.core.models.API)28 File (java.io.File)27 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)23 FileInputStream (java.io.FileInputStream)23 InputStream (java.io.InputStream)22 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)22 WSDLException (javax.wsdl.WSDLException)21 HashMap (java.util.HashMap)20 Resource (org.wso2.carbon.registry.core.Resource)20 MalformedURLException (java.net.MalformedURLException)18 Map (java.util.Map)16 Response (javax.ws.rs.core.Response)16 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)16 SAXException (org.xml.sax.SAXException)16