Search in sources :

Example 6 with WSDLProcessor

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

the class APIMWSDLReader method extractAndValidateWSDLArchive.

/**
 * Extract the WSDL archive zip and validates it
 *
 * @param inputStream zip input stream
 * @return Validation information
 * @throws APIManagementException Error occurred during validation
 */
public static WSDLValidationResponse extractAndValidateWSDLArchive(InputStream inputStream) throws APIManagementException {
    String path = System.getProperty(APIConstants.JAVA_IO_TMPDIR) + File.separator + APIConstants.WSDL_ARCHIVES_TEMP_FOLDER + File.separator + UUID.randomUUID().toString();
    String archivePath = path + File.separator + APIConstants.WSDL_ARCHIVE_ZIP_FILE;
    String extractedLocation = APIFileUtil.extractUploadedArchive(inputStream, APIConstants.API_WSDL_EXTRACTED_DIRECTORY, archivePath, path);
    if (log.isDebugEnabled()) {
        log.debug("Successfully extracted WSDL archive. Location: " + extractedLocation);
    }
    WSDLProcessor processor;
    try {
        processor = getWSDLProcessor(extractedLocation);
    } catch (APIManagementException e) {
        return handleExceptionDuringValidation(e);
    }
    WSDLValidationResponse wsdlValidationResponse = new WSDLValidationResponse();
    if (processor.hasError()) {
        wsdlValidationResponse.setValid(false);
        wsdlValidationResponse.setError(processor.getError());
    } else {
        wsdlValidationResponse.setValid(true);
        WSDLArchiveInfo wsdlArchiveInfo = new WSDLArchiveInfo(path, APIConstants.WSDL_ARCHIVE_ZIP_FILE, processor.getWsdlInfo());
        wsdlValidationResponse.setWsdlArchiveInfo(wsdlArchiveInfo);
        wsdlValidationResponse.setWsdlInfo(processor.getWsdlInfo());
        wsdlValidationResponse.setWsdlProcessor(processor);
    }
    return wsdlValidationResponse;
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse) WSDLArchiveInfo(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLArchiveInfo)

Example 7 with WSDLProcessor

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

the class APIMWSDLReader method getWsdlValidationResponse.

/**
 * Gets WSDL validation response from the WSDL processor
 *
 * @param processor WSDL processor
 * @return WSDL validation response
 * @throws APIMgtWSDLException if error occurred while retrieving WSDL info
 */
public static WSDLValidationResponse getWsdlValidationResponse(WSDLProcessor processor) throws APIMgtWSDLException {
    WSDLValidationResponse wsdlValidationResponse = new WSDLValidationResponse();
    if (processor.hasError()) {
        wsdlValidationResponse.setValid(false);
        wsdlValidationResponse.setError(processor.getError());
    } else {
        wsdlValidationResponse.setValid(true);
        wsdlValidationResponse.setWsdlInfo(processor.getWsdlInfo());
        wsdlValidationResponse.setWsdlProcessor(processor);
    }
    return wsdlValidationResponse;
}
Also used : WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)

Example 8 with WSDLProcessor

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

the class APIConsumerImpl method getWSDL.

@Override
public ResourceFile getWSDL(API api, String environmentName, String environmentType, String organization) throws APIManagementException {
    WSDLValidationResponse validationResponse;
    ResourceFile resourceFile = getWSDL(api.getUuid(), organization);
    if (resourceFile.getContentType().contains(APIConstants.APPLICATION_ZIP)) {
        validationResponse = APIMWSDLReader.extractAndValidateWSDLArchive(resourceFile.getContent());
    } else {
        validationResponse = APIMWSDLReader.validateWSDLFile(resourceFile.getContent());
    }
    if (validationResponse.isValid()) {
        WSDLProcessor wsdlProcessor = validationResponse.getWsdlProcessor();
        wsdlProcessor.updateEndpoints(api, environmentName, environmentType);
        InputStream wsdlDataStream = wsdlProcessor.getWSDL();
        return new ResourceFile(wsdlDataStream, resourceFile.getContentType());
    } else {
        throw new APIManagementException(ExceptionCodes.from(ExceptionCodes.CORRUPTED_STORED_WSDL, api.getId().toString()));
    }
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor) ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse) InputStream(java.io.InputStream)

Example 9 with WSDLProcessor

use of org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor 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 10 with WSDLProcessor

use of org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor 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)

Aggregations

WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)8 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 WSDLProcessor (org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor)8 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 WSDLValidationResponse (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 WSDLArchiveInfo (org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo)3 WSDL11ProcessorImpl (org.wso2.carbon.apimgt.impl.wsdl.WSDL11ProcessorImpl)3 WSDL20ProcessorImpl (org.wso2.carbon.apimgt.impl.wsdl.WSDL20ProcessorImpl)3 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Test (org.testng.annotations.Test)2 ResourceFile (org.wso2.carbon.apimgt.api.model.ResourceFile)2 APINotFoundException (org.wso2.carbon.apimgt.core.exception.APINotFoundException)2 LabelException (org.wso2.carbon.apimgt.core.exception.LabelException)2 API (org.wso2.carbon.apimgt.core.models.API)2 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)2