Search in sources :

Example 11 with WSDLValidationResponse

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

WSDLValidationResponse (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)10 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)6 IOException (java.io.IOException)3 WSDLProcessor (org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ResourceFile (org.wso2.carbon.apimgt.api.model.ResourceFile)2 WSDLValidationResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 API (org.wso2.carbon.apimgt.api.model.API)1 APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)1 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)1 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)1