INT-786 refactored Feed MessageSource and related classes

This commit is contained in:
Mark Fisher
2010-10-27 11:37:08 -04:00
parent ffdde36b1b
commit 35f2bc1444
10 changed files with 154 additions and 249 deletions

View File

@@ -1,28 +0,0 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.feed;
/**
* Header keys for {@link FeedReaderMessageSource}.
*
* @author Josh Long
*/
public abstract class FeedConstants {
static public final String FEED_URL = "feedUrl";
}

View File

@@ -16,6 +16,7 @@
package org.springframework.integration.feed;
import java.net.URL;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -24,6 +25,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.context.IntegrationObjectSupport;
import org.springframework.integration.context.metadata.MetadataStore;
@@ -36,6 +38,12 @@ import org.springframework.util.StringUtils;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.fetcher.FetcherEvent;
import com.sun.syndication.fetcher.FetcherListener;
import com.sun.syndication.fetcher.impl.AbstractFeedFetcher;
import com.sun.syndication.fetcher.impl.FeedFetcherCache;
import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
/**
* This implementation of {@link MessageSource} will produce individual
@@ -46,12 +54,16 @@ import com.sun.syndication.feed.synd.SyndFeed;
* @author Oleg Zhurakousky
* @since 2.0
*/
public class FeedEntryReaderMessageSource extends IntegrationObjectSupport implements MessageSource<SyndEntry> {
public class FeedEntryMessageSource extends IntegrationObjectSupport implements MessageSource<SyndEntry> {
private final URL feedUrl;
private final AbstractFeedFetcher fetcher;
private final Queue<SyndFeed> feeds = new ConcurrentLinkedQueue<SyndFeed>();
private final Queue<SyndEntry> entries = new ConcurrentLinkedQueue<SyndEntry>();
private final FeedReaderMessageSource feedReaderMessageSource;
private volatile String metadataKey;
private volatile MetadataStore metadataStore;
@@ -64,10 +76,22 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple
private final Comparator<SyndEntry> syndEntryComparator = new SyndEntryComparator();
private final Object feedMonitor = new Object();
public FeedEntryReaderMessageSource(FeedReaderMessageSource feedReaderMessageSource) {
Assert.notNull(feedReaderMessageSource, "'feedReaderMessageSource' must not be null");
this.feedReaderMessageSource = feedReaderMessageSource;
public FeedEntryMessageSource(URL feedUrl) {
Assert.notNull(feedUrl, "feedUrl must not be null");
this.feedUrl = feedUrl;
if (feedUrl.getProtocol().equals("file")) {
this.fetcher = new FileUrlFeedFetcher();
}
else if (feedUrl.getProtocol().equals("http")) {
FeedFetcherCache fetcherCache = HashMapFeedInfoCache.getInstance();
this.fetcher = new HttpURLFeedFetcher(fetcherCache);
}
else {
throw new IllegalArgumentException("Unsupported URL protocol: " + feedUrl.getProtocol());
}
}
@@ -91,6 +115,7 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple
@Override
protected void onInit() throws Exception {
this.fetcher.addFetcherEventListener(new FeedQueueUpdatingFetcherListener());
if (this.metadataStore == null) {
// first try to look for a 'messageStore' in the context
BeanFactory beanFactory = this.getBeanFactory();
@@ -103,8 +128,7 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple
}
}
Assert.hasText(this.getComponentName(), "FeedEntryReaderMessageSource must have a name");
this.metadataKey = this.getComponentType() + "." + this.getComponentName()
+ "." + this.feedReaderMessageSource.getFeedUrl();
this.metadataKey = this.getComponentType() + "." + this.getComponentName() + "." + this.feedUrl;
String lastTimeValue = this.metadataStore.get(this.metadataKey);
if (StringUtils.hasText(lastTimeValue)) {
this.lastTime = Long.parseLong(lastTimeValue);
@@ -137,7 +161,7 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple
@SuppressWarnings("unchecked")
private void populateEntryList() {
SyndFeed syndFeed = this.feedReaderMessageSource.receiveFeed();
SyndFeed syndFeed = this.getFeed();
if (syndFeed != null) {
List<SyndEntry> retrievedEntries = (List<SyndEntry>) syndFeed.getEntries();
if (!CollectionUtils.isEmpty(retrievedEntries)) {
@@ -151,6 +175,28 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple
}
}
private SyndFeed getFeed() {
SyndFeed feed = null;
try {
synchronized (this.feedMonitor) {
feed = this.fetcher.retrieveFeed(this.feedUrl);
if (logger.isDebugEnabled()) {
logger.debug("retrieved feed at url '" + this.feedUrl + "'");
}
if (feed == null) {
if (logger.isDebugEnabled()) {
logger.debug("no feeds updated, returning null");
}
}
}
}
catch (Exception e) {
throw new MessagingException(
"Failed to retrieve feed at url '" + this.feedUrl + "'", e);
}
return feed;
}
private static class SyndEntryComparator implements Comparator<SyndEntry> {
@@ -159,4 +205,25 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple
}
}
private class FeedQueueUpdatingFetcherListener implements FetcherListener {
/**
* @see com.sun.syndication.fetcher.FetcherListener#fetcherEvent(com.sun.syndication.fetcher.FetcherEvent)
*/
public void fetcherEvent(final FetcherEvent event) {
String eventType = event.getEventType();
if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) {
logger.debug("\tEVENT: Feed Polled. URL = " + event.getUrlString());
}
else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) {
logger.debug("\tEVENT: Feed Retrieved. URL = " + event.getUrlString());
feeds.add(event.getFeed());
}
else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) {
logger.debug("\tEVENT: Feed Unchanged. URL = " + event.getUrlString());
}
}
}
}

