Search in sources :

Example 1 with WSDLValidationResponse

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

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

the class APIMWSDLReader method handleExceptionDuringValidation.

/**
 * Handles the provided exception occurred during validation and return a validation response or the exception.
 *
 * @param e exception object
 * @return a validation response if the exception contains an ErrorHandler
 * @throws APIManagementException if the exception doesn't contains an ErrorHandler. Throws the same error as 'e'
 */
private static WSDLValidationResponse handleExceptionDuringValidation(APIManagementException e) throws APIManagementException {
    if (e.getErrorHandler() != null && e.getErrorHandler().getHttpStatusCode() < 500) {
        log.debug("Validation error occurred due to invalid WSDL", e);
        WSDLValidationResponse validationResponse = new WSDLValidationResponse();
        validationResponse.setError(e.getErrorHandler());
        return validationResponse;
    } else {
        throw e;
    }
}
Also used : WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)

Example 3 with WSDLValidationResponse

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

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

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

the class ApisApiServiceImpl method validateWSDLAndReset.

/**
 * Validates the provided WSDL and reset the streams as required
 *
 * @param fileInputStream file input stream
 * @param fileDetail file details
 * @param url WSDL url
 * @throws APIManagementException when error occurred during the operation
 */
private WSDLValidationResponse validateWSDLAndReset(InputStream fileInputStream, Attachment fileDetail, String url) throws APIManagementException {
    Map validationResponseMap = validateWSDL(url, fileInputStream, fileDetail, false);
    WSDLValidationResponse validationResponse = (WSDLValidationResponse) validationResponseMap.get(RestApiConstants.RETURN_MODEL);
    if (validationResponse.getWsdlInfo() == null) {
        // Validation failure
        RestApiUtil.handleBadRequest(validationResponse.getError(), log);
    }
    if (fileInputStream != null) {
        if (fileInputStream.markSupported()) {
            // For uploading the WSDL below will require re-reading from the input stream hence resetting
            try {
                fileInputStream.reset();
            } catch (IOException e) {
                throw new APIManagementException("Error occurred while trying to reset the content stream of the " + "WSDL", e);
            }
        } else {
            log.warn("Marking is not supported in 'fileInputStream' InputStream type: " + fileInputStream.getClass() + ". Skipping validating WSDL to avoid re-reading from the " + "input stream.");
        }
    }
    return validationResponse;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse) IOException(java.io.IOException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

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