Search in sources :

Example 16 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method init.

@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    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, getSecuredParsedDocumentFromContent(wsdlContent));
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } catch (WSDLException | APIManagementException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLReader(javax.wsdl.xml.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Example 17 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method initPath.

@Override
public boolean initPath(String path) throws APIMgtWSDLException {
    setMode(Mode.ARCHIVE);
    pathToDefinitionMap = new HashMap<>();
    wsdlArchiveExtractedPath = path;
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
    try {
        // switch off the verbose mode
        wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
        wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
        File folderToImport = new File(path);
        Collection<File> foundWSDLFiles = APIFileUtil.searchFilesWithMatchingExtension(folderToImport, "wsdl");
        if (log.isDebugEnabled()) {
            log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
        }
        for (File file : foundWSDLFiles) {
            String absWSDLPath = file.getAbsolutePath();
            if (log.isDebugEnabled()) {
                log.debug("Processing WSDL file: " + absWSDLPath);
            }
            Definition definition = wsdlReader.readWSDL(path, getSecuredParsedDocumentFromPath(absWSDLPath));
            pathToDefinitionMap.put(absWSDLPath, definition);
            // set the first found WSDL as wsdlDefinition variable assuming that it is the root WSDL
            if (wsdlDefinition == null) {
                wsdlDefinition = definition;
            }
        }
        if (foundWSDLFiles.isEmpty()) {
            setError(ExceptionCodes.NO_WSDL_FOUND_IN_WSDL_ARCHIVE);
        }
        if (log.isDebugEnabled()) {
            log.debug("Successfully processed all WSDL files in path " + path);
        }
    } catch (WSDLException | APIManagementException e) {
        // This implementation class cannot process the WSDL. Continuing after setting canProcess = false
        log.debug(this.getClass().getName() + " was unable to process the WSDL Files for the path: " + path, e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) File(java.io.File) WSDLReader(javax.wsdl.xml.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Example 18 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method updateEndpointsOfSingleWSDL.

/**
 * Update the endpoint information of the provided WSDL definition when an API and the environment details are
 * provided
 *
 * @param api API
 * @param environmentName name of the gateway environment
 * @param environmentType type of the gateway environment
 * @param wsdlDefinition WSDL 1.1 definition
 * @throws APIMgtWSDLException when error occurred while updating the endpoints
 */
private void updateEndpointsOfSingleWSDL(API api, String environmentName, String environmentType, Definition wsdlDefinition) throws APIMgtWSDLException {
    Map serviceMap = wsdlDefinition.getAllServices();
    URL addressURI;
    String organization = api.getOrganization();
    for (Object entry : serviceMap.entrySet()) {
        Map.Entry svcEntry = (Map.Entry) entry;
        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();
            String endpointTransport;
            for (ExtensibilityElement extensibilityElement : extensibilityElementList) {
                try {
                    addressURI = new URL(getAddressUrl(extensibilityElement));
                    endpointTransport = determineURLTransport(addressURI.getProtocol(), api.getTransports());
                    if (log.isDebugEnabled()) {
                        log.debug("Address URI for the port:" + port.getName() + " is " + addressURI.toString());
                    }
                } catch (MalformedURLException e) {
                    if (log.isDebugEnabled()) {
                        log.debug("Error occurred while getting the wsdl address location [" + getAddressUrl(extensibilityElement) + "]");
                    }
                    endpointTransport = determineURLTransport("https", api.getTransports());
                // This string to URL conversion done in order to identify URL transport eg - http or https.
                // Here if there is a conversion failure , consider "https" as default protocol
                }
                try {
                    setAddressUrl(extensibilityElement, endpointTransport, api.getContext(), environmentName, environmentType, organization);
                } catch (APIManagementException e) {
                    throw new APIMgtWSDLException("Error while setting gateway access URLs in the WSDL", e);
                }
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Port(javax.wsdl.Port) Service(javax.wsdl.Service) URL(java.net.URL) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method initPath.

@Override
public boolean initPath(String path) throws APIMgtWSDLException {
    setMode(Mode.ARCHIVE);
    pathToDescriptionMap = new HashMap<>();
    wsdlArchiveExtractedPath = path;
    WSDLReader reader;
    try {
        reader = getWsdlFactoryInstance().newWSDLReader();
    } catch (WSDLException e) {
        throw new APIMgtWSDLException("Error while initializing the WSDL reader", e);
    }
    reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
    File folderToImport = new File(path);
    Collection<File> foundWSDLFiles = APIFileUtil.searchFilesWithMatchingExtension(folderToImport, "wsdl");
    if (log.isDebugEnabled()) {
        log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
    }
    try {
        for (File file : foundWSDLFiles) {
            if (log.isDebugEnabled()) {
                log.debug("Processing WSDL file: " + file.getAbsolutePath());
            }
            Document document = getSecuredParsedDocumentFromPath(file.getAbsolutePath());
            WSDLSource wsdlSource = getWSDLSourceFromDocument(document, reader);
            Description description = reader.readWSDL(wsdlSource);
            pathToDescriptionMap.put(file.getAbsolutePath(), description);
        }
        if (foundWSDLFiles.isEmpty()) {
            setError(ExceptionCodes.NO_WSDL_FOUND_IN_WSDL_ARCHIVE);
        }
        if (log.isDebugEnabled()) {
            log.debug("Successfully processed all WSDL files in path " + path);
        }
    } catch (WSDLException e) {
        // This implementation class cannot process the WSDL. Continuing after setting canProcess = false
        log.debug(this.getClass().getName() + " was unable to process the WSDL Files for the path: " + path, e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : Description(org.apache.woden.wsdl20.Description) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLSource(org.apache.woden.WSDLSource) Document(org.w3c.dom.Document) File(java.io.File) WSDLReader(org.apache.woden.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Example 20 with APIMgtWSDLException

use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method init.

@Override
public boolean init(URL url) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    WSDLReader reader;
    try {
        reader = WSDLFactory.newInstance().newWSDLReader();
    } catch (WSDLException e) {
        throw new APIMgtWSDLException("Error while initializing the WSDL reader", e);
    }
    reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
    Document document = getSecuredParsedDocumentFromURL(url);
    WSDLSource wsdlSource = getWSDLSourceFromDocument(document, reader);
    try {
        wsdlDescription = reader.readWSDL(wsdlSource);
    } catch (WSDLException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLSource(org.apache.woden.WSDLSource) Document(org.w3c.dom.Document) WSDLReader(org.apache.woden.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Aggregations

APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)24 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)22 IOException (java.io.IOException)15 File (java.io.File)12 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 HashMap (java.util.HashMap)9 Map (java.util.Map)9 WSDLException (javax.wsdl.WSDLException)9 WSDLException (org.apache.woden.WSDLException)9 InputStream (java.io.InputStream)8 WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)8 FileInputStream (java.io.FileInputStream)7 WSDLSOAPOperation (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)7 WSDLReader (javax.wsdl.xml.WSDLReader)5 ErrorItem (org.wso2.carbon.apimgt.api.ErrorItem)5 APIMWSDLReader (org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 ArrayList (java.util.ArrayList)4