View File

@@ -1,137 +0,0 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.feed;
import java.net.URL;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.context.IntegrationObjectSupport;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.util.Assert;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.fetcher.FetcherEvent;
import com.sun.syndication.fetcher.FetcherListener;
import com.sun.syndication.fetcher.impl.AbstractFeedFetcher;
import com.sun.syndication.fetcher.impl.FeedFetcherCache;
import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
/**
* This implementation of {@link MessageSource} will produce a Message whose payload is
* an instance of {@link SyndFeed} for a feed identified with the 'feedUrl' attribute.
*
* @author Josh Long
* @author Mario Gray
* @author Oleg Zhurakousky
* @author Mark Fisher
* @since 2.0
*/
public class FeedReaderMessageSource extends IntegrationObjectSupport implements InitializingBean, MessageSource<SyndFeed> {
private final URL feedUrl;
private final AbstractFeedFetcher fetcher;
private volatile FeedFetcherCache fetcherCache;
private final ConcurrentLinkedQueue<SyndFeed> feeds = new ConcurrentLinkedQueue<SyndFeed>();
private final Object feedMonitor = new Object();
public FeedReaderMessageSource(URL feedUrl) {
this.feedUrl = feedUrl;
if (feedUrl.getProtocol().equals("file")) {
this.fetcher = new FileUrlFeedFetcher();
}
else if (feedUrl.getProtocol().equals("http")) {
this.fetcherCache = HashMapFeedInfoCache.getInstance();
this.fetcher = new HttpURLFeedFetcher(fetcherCache);
}
else {
throw new IllegalArgumentException("Unsupported URL protocol: " + feedUrl.getProtocol());
}
}
URL getFeedUrl() {
return this.feedUrl;
}
@Override
protected void onInit() throws Exception {
fetcher.addFetcherEventListener(new FeedQueueUpdatingFetcherListener());
Assert.notNull(this.feedUrl, "the feedUrl must not be null");
}
SyndFeed receiveFeed() {
SyndFeed feed = null;
try {
synchronized (this.feedMonitor) {
feed = this.fetcher.retrieveFeed(this.feedUrl);
if (logger.isDebugEnabled()) {
logger.debug("retrieved feed at url '" + this.feedUrl + "'");
}
if (feed == null) {
if (logger.isDebugEnabled()) {
logger.debug("no feeds updated, returning null");
}
}
}
}
catch (Exception e) {
throw new MessagingException(
"Failed to retrieve feed at url '" + this.feedUrl + "'", e);
}
return feed;
}
public Message<SyndFeed> receive() {
SyndFeed feed = this.receiveFeed();
if (feed == null) {
return null;
}
return MessageBuilder.withPayload(feed).setHeader(FeedConstants.FEED_URL, this.feedUrl).build();
}
private class FeedQueueUpdatingFetcherListener implements FetcherListener {
/**
* @see com.sun.syndication.fetcher.FetcherListener#fetcherEvent(com.sun.syndication.fetcher.FetcherEvent)
*/
public void fetcherEvent(final FetcherEvent event) {
String eventType = event.getEventType();
if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) {
logger.debug("\tEVENT: Feed Polled. URL = " + event.getUrlString());
}
else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) {
logger.debug("\tEVENT: Feed Retrieved. URL = " + event.getUrlString());
feeds.add(event.getFeed());
}
else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) {
logger.debug("\tEVENT: Feed Unchanged. URL = " + event.getUrlString());
}
}
}
}

