Search in sources :

Example 16 with PropertiesFactoryBean

use of org.springframework.beans.factory.config.PropertiesFactoryBean in project spring-integration by spring-projects.

the class SearchReceivingMessageSourceTests method demoReceiveSearchResults.

@SuppressWarnings("unchecked")
@Test
@Ignore
public void demoReceiveSearchResults() 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"));
    SearchReceivingMessageSource tSource = new SearchReceivingMessageSource(template, "foo");
    tSource.setQuery(SEARCH_QUERY);
    tSource.afterPropertiesSet();
    for (int i = 0; i < 50; i++) {
        Message<Tweet> message = (Message<Tweet>) tSource.receive();
        if (message != null) {
            Tweet tweet = message.getPayload();
            logger.info(tweet.getFromUser() + " - " + tweet.getText() + " - " + tweet.getCreatedAt());
        }
    }
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) Message(org.springframework.messaging.Message) Tweet(org.springframework.social.twitter.api.Tweet) 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 17 with PropertiesFactoryBean

use of org.springframework.beans.factory.config.PropertiesFactoryBean in project spring-integration by spring-projects.

the class TimelineReceivingMessageSourceTests method demoReceiveTimeline.

@SuppressWarnings("unchecked")
@Test
@Ignore
public void demoReceiveTimeline() 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"));
    TimelineReceivingMessageSource tSource = new TimelineReceivingMessageSource(template, "foo");
    tSource.afterPropertiesSet();
    for (int i = 0; i < 50; i++) {
        Message<Tweet> message = (Message<Tweet>) tSource.receive();
        if (message != null) {
            Tweet tweet = message.getPayload();
            logger.info(tweet.getFromUser() + " - " + tweet.getText() + " - " + tweet.getCreatedAt());
        }
    }
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) Message(org.springframework.messaging.Message) Tweet(org.springframework.social.twitter.api.Tweet) 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 18 with PropertiesFactoryBean

use of org.springframework.beans.factory.config.PropertiesFactoryBean in project spring-integration by spring-projects.

the class StatusUpdatingMessageHandlerTests method demoSendStatusMessage.

@Test
@Ignore
public void demoSendStatusMessage() 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"));
    Message<?> message1 = new GenericMessage<>("Polishing #springintegration migration to Spring Social. test");
    StatusUpdatingMessageHandler handler = new StatusUpdatingMessageHandler(template);
    handler.afterPropertiesSet();
    handler.handleMessage(message1);
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) GenericMessage(org.springframework.messaging.support.GenericMessage) 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 19 with PropertiesFactoryBean

use of org.springframework.beans.factory.config.PropertiesFactoryBean in project spring-integration by spring-projects.

the class ChainElementsTests method bootStrap.

private ApplicationContext bootStrap(String configProperty) throws Exception {
    PropertiesFactoryBean pfb = new PropertiesFactoryBean();
    pfb.setLocation(new ClassPathResource("org/springframework/integration/xml/config/chain-elements-config.properties"));
    pfb.afterPropertiesSet();
    Properties prop = pfb.getObject();
    StringBuffer buffer = new StringBuffer();
    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 20 with PropertiesFactoryBean

use of org.springframework.beans.factory.config.PropertiesFactoryBean in project springBoot-learn-demo by nbfujx.

the class SchedulerConfig method quartzProperties.

@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    // 在quartz.properties中的属性被读取并注入后再初始化对象
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
Also used : PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) ClassPathResource(org.springframework.core.io.ClassPathResource) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Bean(org.springframework.context.annotation.Bean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean)

Aggregations

PropertiesFactoryBean (org.springframework.beans.factory.config.PropertiesFactoryBean)23 ClassPathResource (org.springframework.core.io.ClassPathResource)21 Properties (java.util.Properties)12 Bean (org.springframework.context.annotation.Bean)11 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 JndiObjectFactoryBean (org.springframework.jndi.JndiObjectFactoryBean)1