Search in sources :

Example 1 with Wsdl

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

the class WSDL11ProcessorImpl method getHttpBindingOperations.

/**
 * Retrieves all the operations defined in the provided Binding.
 *
 * @param binding WSDL binding
 * @return a set of {@link WSDLOperation} defined in the provided Binding
 */
private Set<WSDLOperation> getHttpBindingOperations(Binding binding) {
    Set<WSDLOperation> allBindingOperations = new HashSet<>();
    if (binding.getExtensibilityElements() != null && binding.getExtensibilityElements().size() > 0) {
        if (binding.getExtensibilityElements().get(0) instanceof HTTPBinding) {
            HTTPBinding httpBinding = (HTTPBinding) binding.getExtensibilityElements().get(0);
            String verb = httpBinding.getVerb();
            for (Object opObj : binding.getBindingOperations()) {
                if (opObj instanceof BindingOperation) {
                    BindingOperation bindingOperation = (BindingOperation) opObj;
                    WSDLOperation wsdlOperation = getOperation(bindingOperation, verb);
                    if (wsdlOperation != null) {
                        allBindingOperations.add(wsdlOperation);
                    }
                }
            }
        }
    }
    return allBindingOperations;
}
Also used : BindingOperation(javax.wsdl.BindingOperation) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation) HTTPBinding(javax.wsdl.extensions.http.HTTPBinding) HashSet(java.util.HashSet)

Example 2 with Wsdl

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

the class WSDL11ProcessorImpl method getHttpBindingOperations.

/**
 * Retrieves all the operations defined in the provided WSDL definition.
 *
 * @param definition WSDL Definition
 * @return a set of {@link WSDLOperation} defined in the provided WSDL definition
 */
private Set<WSDLOperation> getHttpBindingOperations(Definition definition) {
    Set<WSDLOperation> allOperations = new HashSet<>();
    for (Object bindingObj : definition.getAllBindings().values()) {
        if (bindingObj instanceof Binding) {
            Binding binding = (Binding) bindingObj;
            Set<WSDLOperation> operations = getHttpBindingOperations(binding);
            allOperations.addAll(operations);
        }
    }
    return allOperations;
}
Also used : HTTPBinding(javax.wsdl.extensions.http.HTTPBinding) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation) HashSet(java.util.HashSet)

Example 3 with Wsdl

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

the class WSDL11ProcessorImpl method init.

/**
 * {@inheritDoc}
 * Will return true if the provided WSDL is of 1.1 and can be successfully parsed by WSDL4J.
 */
@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
    // switch off the verbose mode
    wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        wsdlDefinition = wsdlReader.readWSDL(null, new InputSource(new ByteArrayInputStream(wsdlContent)));
        canProcess = true;
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } 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 : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 4 with Wsdl

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

the class APIMWSDLUtils method getWSDL.

/**
 * Retrieves the WSDL located in the provided URI ({@code wsdlUrl}
 *
 * @param wsdlUrl URL of the WSDL file
 * @return Content bytes of the WSDL file
 * @throws APIMgtWSDLException If an error occurred while retrieving the WSDL file
 */
public static byte[] getWSDL(String wsdlUrl) throws APIMgtWSDLException {
    ByteArrayOutputStream outputStream = null;
    InputStream inputStream = null;
    URLConnection conn;
    try {
        URL url = new URL(wsdlUrl);
        conn = url.openConnection();
        conn.setConnectTimeout(CONNECTION_TIMEOUT);
        conn.setReadTimeout(READ_TIMEOUT);
        conn.connect();
        outputStream = new ByteArrayOutputStream();
        inputStream = conn.getInputStream();
        IOUtils.copy(inputStream, outputStream);
        return outputStream.toByteArray();
    } catch (IOException e) {
        throw new APIMgtWSDLException("Error while reading content from " + wsdlUrl, e, ExceptionCodes.INVALID_WSDL_URL_EXCEPTION);
    } finally {
        if (outputStream != null) {
            IOUtils.closeQuietly(outputStream);
        }
        if (inputStream != null) {
            IOUtils.closeQuietly(inputStream);
        }
    }
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URLConnection(java.net.URLConnection) URL(java.net.URL)

Example 5 with Wsdl

use of org.wso2.carbon.apimgt.api.model.Wsdl 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

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