View File

@@ -39,10 +39,10 @@ import com.sun.syndication.io.XmlReader;
* @author Mark Fisher
* @since 2.0
*/
public class FileUrlFeedFetcher extends AbstractFeedFetcher {
class FileUrlFeedFetcher extends AbstractFeedFetcher {
/*
* (non-Javadoc)
/**
* Retrieve a SyndFeed for the given URL.
* @see com.sun.syndication.fetcher.FeedFetcher#retrieveFeed(java.net.URL)
*/
public SyndFeed retrieveFeed(URL feedUrl) throws IOException, FeedException, FetcherException {

View File

@@ -25,24 +25,22 @@ import org.springframework.integration.config.xml.AbstractPollingInboundChannelA
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
/**
* Handles parsing the configuration for the feed inbound channel adapter.
* Handles parsing the configuration for the feed inbound-channel-adapter.
*
* @author Josh Long
* @author Oleg Zhurakousky
* @author Mark Fisher
* @since 2.0
*/
public class FeedMessageSourceBeanDefinitionParser extends AbstractPollingInboundChannelAdapterParser {
public class FeedInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser {
@Override
protected String parseSource(final Element element, final ParserContext parserContext) {
BeanDefinitionBuilder feedEntryBuilder = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.feed.FeedEntryReaderMessageSource");
BeanDefinitionBuilder feedBuilder = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.feed.FeedReaderMessageSource");
feedBuilder.addConstructorArgValue(element.getAttribute("url"));
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(feedEntryBuilder, element, "metadata-store");
feedEntryBuilder.addConstructorArgValue(feedBuilder.getBeanDefinition());
return BeanDefinitionReaderUtils.registerWithGeneratedName(feedEntryBuilder.getBeanDefinition(), parserContext.getRegistry());
BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.feed.FeedEntryMessageSource");
sourceBuilder.addConstructorArgValue(element.getAttribute("url"));
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(sourceBuilder, element, "metadata-store");
return BeanDefinitionReaderUtils.registerWithGeneratedName(sourceBuilder.getBeanDefinition(), parserContext.getRegistry());
}
}

View File

@@ -22,12 +22,13 @@ import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHa
* NamespaceHandler for the feed module.
*
* @author Josh Long
* @author Mark Fisher
* @since 2.0
*/
public class FeedNamespaceHandler extends AbstractIntegrationNamespaceHandler {
public void init() {
registerBeanDefinitionParser("inbound-channel-adapter", new FeedMessageSourceBeanDefinitionParser());
registerBeanDefinitionParser("inbound-channel-adapter", new FeedInboundChannelAdapterParser());
}
}

View File

@@ -18,15 +18,10 @@ package org.springframework.integration.feed;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
@@ -35,14 +30,13 @@ import org.springframework.integration.Message;
import org.springframework.integration.context.metadata.PropertiesPersistingMetadataStore;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
/**
* @author Oleg Zhurakousky
* @author Mark Fisher
* @since 2.0
*/
public class FeedEntryReaderMessageSourceTests {
public class FeedEntryMessageSourceTests {
@Before
public void prepare() {
@@ -53,47 +47,36 @@ public class FeedEntryReaderMessageSourceTests {
}
@Test(expected=IllegalArgumentException.class)
public void testFailureWhenNotInitialized() {
FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(mock(FeedReaderMessageSource.class));
public void testFailureWhenNotInitialized() throws Exception {
URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss");
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url);
feedEntrySource.receive();
}
@Test
public void testReceiveFeedWithNoEntries() {
FeedReaderMessageSource feedReaderSource = mock(FeedReaderMessageSource.class);
SyndFeed feed = mock(SyndFeed.class);
when(feedReaderSource.receiveFeed()).thenReturn(feed);
FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource);
public void testReceiveFeedWithNoEntries() throws Exception {
URL url = new URL("file:src/test/java/org/springframework/integration/feed/empty.rss");
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url);
feedEntrySource.setBeanName("feedReader");
feedEntrySource.afterPropertiesSet();
assertNull(feedEntrySource.receive());
}
@Test
public void testReceiveFeedWithEntriesSorted() {
FeedReaderMessageSource feedReaderSource = mock(FeedReaderMessageSource.class);
SyndFeed feed = mock(SyndFeed.class);
SyndEntry entry1 = mock(SyndEntry.class);
SyndEntry entry2 = mock(SyndEntry.class);
when(entry1.getPublishedDate()).thenReturn(new Date(System.currentTimeMillis()));
when(entry2.getPublishedDate()).thenReturn(new Date(System.currentTimeMillis()-10000));
List<SyndEntry> entries = new ArrayList<SyndEntry>();
entries.add(entry2);
entries.add(entry1);
when(feed.getEntries()).thenReturn(entries);
when(feedReaderSource.receiveFeed()).thenReturn(feed);
FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource);
feedEntrySource.setComponentName("feedReader");
feedEntrySource.afterPropertiesSet();
Message<SyndEntry> entryMessage = feedEntrySource.receive();
assertEquals(entry2, entryMessage.getPayload());
entryMessage = feedEntrySource.receive();
assertEquals(entry1, entryMessage.getPayload());
reset(feed);
entryMessage = feedEntrySource.receive();
assertNull(entryMessage);
public void testReceiveFeedWithEntriesSorted() throws Exception {
URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss");
FeedEntryMessageSource source = new FeedEntryMessageSource(url);
source.setComponentName("feedReader");
source.afterPropertiesSet();
Message<SyndEntry> message1 = source.receive();
Message<SyndEntry> message2 = source.receive();
Message<SyndEntry> message3 = source.receive();
long time1 = message1.getPayload().getPublishedDate().getTime();
long time2 = message2.getPayload().getPublishedDate().getTime();
long time3 = message3.getPayload().getPublishedDate().getTime();
assertTrue(time1 < time2);
assertTrue(time2 < time3);
assertNull(source.receive());
}
// will test that last feed entry is remembered between the sessions
@@ -101,8 +84,7 @@ public class FeedEntryReaderMessageSourceTests {
@Test
public void testReceiveFeedWithRealEntriesAndRepeatWithPersistentMetadataStore() throws Exception {
URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss");
FeedReaderMessageSource feedReaderSource = new FeedReaderMessageSource(url);
FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource);
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url);
feedEntrySource.setBeanName("feedReader");
PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore();
metadataStore.afterPropertiesSet();
@@ -126,7 +108,7 @@ public class FeedEntryReaderMessageSourceTests {
metadataStore.afterPropertiesSet();
// now test that what's been read is no longer retrieved
feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource);
feedEntrySource = new FeedEntryMessageSource(url);
feedEntrySource.setBeanName("feedReader");
metadataStore = new PropertiesPersistingMetadataStore();
metadataStore.afterPropertiesSet();
@@ -142,8 +124,7 @@ public class FeedEntryReaderMessageSourceTests {
@Test
public void testReceiveFeedWithRealEntriesAndRepeatNoPersistentMetadataStore() throws Exception {
URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss");
FeedReaderMessageSource feedReaderSource = new FeedReaderMessageSource(url);
FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource);
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url);
feedEntrySource.setBeanName("feedReader");
feedEntrySource.afterPropertiesSet();
SyndEntry entry1 = feedEntrySource.receive().getPayload();
@@ -162,7 +143,7 @@ public class FeedEntryReaderMessageSourceTests {
// UNLIKE the previous test
// now test that what's been read is read AGAIN
feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource);
feedEntrySource = new FeedEntryMessageSource(url);
feedEntrySource.setBeanName("feedReader");
feedEntrySource.afterPropertiesSet();
entry1 = feedEntrySource.receive().getPayload();

View File

@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-feed="http://www.springframework.org/schema/integration/feed"
xmlns:feed="http://www.springframework.org/schema/integration/feed"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/feed http://www.springframework.org/schema/integration/feed/spring-integration-feed-2.0.xsd">
<int-feed:inbound-channel-adapter id="feedAdapter"
<feed:inbound-channel-adapter id="feedAdapter"
channel="feedChannel"
auto-startup="false"
metadata-store="customMetadataStore"
url="file:src/test/java/org/springframework/integration/feed/config/sample.rss">
<int:poller fixed-rate="10000" max-messages-per-poll="100" />
</int-feed:inbound-channel-adapter>
</feed:inbound-channel-adapter>
<int:channel id="feedChannel">
<int:queue/>

View File

@@ -41,9 +41,7 @@ import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.context.metadata.MetadataStore;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.feed.FeedEntryReaderMessageSource;
import org.springframework.integration.feed.FeedReaderMessageSource;
import org.springframework.integration.feed.FileUrlFeedFetcher;
import org.springframework.integration.feed.FeedEntryMessageSource;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.test.util.TestUtils;
@@ -69,23 +67,28 @@ public class FeedMessageSourceBeanDefinitionParserTests {
}
@Test
public void validateSuccessfulConfigurationWithCustomMetadataStore() {
public void validateSuccessfulFileConfigurationWithCustomMetadataStore() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"FeedMessageSourceBeanDefinitionParserTests-file-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
FeedEntryReaderMessageSource source = (FeedEntryReaderMessageSource) TestUtils.getPropertyValue(adapter, "source");
FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source");
MetadataStore metadataStore = (MetadataStore) TestUtils.getPropertyValue(source, "metadataStore");
assertTrue(metadataStore instanceof SampleMetadataStore);
assertEquals(metadataStore, context.getBean("customMetadataStore"));
FeedReaderMessageSource feedReaderMessageSource = (FeedReaderMessageSource) TestUtils.getPropertyValue(source, "feedReaderMessageSource");
AbstractFeedFetcher fetcher = (AbstractFeedFetcher) TestUtils.getPropertyValue(feedReaderMessageSource, "fetcher");
assertTrue(fetcher instanceof FileUrlFeedFetcher);
context = new ClassPathXmlApplicationContext(
AbstractFeedFetcher fetcher = (AbstractFeedFetcher) TestUtils.getPropertyValue(source, "fetcher");
assertEquals("FileUrlFeedFetcher", fetcher.getClass().getSimpleName());
context.destroy();
}
public void validateSuccessfulHttpConfigurationWithCustomMetadataStore() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"FeedMessageSourceBeanDefinitionParserTests-http-context.xml", this.getClass());
adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
source = (FeedEntryReaderMessageSource) TestUtils.getPropertyValue(adapter, "source");
feedReaderMessageSource = (FeedReaderMessageSource) TestUtils.getPropertyValue(source, "feedReaderMessageSource");
fetcher = (AbstractFeedFetcher) TestUtils.getPropertyValue(feedReaderMessageSource, "fetcher");
SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source");
MetadataStore metadataStore = (MetadataStore) TestUtils.getPropertyValue(source, "metadataStore");
assertTrue(metadataStore instanceof SampleMetadataStore);
assertEquals(metadataStore, context.getBean("customMetadataStore"));
AbstractFeedFetcher fetcher = (AbstractFeedFetcher) TestUtils.getPropertyValue(source, "fetcher");
assertTrue(fetcher instanceof HttpURLFeedFetcher);
context.destroy();
}

View File

@@ -0,0 +1,20 @@
<rss version="2.0">
<channel>
<title>Spring Integration</title>
<link>http://www.springsource.org/spring-integration</link>
<description>
Spring Integration is a really cool framework
</description>
<language>en-us</language>
<copyright>Copyright 2004-2010 SpringSource/VMWare
All Rights Reserved.</copyright>
<lastBuildDate>Tue, 12 Apr 2010 18:21:32 EST</lastBuildDate>
<ttl>240</ttl>
<image>
<url>http://www.springsource.org/sites/all/themes/dotorg09/images/dotorg09_logo.png</url>
<title>Spring Integration</title>
<link>http://www.springsource.org/spring-integration</link>
</image>
</channel>
</rss>