Commit in servicemix/base on MAIN
lib/rome/rome-fetcher-0.6.jar[binary]added 1.1
        /rome-0.6.jar[binary]added 1.1
src/main/release/examples/bpel/servicemix.xml+3-11.4 -> 1.5
src/main/java/org/servicemix/components/rss/RssPollingComponent.java+221added 1.1
+224-1
3 added + 1 modified, total 4 files
Added Rome RSS support

servicemix/base/src/main/release/examples/bpel
servicemix.xml 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- servicemix.xml	5 Aug 2005 09:54:07 -0000	1.4
+++ servicemix.xml	11 Aug 2005 16:38:08 -0000	1.5
@@ -6,6 +6,8 @@
    <property name="rootDir" value="./wdir"/>
    <property name="createMBeanServer" value="true"/>
    <property name="installationDirPath" value="./install"/>
+   <property name="deploymentDirPath" value="./deploy"/>
+
    <property name="monitorInstallationDirectory" value="true"/>
    <property name="dumpStats" value="true"/>
    <property name="statsInterval" value="10"/>
@@ -14,7 +16,7 @@
     <components>
 
       <!-- Subscribe to a JMS destination -->
-      <component id="myComponent" service="pxe:JmService" class="org.servicemix.components.jms.JmsServiceComponent"
+      <component id="myComponent" service="pxe:JmsService" class="org.servicemix.components.jms.JmsServiceComponent"
         destinationService="pxe:ProcessSVC" destinationEndpoint="ProcessPORT" destinationOperation="Run">
         <property name="template">
           <bean class="org.springframework.jms.core.JmsTemplate">

servicemix/base/src/main/java/org/servicemix/components/rss
RssPollingComponent.java added at 1.1
diff -N RssPollingComponent.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ RssPollingComponent.java	11 Aug 2005 16:38:08 -0000	1.1
@@ -0,0 +1,221 @@
+/** 
+ * <a href="">ServiceMix: The open source ESB</a> 
+ * 
+ * Copyright 2005 RAJD Consultancy Ltd
+ * 
+ * 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 java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.servicemix.components.util.ComponentSupport;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.SyndFeedOutput;
+import com.sun.syndication.io.XmlReader;
+
+/**
+ * The RssPollingComponent polls for updates to RSS feeds
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class RssPollingComponent extends ComponentSupport {
+    private static final Log log = LogFactory.getLog(RssPollingComponent.class);
+    private List urlStrings = new ArrayList();
+    private List urls = new ArrayList();
+    private Date lastPolledDate = new Date(0);
+    private String outputType = "rss_2.0";
+    private int monitorInterval = 10;// time in seconds
+    private Timer statsTimer = new Timer(true);
+    private TimerTask timerTask;
+
+    /**
+     * Start the item.
+     * 
+     * @exception javax.jbi.JBIException if the item fails to start.
+     */
+    public void start() throws javax.jbi.JBIException {
+        super.start();
+        urls.clear();
+        if (urlStrings != null) {
+            for (int i = 0;i < urlStrings.size();i++) {
+                try {
+                    urls.add(new URL(urlStrings.get(i).toString()));
+                }
+                catch (MalformedURLException e) {
+                    log.warn("URL: " + urlStrings.get(i) + " is badly formed", e);
+                }
+            }
+        }
+        if (timerTask != null) {
+            timerTask.cancel();
+        }
+        timerTask = new TimerTask() {
+            public void run() {
+                doPoll();
+            }
+        };
+        long interval = monitorInterval * 1000;
+        statsTimer.scheduleAtFixedRate(timerTask, 0, interval);
+        
+    }
+
+    /**
+     * Stop the item. This suspends current messaging activities.
+     * 
+     * @exception javax.jbi.JBIException if the item fails to stop.
+     */
+    public void stop() throws javax.jbi.JBIException {
+        if (timerTask != null) {
+            timerTask.cancel();
+            timerTask = null;
+        }
+        super.stop();
+    }
+
+    /**
+     * Shut down the item. The releases resources, preparatory to uninstallation.
+     * 
+     * @exception javax.jbi.JBIException if the item fails to shut down.
+     */
+    public void shutDown() throws javax.jbi.JBIException {
+        stop();
+        super.shutDown();
+    }
+
+    /**
+     * @return Returns the urlStrings.
+     */
+    public List getUrlStrings() {
+        return urlStrings;
+    }
+
+    /**
+     * @param urlStrings The urlStrings to set.
+     */
+    public void setUrlStrings(List urlStrings) {
+        this.urlStrings = urlStrings;
+    }
+
+    /**
+     * @return Returns the outputType.
+     */
+    public String getOutputType() {
+        return outputType;
+    }
+
+    /**
+     * @param outputType The outputType to set.
+     */
+    public void setOutputType(String outputType) {
+        this.outputType = outputType;
+    }
+
+    /**
+     * @return Returns the lastPolledDate.
+     */
+    public Date getLastPolledDate() {
+        return lastPolledDate;
+    }
+
+    /**
+     * @param lastPolledDate The lastPolledDate to set.
+     */
+    public void setLastPolledDate(Date startDate) {
+        this.lastPolledDate = startDate;
+    }
+
+    /**
+     * @return Returns the monitorInterval (number in secs)
+     */
+    public int getMonitorInterval() {
+        return monitorInterval;
+    }
+
+    /**
+     * @param monitorInterval The monitorInterval to set (in secs)
+     */
+    public void setMonitorInterval(int monitorInterval) {
+        this.monitorInterval = monitorInterval;
+    }
+
+    /**
+     * Poll for updates
+     */
+    protected void doPoll() {
+        List list = getLastesEntries();
+        if (list != null && !list.isEmpty()) {
+            SyndFeed feed = new SyndFeedImpl();
+            feed.setFeedType(outputType);
+            feed.setTitle("Aggregated Feed");
+            feed.setDescription("Anonymous Aggregated Feed");
+            feed.setAuthor("servicemix");
+            feed.setLink("http://www.servicemix.org");
+            feed.setEntries(list);
+            // send on to the nmr ...
+            SyndFeedOutput output = new SyndFeedOutput();
+            try {
+                Source source = new DOMSource(output.outputW3CDom(feed));
+                InOnly exchange = getExchangeFactory().createInOnlyExchange();
+                NormalizedMessage message = exchange.createMessage();
+                message.setContent(source);
+                exchange.setInMessage(message);
+                done(exchange);
+            }
+            catch (Exception e) {
+                log.error("Failed to send RSS message to the NMR");
+            }
+            finally {
+                lastPolledDate = new Date();
+            }
+        }
+    }
+
+    protected List getLastesEntries() {
+        List result = new ArrayList();
+        SyndFeedInput input = new SyndFeedInput();
+        for (int i = 0;i < urls.size();i++) {
+            URL inputUrl = (URL) urls.get(i);
+            SyndFeed inFeed;
+            try {
+                inFeed = input.build(new XmlReader(inputUrl));
+                List entries = inFeed.getEntries();
+                for (int k = 0;k < entries.size();k++) {
+                    SyndEntry entry = (SyndEntry) entries.get(k);
+                    if (entry.getPublishedDate().after(getLastPolledDate())) {
+                        result.add(entry);
+                    }
+                }
+            }
+            catch (Exception e) {
+                log.warn("Failed to process feed from: " + inputUrl, e);
+            }
+        }
+        return result;
+    }
+}
CVSspam 0.2.8



Reply via email to