use of org.springframework.core.io.DefaultResourceLoader in project spring-security by spring-projects.
the class SecurityMockMvcRequestPostProcessors method x509.
/**
* Finds an X509Cetificate using a resoureName and populates it on the request.
*
* @param resourceName the name of the X509Certificate resource
* @return the
* {@link org.springframework.test.web.servlet.request.RequestPostProcessor} to use.
* @throws IOException
* @throws CertificateException
*/
public static RequestPostProcessor x509(String resourceName) throws IOException, CertificateException {
ResourceLoader loader = new DefaultResourceLoader();
Resource resource = loader.getResource(resourceName);
InputStream inputStream = resource.getInputStream();
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(inputStream);
return x509(certificate);
}
use of org.springframework.core.io.DefaultResourceLoader in project gwt-test-utils by gwt-test-utils.
the class GwtTestContextLoader method createBeanDefinitionReader.
@Override
protected BeanDefinitionReader createBeanDefinitionReader(GenericApplicationContext context) {
XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(context);
beanDefinitionReader.setResourceLoader(new DefaultResourceLoader(GwtFactory.get().getClassLoader()));
return beanDefinitionReader;
}
use of org.springframework.core.io.DefaultResourceLoader in project opennms by OpenNMS.
the class Migrator method getMigrationResourceLoader.
/**
* <p>getMigrationResourceLoader</p>
*
* @param migration a {@link org.opennms.core.schema.Migration} object.
* @return a {@link org.springframework.core.io.ResourceLoader} object.
*/
protected ResourceLoader getMigrationResourceLoader(final Migration migration) {
final File changeLog = new File(migration.getChangeLog());
final List<URL> urls = new ArrayList<URL>();
try {
if (changeLog.exists()) {
urls.add(changeLog.getParentFile().toURI().toURL());
}
} catch (final MalformedURLException e) {
LOG.info("unable to figure out URL for {}", migration.getChangeLog(), e);
}
final ClassLoader cl = new URLClassLoader(urls.toArray(new URL[0]), this.getClass().getClassLoader());
return new DefaultResourceLoader(cl);
}
use of org.springframework.core.io.DefaultResourceLoader in project opennms by OpenNMS.
the class JUnitSnmpAgentExecutionListener method handleSnmpAgent.
private void handleSnmpAgent(final TestContext testContext, final JUnitSnmpAgent config, boolean useMockSnmpStrategy, MockSnmpDataProvider provider) throws IOException, UnknownHostException, InterruptedException {
if (config == null)
return;
String factoryClassName = "unknown";
try {
final SnmpAgentConfigFactory factory = testContext.getApplicationContext().getBean("snmpPeerFactory", SnmpAgentConfigFactory.class);
factoryClassName = factory.getClass().getName();
} catch (final Exception e) {
// ignore
}
if (!factoryClassName.contains("ProxySnmpAgentConfigFactory")) {
LOG.warn("SNMP Peer Factory ({}) is not the ProxySnmpAgentConfigFactory -- did you forget to include applicationContext-proxy-snmp.xml?", factoryClassName);
}
LOG.debug("handleSnmpAgent(testContext, {}, {})", config, useMockSnmpStrategy);
String host = config.host();
if (host == null || "".equals(host)) {
/*
* NOTE: This call produces different results on different platforms so make
* sure your client code is aware of this. If you use the {@link ProxySnmpAgentConfigFactory}
* by including the <code>classpath:/META-INF/opennms/applicationContext-proxy-snmp.xml</code>
* Spring context, you probably won't need to deal with this. It will override the
* SnmpPeerFactory with the correct values.
*
* Linux: 127.0.0.1
* Mac OS: primary external interface
*/
host = InetAddressUtils.getLocalHostAddressAsString();
//host = "127.0.0.1";
}
final ResourceLoader loader = new DefaultResourceLoader();
final Resource resource = loader.getResource(config.resource());
// NOTE: The default value for config.port is specified inside {@link JUnitSnmpAgent}
final InetAddress hostAddress = addr(host);
final int port = config.port();
final SnmpAgentAddress agentAddress = new SnmpAgentAddress(hostAddress, port);
final SnmpAgentConfigProxyMapper mapper = SnmpAgentConfigProxyMapper.getInstance();
if (useMockSnmpStrategy) {
// since it's all virtual, the "mapped" port just points to the real agent address
mapper.addProxy(hostAddress, agentAddress);
} else {
MockSnmpAgent agent = null;
try {
agent = MockSnmpAgent.createAgentAndRun(resource.getURL(), str(InetAddress.getLocalHost()) + "/0");
} catch (Throwable e) {
agent = MockSnmpAgent.createAgentAndRun(resource.getURL(), str(InetAddressUtils.ONE_TWENTY_SEVEN) + "/0");
}
SnmpAgentAddress listenAddress = new SnmpAgentAddress(agent.getInetAddress(), agent.getPort());
mapper.addProxy(hostAddress, listenAddress);
testContext.setAttribute(IPADDRESS_KEY, listenAddress.getAddress());
testContext.setAttribute(PORT_KEY, listenAddress.getPort());
LOG.debug("using MockSnmpAgent on {} for 'real' address {}", listenAddress, agentAddress);
provider.addAgent(agentAddress, agent);
}
provider.setDataForAddress(agentAddress, resource);
}
use of org.springframework.core.io.DefaultResourceLoader in project opennms by OpenNMS.
the class ProvisionerIT method testProvisionerServiceRescanAfterAddingSnmpNms7838.
// fail if we take more than five minutes
@Test(timeout = 300000)
// Start the test with an empty SNMP agent
@JUnitSnmpAgent(host = "198.51.100.201", port = 161, resource = "classpath:/snmpwalk-empty.properties")
public void testProvisionerServiceRescanAfterAddingSnmpNms7838() throws Exception {
importFromResource("classpath:/requisition_then_scan2.xml", Boolean.TRUE.toString());
final List<OnmsNode> nodes = getNodeDao().findAll();
final OnmsNode node = nodes.get(0);
runPendingScans();
m_nodeDao.flush();
assertEquals(1, getInterfaceDao().countAll());
// Make sure that the OnmsIpInterface doesn't have an ifIndex
assertNull(getInterfaceDao().get(node, "198.51.100.201").getIfIndex());
// Make sure that no OnmsSnmpInterface records exist for the node
assertNull(getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 4));
assertNull(getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 5));
LOG.info("******************** ADDING SNMP DATA ********************");
// Add some SNMP data to the agent
m_mockSnmpDataProvider.setDataForAddress(new SnmpAgentAddress(addr("198.51.100.201"), 161), new DefaultResourceLoader().getResource("classpath:/snmpTestData3.properties"));
// Rescan
m_mockEventIpcManager.sendEventToListeners(nodeUpdated(node.getId()));
runPendingScans();
m_nodeDao.flush();
// Make sure that a second interface was added from the SNMP agent data
assertEquals(2, getInterfaceDao().countAll());
// Verify the ifIndex entries
assertEquals(5, getInterfaceDao().get(node, "198.51.100.201").getIfIndex().intValue());
assertEquals(5, getInterfaceDao().get(node, "198.51.100.201").getSnmpInterface().getIfIndex().intValue());
assertEquals(4, getInterfaceDao().get(node, "198.51.100.204").getIfIndex().intValue());
assertEquals(4, getInterfaceDao().get(node, "198.51.100.204").getSnmpInterface().getIfIndex().intValue());
}
Aggregations