Search in sources :

Example 1 with PropertiesFactoryBean

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;
}
Also used : Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) FactoryBean(org.springframework.beans.factory.FactoryBean) SimpleUrlValidatorFactoryBean(org.apereo.cas.web.SimpleUrlValidatorFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with PropertiesFactoryBean

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;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 3 with PropertiesFactoryBean

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;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 4 with PropertiesFactoryBean

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());
        }
    }
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) DirectMessage(org.springframework.social.twitter.api.DirectMessage) Message(org.springframework.messaging.Message) DirectMessage(org.springframework.social.twitter.api.DirectMessage) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with PropertiesFactoryBean

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);
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

PropertiesFactoryBean (org.springframework.beans.factory.config.PropertiesFactoryBean)22 ClassPathResource (org.springframework.core.io.ClassPathResource)20 Properties (java.util.Properties)12 Bean (org.springframework.context.annotation.Bean)10 ByteArrayInputStream (java.io.ByteArrayInputStream)6 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)6 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)6 InputStreamResource (org.springframework.core.io.InputStreamResource)6 SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)6 Ignore (org.junit.Ignore)5 Test (org.junit.Test)5 TwitterTemplate (org.springframework.social.twitter.api.impl.TwitterTemplate)5 Message (org.springframework.messaging.Message)3 Tweet (org.springframework.social.twitter.api.Tweet)2 ArrayList (java.util.ArrayList)1 SimpleUrlValidatorFactoryBean (org.apereo.cas.web.SimpleUrlValidatorFactoryBean)1 FactoryBean (org.springframework.beans.factory.FactoryBean)1 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)1 Resource (org.springframework.core.io.Resource)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1