use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class APIPublisherImpl method extractAndValidateWSDLArchive.
@Override
public WSDLArchiveInfo extractAndValidateWSDLArchive(InputStream inputStream) throws APIMgtDAOException, APIMgtWSDLException {
String path = System.getProperty(APIMgtConstants.JAVA_IO_TMPDIR) + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVES_FOLDERNAME + File.separator + UUID.randomUUID().toString();
String archivePath = path + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVE_FILENAME;
String extractedLocation = APIFileUtils.extractUploadedArchive(inputStream, APIMgtConstants.WSDLConstants.EXTRACTED_WSDL_ARCHIVE_FOLDERNAME, archivePath, path);
if (log.isDebugEnabled()) {
log.debug("Successfully extracted WSDL archive. Location: " + extractedLocation);
}
WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
if (!processor.canProcess()) {
throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo(path, APIMgtConstants.WSDLConstants.WSDL_ARCHIVE_FILENAME);
archiveInfo.setWsdlInfo(processor.getWsdlInfo());
return archiveInfo;
}
use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class APIPublisherImpl method addAPIFromWSDLArchive.
@Override
public String addAPIFromWSDLArchive(API.APIBuilder apiBuilder, InputStream inputStream, boolean isHttpBinding) throws APIManagementException {
WSDLArchiveInfo archiveInfo = extractAndValidateWSDLArchive(inputStream);
if (log.isDebugEnabled()) {
log.debug("Successfully extracted and validated WSDL file. Location: " + archiveInfo.getAbsoluteFilePath());
}
apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(archiveInfo.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
String uuid = addAPI(apiBuilder);
if (log.isDebugEnabled()) {
log.debug("Successfully added the API. uuid: " + uuid);
}
try (InputStream fileInputStream = new FileInputStream(archiveInfo.getAbsoluteFilePath())) {
getApiDAO().addOrUpdateWSDLArchive(uuid, fileInputStream, getUsername());
if (log.isDebugEnabled()) {
log.debug("Successfully added/updated the WSDL archive. uuid: " + uuid);
}
if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(archiveInfo.getWsdlInfo().getVersion())) {
log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
}
return uuid;
} catch (IOException e) {
throw new APIMgtWSDLException("Unable to process WSDL archive at " + archiveInfo.getAbsoluteFilePath(), e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
} finally {
try {
APIFileUtils.deleteDirectory(archiveInfo.getLocation());
} catch (APIMgtDAOException e) {
// This is not a blocker. Give a warning and continue
log.warn("Error occured while deleting processed WSDL artifacts folder : " + archiveInfo.getLocation());
}
}
}
use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class APIPublisherImpl method addAPIFromWSDLFile.
@Override
public String addAPIFromWSDLFile(API.APIBuilder apiBuilder, InputStream inputStream, boolean isHttpBinding) throws APIManagementException {
byte[] wsdlContent;
try {
wsdlContent = IOUtils.toByteArray(inputStream);
} catch (IOException e) {
throw new APIMgtWSDLException("Error while converting input stream to byte array", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
}
WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(processor.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
if (!processor.canProcess()) {
throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
String uuid = addAPI(apiBuilder);
if (log.isDebugEnabled()) {
log.debug("Successfully added the API. uuid: " + uuid);
}
getApiDAO().addOrUpdateWSDL(uuid, wsdlContent, getUsername());
if (log.isDebugEnabled()) {
log.debug("Successfully added the WSDL file to database. API uuid: " + uuid);
}
if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(processor.getWsdlInfo().getVersion())) {
log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
}
return uuid;
}
use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getSOAPOperation.
/**
* Retrieves WSDL operation given the soap binding operation
*
* @param bindingOperation {@link BindingOperation} object
* @return a set of {@link WSDLOperation} defined in the provided Binding
*/
private WSDLSOAPOperation getSOAPOperation(BindingOperation bindingOperation) throws APIMgtWSDLException {
WSDLSOAPOperation wsdlOperation = null;
for (Object boExtElement : bindingOperation.getExtensibilityElements()) {
if (boExtElement instanceof SOAPOperation) {
SOAPOperation soapOperation = (SOAPOperation) boExtElement;
wsdlOperation = new WSDLSOAPOperation();
wsdlOperation.setName(bindingOperation.getName());
wsdlOperation.setSoapAction(soapOperation.getSoapActionURI());
wsdlOperation.setTargetNamespace(getTargetNamespace(bindingOperation));
wsdlOperation.setStyle(soapOperation.getStyle());
wsdlOperation.setInputParameterModel(getSoapInputParameterModel(bindingOperation));
wsdlOperation.setOutputParameterModel(getSoapOutputParameterModel(bindingOperation));
wsdlOperation.setMessageType(getSoapMessageType(bindingOperation));
} else if (boExtElement instanceof SOAP12Operation) {
SOAP12Operation soapOperation = (SOAP12Operation) boExtElement;
wsdlOperation = new WSDLSOAPOperation();
wsdlOperation.setName(bindingOperation.getName());
wsdlOperation.setSoapAction(soapOperation.getSoapActionURI());
wsdlOperation.setTargetNamespace(getTargetNamespace(bindingOperation));
wsdlOperation.setStyle(soapOperation.getStyle());
wsdlOperation.setInputParameterModel(getSoapInputParameterModel(bindingOperation));
wsdlOperation.setOutputParameterModel(getSoapOutputParameterModel(bindingOperation));
wsdlOperation.setMessageType(getSoapMessageType(bindingOperation));
}
}
return wsdlOperation;
}
use of org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getWsdlInfo.
public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
WSDLInfo wsdlInfo = new WSDLInfo();
if (wsdlDefinition != null) {
Set<WSDLSOAPOperation> soapOperations = getSoapBindingOperations(wsdlDefinition);
wsdlInfo.setVersion(WSDL_VERSION_11);
if (!soapOperations.isEmpty()) {
wsdlInfo.setHasSoapBindingOperations(true);
wsdlInfo.setSoapBindingOperations(soapOperations);
} else {
wsdlInfo.setHasSoapBindingOperations(false);
}
wsdlInfo.setHasSoapBindingOperations(hasSoapBindingOperations());
wsdlInfo.setHasSoap12BindingOperations(hasSoap12BindingOperations());
if (parameterModelMap.size() > 0) {
wsdlInfo.setParameterModelMap(parameterModelMap);
}
} else {
throw new APIMgtWSDLException("WSDL Definition is not initialized.");
}
return wsdlInfo;
}
Aggregations