Search in sources :

Example 31 with APIMgtWSDLException

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

the class WSDLProcessFactory method getWSDLProcessor.

/**
 * Returns the appropriate WSDL 1.1 or 2.0 processor based on the content {@code wsdlContent}.
 *
 * @param wsdlContent Content of the WSDL
 * @return WSDL 1.1 or 2.0 processor for the provided content
 * @throws APIMgtWSDLException If an error occurs while determining the processor
 */
public WSDLProcessor getWSDLProcessor(byte[] wsdlContent) throws APIMgtWSDLException {
    for (String clazz : getWSDLProcessorClasses()) {
        WSDLProcessor processor;
        try {
            processor = (WSDLProcessor) Class.forName(clazz).newInstance();
            boolean canProcess = processor.init(wsdlContent);
            if (canProcess) {
                return processor;
            }
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new APIMgtWSDLException("Error while instantiating " + clazz, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
        }
    }
    // no processors found if this line reaches
    throw new APIMgtWSDLException("No WSDL processor found to process WSDL content", ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

Example 32 with APIMgtWSDLException

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

the class WSDLProcessFactory method getWSDLProcessorForPath.

/**
 * Returns the appropriate WSDL 1.1 or 2.0 processor based on the file path {@code wsdlPath}.
 *
 * @param wsdlPath File path containing WSDL files and dependant files
 * @return WSDL 1.1 or 2.0 processor for the provided content
 * @throws APIMgtWSDLException If an error occurs while determining the processor
 */
public WSDLProcessor getWSDLProcessorForPath(String wsdlPath) throws APIMgtWSDLException {
    for (String clazz : getWSDLProcessorClasses()) {
        WSDLProcessor processor;
        try {
            processor = (WSDLProcessor) Class.forName(clazz).newInstance();
            boolean canProcess = processor.initPath(wsdlPath);
            if (canProcess) {
                return processor;
            }
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new APIMgtWSDLException("Error while instantiating " + clazz, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
        }
    }
    // no processors found if this line reaches
    throw new APIMgtWSDLException("No WSDL processor found to process WSDL content", ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

Example 33 with APIMgtWSDLException

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

the class WSDL11ProcessorImpl method getWSDLByteArrayOutputStream.

/**
 * Retrieves a {@link ByteArrayOutputStream} for provided {@link Definition}.
 *
 * @param definition WSDL Definition
 * @return A {@link ByteArrayOutputStream} for provided {@link Definition}
 * @throws APIMgtWSDLException If an error occurs while creating {@link ByteArrayOutputStream}
 */
private ByteArrayOutputStream getWSDLByteArrayOutputStream(Definition definition) throws APIMgtWSDLException {
    WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        writer.writeWSDL(definition, byteArrayOutputStream);
    } catch (WSDLException e) {
        throw new APIMgtWSDLException("Error while stringifying WSDL definition", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    }
    return byteArrayOutputStream;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) WSDLWriter(javax.wsdl.xml.WSDLWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 34 with APIMgtWSDLException

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

the class WSDL11ProcessorImpl method getWsdlInfo.

@Override
public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
    WSDLInfo wsdlInfo = new WSDLInfo();
    Map<String, String> endpointsMap = getEndpoints();
    Set<WSDLOperation> operations = getHttpBindingOperations();
    wsdlInfo.setEndpoints(endpointsMap);
    wsdlInfo.setVersion(APIMgtConstants.WSDLConstants.WSDL_VERSION_11);
    if (!operations.isEmpty()) {
        wsdlInfo.setHasHttpBindingOperations(true);
        wsdlInfo.setHttpBindingOperations(operations);
    } else {
        wsdlInfo.setHasHttpBindingOperations(false);
    }
    wsdlInfo.setHasSoapBindingOperations(hasSoapBindingOperations());
    return wsdlInfo;
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.core.models.WSDLInfo) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation)

Example 35 with APIMgtWSDLException

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

the class WSDL11ProcessorImpl method getUpdatedWSDLPath.

/**
 * Updates the endpoints of all the WSDL files in the path based on the provided API (context) and Label (host).
 *
 * @param api   Provided API object
 * @param label Provided label object
 * @return Updated WSDL file path
 * @throws APIMgtWSDLException Error while updating WSDL files
 */
@Override
public String getUpdatedWSDLPath(API api, Label label) throws APIMgtWSDLException {
    if (label != null) {
        for (Map.Entry<String, Definition> entry : pathToDefinitionMap.entrySet()) {
            Definition definition = entry.getValue();
            if (log.isDebugEnabled()) {
                log.debug("Updating endpoints of WSDL: " + entry.getKey());
            }
            updateEndpoints(label.getAccessUrls(), api, definition);
            if (log.isDebugEnabled()) {
                log.debug("Successfully updated endpoints of WSDL: " + entry.getKey());
            }
            try (FileOutputStream wsdlFileOutputStream = new FileOutputStream(new File(entry.getKey()))) {
                WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
                writer.writeWSDL(definition, wsdlFileOutputStream);
            } catch (IOException | WSDLException e) {
                throw new APIMgtWSDLException("Failed to create WSDL archive for API:" + api.getName() + ":" + api.getVersion() + " for label " + label.getName(), ExceptionCodes.ERROR_WHILE_CREATING_WSDL_ARCHIVE);
            }
        }
    }
    return wsdlArchiveExtractedPath;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) FileOutputStream(java.io.FileOutputStream) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File)

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