use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImplTestCase method testCompositeApisApiIdImplementationPut.
@Test
public void testCompositeApisApiIdImplementationPut() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String apiID = UUID.randomUUID().toString();
CompositeApisApiServiceImpl compositeApisApiService = new CompositeApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
InputStream implmentation = null;
FileInfo fileInfo = new FileInfo();
fileInfo.setFileName("sample.txt");
fileInfo.setContentType(contentType);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiStore).updateCompositeApiImplementation(apiID, implmentation);
Response response = compositeApisApiService.compositeApisApiIdImplementationPut(apiID, implmentation, fileInfo, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateImage.
/**
* @see ApiDAO#updateImage(String, InputStream, String, String)
*/
@Override
public void updateImage(String apiID, InputStream image, String dataType, String updatedBy) throws APIMgtDAOException {
if (image != null) {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
if (!ApiResourceDAO.isResourceExistsForCategory(connection, apiID, ResourceCategory.IMAGE)) {
ApiResourceDAO.addBinaryResource(connection, apiID, UUID.randomUUID().toString(), ResourceCategory.IMAGE, dataType, image, updatedBy);
} else {
ApiResourceDAO.updateBinaryResourceForCategory(connection, apiID, ResourceCategory.IMAGE, image, updatedBy);
}
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "updating Image for API: " + apiID + ", Data Type: " + dataType + ", Updated By: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "updating Image for API: " + apiID + ", Data Type: " + dataType + ", Updated By: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ApiDAOImpl method addOrUpdateWSDLArchive.
@Override
public void addOrUpdateWSDLArchive(String apiID, InputStream inputStream, String updatedBy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
if (!ApiResourceDAO.isResourceExistsForCategory(connection, apiID, ResourceCategory.WSDL_ZIP)) {
if (ApiResourceDAO.isResourceExistsForCategory(connection, apiID, ResourceCategory.WSDL_TEXT)) {
removeWSDL(apiID);
}
ApiResourceDAO.addBinaryResource(connection, apiID, UUID.randomUUID().toString(), ResourceCategory.WSDL_ZIP, MediaType.APPLICATION_OCTET_STREAM, inputStream, updatedBy);
} else {
ApiResourceDAO.updateBinaryResourceForCategory(connection, apiID, ResourceCategory.WSDL_ZIP, inputStream, updatedBy);
}
connection.commit();
} catch (SQLException e) {
connection.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding or updating WSDL archive for API(api: " + apiID + ")", e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding or updating WSDL archive for API(api: " + apiID + ")", e);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class APIPublisherImpl method updateAPIWSDLArchive.
@Override
public void updateAPIWSDLArchive(String apiId, InputStream inputStream) throws APIMgtDAOException, APIMgtWSDLException {
WSDLArchiveInfo archiveInfo = null;
InputStream fileInputStream = null;
try {
archiveInfo = extractAndValidateWSDLArchive(inputStream);
if (log.isDebugEnabled()) {
log.debug("Successfully extracted and validated WSDL file. Location: " + archiveInfo.getAbsoluteFilePath());
}
fileInputStream = new FileInputStream(archiveInfo.getAbsoluteFilePath());
getApiDAO().addOrUpdateWSDLArchive(apiId, fileInputStream, getUsername());
if (log.isDebugEnabled()) {
log.debug("Successfully updated the WSDL archive in DB. API uuid: " + apiId);
}
} catch (IOException e) {
throw new APIMgtWSDLException("Unable to process WSDL archive at " + archiveInfo.getAbsoluteFilePath(), e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
} finally {
try {
if (fileInputStream != null) {
fileInputStream.close();
}
if (archiveInfo != null) {
APIFileUtils.deleteDirectory(archiveInfo.getLocation());
}
} catch (APIMgtDAOException | IOException 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.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class APIStoreImpl method updateCompositeApi.
/**
* {@inheritDoc}
*/
@Override
public void updateCompositeApi(CompositeAPI.Builder apiBuilder) throws APIManagementException {
apiBuilder.provider(getUsername());
apiBuilder.updatedBy(getUsername());
CompositeAPI originalAPI = getApiDAO().getCompositeAPI(apiBuilder.getId());
apiBuilder.createdTime(originalAPI.getCreatedTime());
// workflow status is an internal property and shouldn't be allowed to update externally
apiBuilder.workflowStatus(originalAPI.getWorkflowStatus());
APIUtils.verifyValidityOfApiUpdate(apiBuilder, originalAPI);
try {
String updatedSwagger = apiDefinitionFromSwagger20.generateSwaggerFromResources(apiBuilder);
InputStream gatewayConfig = getApiDAO().getCompositeAPIGatewayConfig(apiBuilder.getId());
GatewaySourceGenerator gatewaySourceGenerator = getGatewaySourceGenerator();
APIConfigContext apiConfigContext = new APIConfigContext(apiBuilder.build(), config.getGatewayPackageName());
gatewaySourceGenerator.setApiConfigContext(apiConfigContext);
String updatedGatewayConfig = gatewaySourceGenerator.getGatewayConfigFromSwagger(IOUtils.toString(gatewayConfig, StandardCharsets.UTF_8), updatedSwagger);
CompositeAPI api = apiBuilder.build();
if (originalAPI.getContext() != null && !originalAPI.getContext().equals(apiBuilder.getContext())) {
if (isContextExist(api.getContext())) {
throw new APIManagementException("Context already Exist", ExceptionCodes.API_ALREADY_EXISTS);
}
}
// publishing config to gateway
gateway.addCompositeAPI(api);
getApiDAO().updateApiDefinition(api.getId(), updatedSwagger, api.getUpdatedBy());
getApiDAO().updateCompositeAPIGatewayConfig(api.getId(), new ByteArrayInputStream(updatedGatewayConfig.getBytes(StandardCharsets.UTF_8)), api.getUpdatedBy());
if (log.isDebugEnabled()) {
log.debug("API " + api.getName() + "-" + api.getVersion() + " was updated successfully.");
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while updating the API - " + apiBuilder.getName();
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
} catch (IOException e) {
String errorMsg = "Error occurred while reading gateway configuration the API - " + apiBuilder.getName();
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
}
Aggregations