use of org.springframework.core.io.ResourceLoader in project opennms by OpenNMS.
the class DroolsTicketerServiceLayerTest method setUp.
@Before
public void setUp() throws Exception {
m_eventIpcManager = new MockEventIpcManager();
EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
MockLogAppender.setupLogging();
ResourceLoader loader = new DefaultResourceLoader();
Resource resource = loader.getResource("classpath:/drools-ticketer-rules.drl");
m_easyMockUtils = new EasyMockUtils();
m_configDao = m_easyMockUtils.createMock(DroolsTicketerConfigDao.class);
EasyMock.expect(m_configDao.getRulesFile()).andReturn(resource.getFile()).times(1);
EasyMock.replay(m_configDao);
m_alarmDao = m_easyMockUtils.createMock(AlarmDao.class);
m_ticketerPlugin = m_easyMockUtils.createMock(Plugin.class);
m_droolsTicketerServiceLayer = new DroolsTicketerServiceLayer(m_configDao);
m_droolsTicketerServiceLayer.setAlarmDao(m_alarmDao);
m_droolsTicketerServiceLayer.setTicketerPlugin(m_ticketerPlugin);
EasyMock.reset(m_configDao);
m_alarm = new OnmsAlarm();
m_alarm.setId(1);
m_alarm.setLogMsg("Test Logmsg");
m_alarm.setDescription("Test Description");
m_alarm.setUei("uei.opennms.org/nodes/nodeDown");
m_ticket = new Ticket();
m_ticket.setId("4");
}
use of org.springframework.core.io.ResourceLoader in project grails-core by grails.
the class DefaultGroovyPageLocator method findResource.
protected Resource findResource(List<String> searchPaths) {
Resource foundResource = null;
Resource resource;
for (ResourceLoader loader : resourceLoaders) {
for (String path : searchPaths) {
resource = loader.getResource(path);
if (resource != null && resource.exists()) {
foundResource = resource;
break;
}
}
if (foundResource != null)
break;
}
return foundResource;
}
use of org.springframework.core.io.ResourceLoader in project cas by apereo.
the class CasCoreAuthenticationPolicyConfiguration method authenticationPolicyExecutionPlanConfigurer.
@ConditionalOnMissingBean(name = "authenticationPolicyExecutionPlanConfigurer")
@Bean
public AuthenticationEventExecutionPlanConfigurer authenticationPolicyExecutionPlanConfigurer() {
return plan -> {
final AuthenticationPolicyProperties police = casProperties.getAuthn().getPolicy();
if (police.getReq().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", RequiredHandlerAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(new RequiredHandlerAuthenticationPolicy(police.getReq().getHandlerName(), police.getReq().isTryAll()));
} else if (police.getAll().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", AllAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(new AllAuthenticationPolicy());
} else if (police.getNotPrevented().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", NotPreventedAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(notPreventedAuthenticationPolicy());
} else if (police.getUniquePrincipal().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", UniquePrincipalAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(new UniquePrincipalAuthenticationPolicy(ticketRegistry.getIfAvailable()));
} else if (!police.getGroovy().isEmpty()) {
LOGGER.debug("Activating authentication policy [{}]", GroovyScriptAuthenticationPolicy.class.getSimpleName());
police.getGroovy().forEach(groovy -> plan.registerAuthenticationPolicy(new GroovyScriptAuthenticationPolicy(resourceLoader, groovy.getScript())));
} else if (!police.getRest().isEmpty()) {
LOGGER.debug("Activating authentication policy [{}]", RestfulAuthenticationPolicy.class.getSimpleName());
police.getRest().forEach(r -> plan.registerAuthenticationPolicy(new RestfulAuthenticationPolicy(new RestTemplate(), r.getEndpoint())));
} else if (police.getAny().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", AnyAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(new AnyAuthenticationPolicy(police.getAny().isTryAll()));
}
};
}
use of org.springframework.core.io.ResourceLoader 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.ResourceLoader in project com.revolsys.open by revolsys.
the class ModuleImport method getApplicationContext.
protected GenericApplicationContext getApplicationContext(final BeanDefinitionRegistry parentRegistry) {
if (this.applicationContext == null) {
this.applicationContext = new GenericApplicationContext();
if (parentRegistry instanceof ResourceLoader) {
final ResourceLoader resourceLoader = (ResourceLoader) parentRegistry;
final ClassLoader classLoader = resourceLoader.getClassLoader();
this.applicationContext.setClassLoader(classLoader);
}
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.applicationContext, null);
final DefaultListableBeanFactory beanFactory = this.applicationContext.getDefaultListableBeanFactory();
final BeanFactory parentBeanFactory = (BeanFactory) parentRegistry;
for (final String beanName : parentRegistry.getBeanDefinitionNames()) {
final BeanDefinition beanDefinition = parentRegistry.getBeanDefinition(beanName);
final String beanClassName = beanDefinition.getBeanClassName();
if (beanClassName != null) {
if (beanClassName.equals(AttributeMap.class.getName())) {
registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
this.beanNamesNotToExport.add(beanName);
} else if (beanClassName.equals(MapFactoryBean.class.getName())) {
final PropertyValue targetMapClass = beanDefinition.getPropertyValues().getPropertyValue("targetMapClass");
if (targetMapClass != null) {
final Object mapClass = targetMapClass.getValue();
if (AttributeMap.class.getName().equals(mapClass)) {
registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
this.beanNamesNotToExport.add(beanName);
}
}
}
}
}
beanFactory.addPropertyEditorRegistrar(this.resourceEditorRegistrar);
final AttributesBeanConfigurer attributesConfig = new AttributesBeanConfigurer(this.applicationContext, this.parameters);
this.applicationContext.addBeanFactoryPostProcessor(attributesConfig);
for (final String beanName : this.importBeanNames) {
registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
this.beanNamesNotToExport.add(beanName);
}
for (final Entry<String, String> entry : this.importBeanAliases.entrySet()) {
final String beanName = entry.getKey();
final String aliasName = entry.getValue();
registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, aliasName);
this.beanNamesNotToExport.add(aliasName);
}
final XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(this.applicationContext);
for (final Resource resource : this.resources) {
beanReader.loadBeanDefinitions(resource);
}
this.applicationContext.refresh();
}
return this.applicationContext;
}
Aggregations