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()));
}
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations