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