use of org.springframework.beans.factory.config.PropertiesFactoryBean in project cas by apereo.
the class CasCoreWebConfiguration method casCommonMessages.
/**
* Load property files containing non-i18n fallback values
* that should be exposed to Thyme templates.
* keys in properties files added last will take precedence over the
* internal cas_common_messages.properties.
* Keys in regular messages bundles will override any of the common messages.
*
* @return PropertiesFactoryBean containing all common (non-i18n) messages
*/
@Bean
public PropertiesFactoryBean casCommonMessages() {
final PropertiesFactoryBean properties = new PropertiesFactoryBean();
final List<Resource> resourceList = new ArrayList<>();
final DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
resourceList.add(resourceLoader.getResource("classpath:/cas_common_messages.properties"));
for (final String resourceName : casProperties.getMessageBundle().getCommonNames()) {
final Resource resource = resourceLoader.getResource(resourceName);
// resource existence unknown at this point, let PropertiesFactoryBean determine and log
resourceList.add(resource);
}
properties.setLocations(resourceList.toArray(new Resource[] {}));
properties.setSingleton(true);
properties.setIgnoreResourceNotFound(true);
return properties;
}
use of org.springframework.beans.factory.config.PropertiesFactoryBean in project spring-integration by spring-projects.
the class IdempotentReceiverParserTests method bootStrap.
private ApplicationContext bootStrap(String configProperty) throws Exception {
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
pfb.setLocation(new ClassPathResource("org/springframework/integration/config/xml/idempotent-receiver-configs.properties"));
pfb.afterPropertiesSet();
Properties prop = pfb.getObject();
ByteArrayInputStream stream = new ByteArrayInputStream((prop.getProperty("xmlheaders") + prop.getProperty(configProperty) + prop.getProperty("xmlfooter")).getBytes());
GenericApplicationContext ac = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
reader.loadBeanDefinitions(new InputStreamResource(stream));
ac.refresh();
return ac;
}
use of org.springframework.beans.factory.config.PropertiesFactoryBean in project spring-integration by spring-projects.
the class ChainElementsFailureTests method bootStrap.
private ApplicationContext bootStrap(String configProperty) throws Exception {
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
pfb.setLocation(new ClassPathResource("org/springframework/integration/config/xml/chain-elements-config.properties"));
pfb.afterPropertiesSet();
Properties prop = pfb.getObject();
StringBuilder buffer = new StringBuilder();
buffer.append(prop.getProperty("xmlheaders")).append(prop.getProperty(configProperty)).append(prop.getProperty("xmlfooter"));
ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes());
GenericApplicationContext ac = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
reader.loadBeanDefinitions(new InputStreamResource(stream));
ac.refresh();
return ac;
}
use of org.springframework.beans.factory.config.PropertiesFactoryBean in project spring-integration by spring-projects.
the class DirectMessageReceivingMessageSourceTests method demoReceiveDm.
@SuppressWarnings("unchecked")
@Test
@Ignore
public void demoReceiveDm() throws Exception {
PropertiesFactoryBean pf = new PropertiesFactoryBean();
pf.setLocation(new ClassPathResource("sample.properties"));
pf.afterPropertiesSet();
Properties prop = pf.getObject();
TwitterTemplate template = new TwitterTemplate(prop.getProperty("z_oleg.oauth.consumerKey"), prop.getProperty("z_oleg.oauth.consumerSecret"), prop.getProperty("z_oleg.oauth.accessToken"), prop.getProperty("z_oleg.oauth.accessTokenSecret"));
DirectMessageReceivingMessageSource tSource = new DirectMessageReceivingMessageSource(template, "foo");
tSource.afterPropertiesSet();
for (int i = 0; i < 50; i++) {
Message<DirectMessage> message = (Message<DirectMessage>) tSource.receive();
if (message != null) {
DirectMessage tweet = message.getPayload();
logger.info(tweet.getSender().getScreenName() + " - " + tweet.getText() + " - " + tweet.getCreatedAt());
}
}
}
use of org.springframework.beans.factory.config.PropertiesFactoryBean in project spring-integration by spring-projects.
the class DirectMessageSendingMessageHandlerTests method validateSendDirectMessage.
@Test
@Ignore
public void validateSendDirectMessage() throws Exception {
PropertiesFactoryBean pf = new PropertiesFactoryBean();
pf.setLocation(new ClassPathResource("sample.properties"));
pf.afterPropertiesSet();
Properties prop = pf.getObject();
TwitterTemplate template = new TwitterTemplate(prop.getProperty("spring_eip.oauth.consumerKey"), prop.getProperty("spring_eip.oauth.consumerSecret"), prop.getProperty("spring_eip.oauth.accessToken"), prop.getProperty("spring_eip.oauth.accessTokenSecret"));
Message<?> message1 = MessageBuilder.withPayload("Polsihing SI Twitter migration").setHeader(TwitterHeaders.DM_TARGET_USER_ID, "z_oleg").build();
DirectMessageSendingMessageHandler handler = new DirectMessageSendingMessageHandler(template);
handler.afterPropertiesSet();
handler.handleMessage(message1);
}
Aggregations