use of org.wso2.carbon.apimgt.api.model.Wsdl 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.api.model.Wsdl 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.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIMWSDLReader method getWSDL.
/**
* Gets WSDL definition as a byte array
*
* @return converted WSDL definition as byte array
* @throws APIManagementException
*/
@Deprecated
public byte[] getWSDL() throws APIManagementException {
try {
Definition wsdlDefinition = readWSDLFile();
WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
writer.writeWSDL(wsdlDefinition, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (Exception e) {
String msg = "Error occurs when change the address URL of the WSDL";
throw new APIManagementException(msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIMWSDLReader method updateWSDL2.
/**
* Update WSDL 2.0 service definitions saved in registry
*
* @param wsdl byte array of wsdl definition saved in registry
* @param api API object
* @return the OMElemnt of the new WSDL content
* @throws APIManagementException
*/
public OMElement updateWSDL2(byte[] wsdl, API api) throws APIManagementException {
try {
// Generate wsdl document from registry data
DocumentBuilderFactory factory = getSecuredDocumentBuilder();
DocumentBuilder builder = factory.newDocumentBuilder();
org.apache.woden.WSDLFactory wsdlFactory = org.apache.woden.WSDLFactory.newInstance();
org.apache.woden.WSDLReader reader = wsdlFactory.newWSDLReader();
reader.setFeature(org.apache.woden.WSDLReader.FEATURE_VALIDATION, false);
Document dom = builder.parse(new ByteArrayInputStream(wsdl));
Element domElement = dom.getDocumentElement();
WSDLSource wsdlSource = reader.createWSDLSource();
wsdlSource.setSource(domElement);
org.apache.woden.wsdl20.Description wsdlDefinition = reader.readWSDL(wsdlSource);
// Update transports
setServiceDefinitionForWSDL2(wsdlDefinition, api);
org.apache.woden.WSDLWriter writer = org.apache.woden.WSDLFactory.newInstance().newWSDLWriter();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
writer.writeWSDL(wsdlDefinition.toElement(), byteArrayOutputStream);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
return APIUtil.buildOMElement(byteArrayInputStream);
} catch (Exception e) {
String msg = " Error occurs when updating WSDL ";
log.error(msg, e);
throw new APIManagementException(msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIMWSDLReader method getWSDL.
/**
* Gets WSDL definition as a byte array given the WSDL definition
*
* @param wsdlDefinition generated WSDL definition
* @return converted WSDL definition as byte array
* @throws APIManagementException
*/
public byte[] getWSDL(Definition wsdlDefinition) throws APIManagementException {
try {
WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
writer.writeWSDL(wsdlDefinition, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (WSDLException e) {
throw new APIManagementException("Error occurs when change the address URL of the WSDL", e);
}
}
Aggregations