| Commit in servicemix/base/src on MAIN | |||
| main/java/org/servicemix/components/rss/FeedWriter.java | +39 | -9 | 1.1 -> 1.2 |
| test/resources/org/servicemix/components/rss/example.xml | +23 | added 1.1 | |
| test/java/org/servicemix/components/rss/FeedWriterTest.java | +43 | added 1.1 | |
| +105 | -9 | ||
added a test case for the RSS feed writer
servicemix/base/src/main/java/org/servicemix/components/rss
diff -u -r1.1 -r1.2 --- FeedWriter.java 23 Sep 2005 02:01:34 -0000 1.1 +++ FeedWriter.java 23 Sep 2005 02:40:41 -0000 1.2 @@ -46,8 +46,7 @@
import java.util.List; /**
- * This component generates an RSS/Atom Feed from the JBI messages it - * receives.
+ * This component generates an RSS/Atom Feed from the JBI messages it receives.
* * @version $Revision$ */
@@ -60,7 +59,9 @@
private String feedDescription = "This feed is autogenerated by ServiceMix";
private int maximumEntryCount = 20;
private File feedFile;
+ private String contentType = "text/plain";
private SourceTransformer sourceTransformer = new SourceTransformer();
+ private boolean loadOnStartup = true;
public SyndFeed getCachedFeed() throws IllegalArgumentException, FeedException, IOException {
if (cachedFeed == null) {
@@ -124,8 +125,13 @@
this.feedFile = feedFile;
}
- // Implementation methods - // -------------------------------------------------------------------------
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
public SourceTransformer getSourceTransformer() {
return sourceTransformer;
@@ -135,6 +141,17 @@
this.sourceTransformer = sourceTransformer;
}
+ public boolean isLoadOnStartup() {
+ return loadOnStartup;
+ }
+
+ public void setLoadOnStartup(boolean loadOnStartup) {
+ this.loadOnStartup = loadOnStartup;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+
protected void init() throws JBIException {
super.init();
@@ -186,17 +203,27 @@
protected SyndContent createEntryContent(MessageExchange exchange, NormalizedMessage message)
throws TransformerException {
SyndContent description = new SyndContentImpl();
- description.setType("text/xml");
+ description.setType(contentType);
Source content = message.getContent();
// TODO use an _expression_ for the value?
if (content != null) {
String value = getSourceTransformer().toString(content);
+ + value = encodeContent(value); +
description.setValue(value);
}
return description;
}
+ /**
+ * Encodes the content so its valid XML when used inside an entry
+ */
+ protected String encodeContent(String value) {
+ return "<![CDATA[" + value + "]]>";
+ }
+
protected void writeFeed(SyndFeed feed, MessageExchange messageExchange, NormalizedMessage message)
throws IOException, FeedException {
Writer writer = new FileWriter(feedFile);
@@ -222,10 +249,13 @@
}
protected SyndFeed loadOrCreateFeed() throws IllegalArgumentException, FeedException, IOException {
- File file = getFeedFile();
- if (file.exists() && file.isFile()) {
- SyndFeedInput input = new SyndFeedInput();
- return input.build(new XmlReader(file));
+ if (isLoadOnStartup()) {
+ File file = getFeedFile();
+ if (file.exists() && file.isFile()) {
+ SyndFeedInput input = new SyndFeedInput();
+ XmlReader xmlReader = new XmlReader(file);
+ return input.build(xmlReader);
+ }
}
return createFeed();
}
servicemix/base/src/test/resources/org/servicemix/components/rss
example.xml added at 1.1
diff -N example.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ example.xml 23 Sep 2005 02:40:41 -0000 1.1 @@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns:foo="http://servicemix.org/cheese/"> + + <!-- the JBI container --> + <container id="jbi"> + <components> + + <component id="feedWriter" service="foo:feedWriter" class="org.servicemix.components.rss.FeedWriter"> + <property name="feedFile" value="target/serviceMixFeed.xml"/> + + <!-- TODO temporarily disable loading due to bug when running the test case for the 2nd time --> + <property name="loadOnStartup" value="false"/> + </component> + + <component id="receiver" service="foo:receiver" class="org.servicemix.examples.ReceiverComponent"/> + </components> + </container> + + <bean id="client" class="org.servicemix.client.DefaultServiceMixClient"> + <constructor-arg ref="jbi"/> + </bean> + +</beans>
servicemix/base/src/test/java/org/servicemix/components/rss
FeedWriterTest.java added at 1.1
diff -N FeedWriterTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ FeedWriterTest.java 23 Sep 2005 02:40:42 -0000 1.1 @@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * 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.servicemix.components.rss;
+
+import org.servicemix.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision$
+ */
+public class FeedWriterTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "feedWriter");
+
+ sendMessages(service, 20);
+
+ // now lets assert that the RSS feed has data in it.
+
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/servicemix/components/rss/example.xml");
+ }
+}
