use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class APIStoreImpl method getAPIWSDLArchive.
@Override
public WSDLArchiveInfo getAPIWSDLArchive(String apiId, String labelName) throws APIMgtDAOException, APIMgtWSDLException, APINotFoundException, LabelException {
API api = getApiDAO().getAPI(apiId);
if (api == null) {
throw new APINotFoundException("API with id " + apiId + " not found.", ExceptionCodes.API_NOT_FOUND);
}
// api.getLabels() should not be null and the labels should contain labelName
if ((api.getLabels() == null || !api.getLabels().contains(labelName))) {
throw new LabelException("API with id " + apiId + " does not contain label " + labelName, ExceptionCodes.LABEL_NOT_FOUND_IN_API);
}
try (InputStream wsdlZipInputStream = getApiDAO().getWSDLArchive(apiId)) {
String rootPath = System.getProperty(APIMgtConstants.JAVA_IO_TMPDIR) + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVES_FOLDERNAME + File.separator + UUID.randomUUID().toString();
String archivePath = rootPath + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVE_FILENAME;
String extractedLocation = APIFileUtils.extractUploadedArchive(wsdlZipInputStream, APIMgtConstants.WSDLConstants.EXTRACTED_WSDL_ARCHIVE_FOLDERNAME, archivePath, rootPath);
if (log.isDebugEnabled()) {
log.debug("Successfully extracted WSDL archive in path: " + extractedLocation);
}
Label label = getLabelDAO().getLabelByName(labelName);
WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
String wsdlPath = processor.getUpdatedWSDLPath(api, label);
if (log.isDebugEnabled()) {
log.debug("Successfully updated WSDLs in path [" + extractedLocation + "] with endpoints of label: " + labelName + " and context of API " + api.getContext());
}
String wsdlArchiveProcessedFileName = api.getProvider() + "-" + api.getName() + "-" + api.getVersion() + "-" + labelName + "-wsdl";
APIFileUtils.archiveDirectory(wsdlPath, rootPath, wsdlArchiveProcessedFileName);
if (log.isDebugEnabled()) {
log.debug("Successfully archived WSDL files: " + wsdlPath);
}
WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo(rootPath, wsdlArchiveProcessedFileName + ".zip");
archiveInfo.setWsdlInfo(processor.getWsdlInfo());
return archiveInfo;
} catch (IOException e) {
throw new APIMgtWSDLException(e);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class APIPublisherImpl method updateAPIWSDL.
@Override
public String updateAPIWSDL(String apiId, InputStream inputStream) throws APIMgtDAOException, APIMgtWSDLException {
byte[] wsdlContent;
try {
wsdlContent = IOUtils.toByteArray(inputStream);
WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
if (!processor.canProcess()) {
throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
if (log.isDebugEnabled()) {
log.debug("Successfully validated the content of WSDL. API uuid: " + apiId);
}
getApiDAO().addOrUpdateWSDL(apiId, wsdlContent, getUsername());
if (log.isDebugEnabled()) {
log.debug("Successfully added WSDL to the DB. API uuid: " + apiId);
}
return new String(wsdlContent, APIMgtConstants.ENCODING_UTF_8);
} catch (IOException e) {
throw new APIMgtWSDLException("Error while updating WSDL of API " + apiId, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class APIStoreImpl method addCompositeApiFromDefinition.
/**
* {@inheritDoc}
*/
@Override
public String addCompositeApiFromDefinition(InputStream apiDefinition) throws APIManagementException {
try {
String apiDefinitionString = IOUtils.toString(apiDefinition);
CompositeAPI.Builder apiBuilder = apiDefinitionFromSwagger20.generateCompositeApiFromSwaggerResource(getUsername(), apiDefinitionString);
apiBuilder.apiDefinition(apiDefinitionString);
addCompositeApi(apiBuilder);
return apiBuilder.getId();
} catch (IOException e) {
throw new APIManagementException("Couldn't Generate ApiDefinition from file", ExceptionCodes.API_DEFINITION_MALFORMED);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testSingleWSDLForAPI.
@Test
public void testSingleWSDLForAPI() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
// there can't be any WSDLs added at first
boolean isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
boolean isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
// add a WSDL
byte[] wsdlContentBytes = SampleTestObjectCreator.createDefaultWSDL11Content();
apiDAO.addOrUpdateWSDL(api.getId(), wsdlContentBytes, ADMIN);
// retrieves and check whether they are same
String receivedFromDB = apiDAO.getWSDL(api.getId());
Assert.assertEquals(new String(wsdlContentBytes), receivedFromDB);
// now there should be a single WSDL for API exists but no WSDL archives
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertTrue(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
// update the WSDL file
wsdlContentBytes = SampleTestObjectCreator.createAlternativeWSDL11Content();
apiDAO.addOrUpdateWSDL(api.getId(), wsdlContentBytes, ADMIN);
// retrieves and check whether updated successfully
receivedFromDB = apiDAO.getWSDL(api.getId());
Assert.assertEquals(new String(wsdlContentBytes), receivedFromDB);
// update with a WSDL archive
InputStream wsdl11ArchiveInputStream = SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream();
byte[] wsdlArchiveBytesDefault = IOUtils.toByteArray(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
apiDAO.addOrUpdateWSDLArchive(api.getId(), wsdl11ArchiveInputStream, ADMIN);
// retrieves and check whether successfully updated
InputStream wsdlArchiveInputStreamFromDB = apiDAO.getWSDLArchive(api.getId());
byte[] streamFromDBBytes = IOUtils.toByteArray(wsdlArchiveInputStreamFromDB);
Assert.assertEquals(wsdlArchiveBytesDefault.length, streamFromDBBytes.length);
// removes and validate
apiDAO.removeWSDLArchiveOfAPI(api.getId());
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetImage.
@Test(description = "Get image from API")
public void testGetImage() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
testAddGetEndpoint();
API api = SampleTestObjectCreator.createDefaultAPI().build();
apiDAO.addAPI(api);
apiDAO.updateImage(api.getId(), SampleTestObjectCreator.createDefaultThumbnailImage(), "image/jpg", ADMIN);
InputStream image = apiDAO.getImage(api.getId());
Assert.assertNotNull(image);
}
Aggregations