use of org.springframework.core.io.ByteArrayResource in project opennms by OpenNMS.
the class OpenNMSITCase method setUp.
@Before
public void setUp() throws Exception {
MockUtil.println("------------ Begin Test " + this + " --------------------------");
MockLogAppender.setupLogging();
if (m_runSupers) {
createMockNetwork();
populateDatabase();
DataSourceFactory.setInstance(m_db);
SnmpPeerFactory.setInstance(new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes())));
if (isStartEventd()) {
m_eventdIpcMgr = new EventIpcManagerDefaultImpl(m_registry);
EventUtilJdbcImpl eventUtil = new EventUtilJdbcImpl();
AbstractEventUtil.setInstance(eventUtil);
JdbcEventdServiceManager eventdServiceManager = new JdbcEventdServiceManager();
eventdServiceManager.setDataSource(m_db);
eventdServiceManager.afterPropertiesSet();
/*
* Make sure we specify a full resource path since "this" is
* the unit test class, which is most likely in another package.
*/
File configFile = ConfigurationTestUtils.getFileForResource(this, "/org/opennms/netmgt/mock/eventconf.xml");
DefaultEventConfDao eventConfDao = new DefaultEventConfDao();
eventConfDao.setConfigResource(new FileSystemResource(configFile));
eventConfDao.afterPropertiesSet();
EventExpander eventExpander = new EventExpander(m_registry);
eventExpander.setEventConfDao(eventConfDao);
eventExpander.setEventUtil(eventUtil);
eventExpander.afterPropertiesSet();
EventIpcBroadcastProcessor eventIpcBroadcastProcessor = new EventIpcBroadcastProcessor(m_registry);
eventIpcBroadcastProcessor.setEventIpcBroadcaster(m_eventdIpcMgr);
eventIpcBroadcastProcessor.afterPropertiesSet();
List<EventProcessor> eventProcessors = new ArrayList<EventProcessor>(3);
eventProcessors.add(eventExpander);
eventProcessors.add(eventIpcBroadcastProcessor);
DefaultEventHandlerImpl eventHandler = new DefaultEventHandlerImpl(m_registry);
eventHandler.setEventProcessors(eventProcessors);
eventHandler.afterPropertiesSet();
m_eventdIpcMgr.setHandlerPoolSize(5);
m_eventdIpcMgr.setEventHandler(eventHandler);
m_eventdIpcMgr.afterPropertiesSet();
m_eventProxy = m_eventdIpcMgr;
EventIpcManagerFactory.setIpcManager(m_eventdIpcMgr);
EventIpcManagerEventHandlerProxy proxy = new EventIpcManagerEventHandlerProxy();
proxy.setEventIpcManager(m_eventdIpcMgr);
proxy.afterPropertiesSet();
List<EventHandler> eventHandlers = new ArrayList<EventHandler>(1);
eventHandlers.add(proxy);
TcpEventReceiver tcpEventReceiver = new TcpEventReceiver();
tcpEventReceiver.setPort(5837);
tcpEventReceiver.setEventHandlers(eventHandlers);
UdpEventReceiver udpEventReceiver = new UdpEventReceiver();
udpEventReceiver.setPort(5837);
tcpEventReceiver.setEventHandlers(eventHandlers);
List<EventReceiver> eventReceivers = new ArrayList<EventReceiver>(2);
eventReceivers.add(tcpEventReceiver);
eventReceivers.add(udpEventReceiver);
m_eventd = new Eventd();
m_eventd.setEventdServiceManager(eventdServiceManager);
m_eventd.setEventReceivers(eventReceivers);
m_eventd.setReceiver(new BroadcastEventProcessor(m_eventdIpcMgr, eventConfDao));
m_eventd.init();
m_eventd.start();
}
}
m_transMgr = new DataSourceTransactionManager(DataSourceFactory.getInstance());
}
use of org.springframework.core.io.ByteArrayResource in project geode by apache.
the class ConvertUtils method convert.
/**
* Converts the 2-dimensional byte array of file data, which includes the name of the file as
* bytes followed by the byte content of the file, for all files being transmitted by Gfsh to the
* GemFire Manager.
* <p/>
*
* @param fileData a 2 dimensional byte array of files names and file content.
* @return an array of Spring Resource objects encapsulating the details (name and content) of
* each file being transmitted by Gfsh to the GemFire Manager.
* @see org.springframework.core.io.ByteArrayResource
* @see org.springframework.core.io.Resource
* @see org.apache.geode.management.internal.cli.CliUtil#bytesToData(byte[][])
* @see org.apache.geode.management.internal.cli.CliUtil#bytesToNames(byte[][])
*/
public static Resource[] convert(final byte[][] fileData) {
if (fileData != null) {
final String[] fileNames = CliUtil.bytesToNames(fileData);
final byte[][] fileContent = CliUtil.bytesToData(fileData);
final List<Resource> resources = new ArrayList<Resource>(fileNames.length);
for (int index = 0; index < fileNames.length; index++) {
final String filename = fileNames[index];
resources.add(new ByteArrayResource(fileContent[index], String.format("Contents of JAR file (%1$s).", filename)) {
@Override
public String getFilename() {
return filename;
}
});
}
return resources.toArray(new Resource[resources.size()]);
}
return new Resource[0];
}
use of org.springframework.core.io.ByteArrayResource in project ignite by apache.
the class GridUriDeploymentSpringParser method parseTasksDocument.
/**
* Converts given input stream expecting XML inside to
* {@link GridUriDeploymentSpringDocument}.
* <p>
* This is a workaround for the {@link InputStreamResource} which does
* not work properly.
*
* @param in Input stream with XML.
* @param log Logger
* @return Grid wrapper for the input stream.
* @throws org.apache.ignite.spi.IgniteSpiException Thrown if incoming input stream could not be
* read or parsed by {@code Spring} {@link XmlBeanFactory}.
* @see XmlBeanFactory
*/
static GridUriDeploymentSpringDocument parseTasksDocument(InputStream in, IgniteLogger log) throws IgniteSpiException {
assert in != null;
// Note: use ByteArrayResource instead of InputStreamResource because InputStreamResource doesn't work.
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
U.copy(in, out);
XmlBeanFactory factory = new XmlBeanFactory(new ByteArrayResource(out.toByteArray()));
return new GridUriDeploymentSpringDocument(factory);
} catch (BeansException | IOException e) {
throw new IgniteSpiException("Failed to parse spring XML file.", e);
} finally {
U.close(out, log);
}
}
use of org.springframework.core.io.ByteArrayResource in project ignite by apache.
the class IgniteSpringHelperImpl method userVersion.
/** {@inheritDoc} */
@Override
public String userVersion(ClassLoader ldr, IgniteLogger log) {
assert ldr != null;
assert log != null;
// For system class loader return cached version.
if (ldr == U.gridClassLoader() && SYS_LDR_VER.get() != null)
return SYS_LDR_VER.get();
String usrVer = U.DFLT_USER_VERSION;
InputStream in = ldr.getResourceAsStream(IGNITE_XML_PATH);
if (in != null) {
// Note: use ByteArrayResource instead of InputStreamResource because
// InputStreamResource doesn't work.
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
U.copy(in, out);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(new ByteArrayResource(out.toByteArray()));
usrVer = (String) factory.getBean("userVersion");
usrVer = usrVer == null ? U.DFLT_USER_VERSION : usrVer.trim();
} catch (NoSuchBeanDefinitionException ignored) {
if (log.isInfoEnabled())
log.info("User version is not explicitly defined (will use default version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']');
usrVer = U.DFLT_USER_VERSION;
} catch (BeansException e) {
U.error(log, "Failed to parse Spring XML file (will use default user version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']', e);
usrVer = U.DFLT_USER_VERSION;
} catch (IOException e) {
U.error(log, "Failed to read Spring XML file (will use default user version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']', e);
usrVer = U.DFLT_USER_VERSION;
} finally {
U.close(out, log);
}
}
// For system class loader return cached version.
if (ldr == U.gridClassLoader())
SYS_LDR_VER.compareAndSet(null, usrVer);
return usrVer;
}
Aggregations