Search in sources :

Example 21 with WSDLProcessor

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

the class APIMWSDLReader method validateWSDLFile.

/**
 * Extract the WSDL file and validates it
 *
 * @param inputStream file input stream
 * @return Validation information
 * @throws APIManagementException Error occurred during validation
 */
public static WSDLValidationResponse validateWSDLFile(InputStream inputStream) throws APIManagementException {
    WSDLValidationResponse wsdlValidationResponse;
    String path = System.getProperty(APIConstants.JAVA_IO_TMPDIR) + File.separator + APIConstants.WSDL_ARCHIVES_TEMP_FOLDER + File.separator + UUID.randomUUID().toString();
    String wsdlFilePath = path + File.separator + APIConstants.WSDL_FILE + APIConstants.WSDL_FILE_EXTENSION;
    // Append an additional '/' if not found before the prefix
    if (!wsdlFilePath.startsWith("/")) {
        wsdlFilePath = "/" + wsdlFilePath;
    }
    APIFileUtil.extractSingleWSDLFile(inputStream, path, wsdlFilePath);
    String finalPath = APIConstants.FILE_URI_PREFIX + wsdlFilePath;
    try {
        WSDLProcessor processor = getWSDLProcessor(finalPath);
        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;
    } catch (APIManagementException e) {
        return handleExceptionDuringValidation(e);
    }
}
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)

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