diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2e975ff --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.classpath +/.project +/.settings +/target \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3456d30 --- /dev/null +++ b/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + + com.rometools + rome-certiorem-webapp + 1.0.0-SNAPSHOT + war + + + UTF-8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + + + + + com.rometools + rome-certiorem + 1.0.0-SNAPSHOT + + + com.google.inject + guice + 2.0 + + + com.google.inject.extensions + guice-servlet + 2.0 + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + junit + junit + 4.11 + test + + + + diff --git a/src/main/java/org/rometools/certiorem/example/HubServlet.java b/src/main/java/org/rometools/certiorem/example/HubServlet.java new file mode 100644 index 0000000..f41ea86 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/example/HubServlet.java @@ -0,0 +1,24 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.rometools.certiorem.example; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.rometools.certiorem.hub.Hub; +import org.rometools.certiorem.web.AbstractHubServlet; + +/** + * + * @author robert.cooper + */ +@Singleton +public class HubServlet extends AbstractHubServlet { + + @Inject + public HubServlet(final Hub hub){ + super(hub); + } +} diff --git a/src/main/java/org/rometools/certiorem/example/NotifyTest.java b/src/main/java/org/rometools/certiorem/example/NotifyTest.java new file mode 100644 index 0000000..b26eb09 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/example/NotifyTest.java @@ -0,0 +1,35 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.rometools.certiorem.example; + +import com.google.inject.Singleton; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.rometools.certiorem.pub.NotificationException; +import org.rometools.certiorem.pub.Publisher; + +/** + * + * @author robert.cooper + */ +@Singleton +public class NotifyTest extends HttpServlet{ + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException{ + Publisher pub = new Publisher(); + try { + pub.sendUpdateNotification("http://localhost/webapp/hub", "http://localhost/webapp/research-atom.xml"); + } catch (NotificationException ex) { + Logger.getLogger(NotifyTest.class.getName()).log(Level.SEVERE, null, ex); + throw new ServletException(ex); + } + } +} diff --git a/src/main/java/org/rometools/certiorem/example/ServerModule.java b/src/main/java/org/rometools/certiorem/example/ServerModule.java new file mode 100644 index 0000000..4cfa3db --- /dev/null +++ b/src/main/java/org/rometools/certiorem/example/ServerModule.java @@ -0,0 +1,73 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.rometools.certiorem.example; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.servlet.GuiceServletContextListener; +import com.google.inject.servlet.ServletModule; + +import org.rometools.certiorem.hub.Hub; +import org.rometools.certiorem.hub.data.ram.InMemoryHubDAO; +import org.rometools.certiorem.hub.notify.standard.UnthreadedNotifier; +import org.rometools.certiorem.hub.verify.standard.UnthreadedVerifier; +import org.rometools.certiorem.sub.Subscriptions; +import org.rometools.certiorem.sub.data.ram.InMemorySubDAO; +import org.rometools.certiorem.sub.request.AsyncRequester; + +import org.rometools.fetcher.FeedFetcher; +import org.rometools.fetcher.impl.HashMapFeedInfoCache; +import org.rometools.fetcher.impl.HttpURLFeedFetcher; + + +/** + * + * @author robert.cooper + */ +public class ServerModule extends GuiceServletContextListener { + @Override + protected Injector getInjector() { + return Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + } + + @Provides + @Singleton + public Hub buildHub() { + FeedFetcher fetcher = new HttpURLFeedFetcher(new HashMapFeedInfoCache()); + Hub hub = new Hub(new InMemoryHubDAO(), new UnthreadedVerifier(), new UnthreadedNotifier(), fetcher); + + return hub; + } + + @Provides + @Singleton + public Subscriptions buildSubs() { + System.out.println("buildSubs"); + Subscriptions subs = new Subscriptions(new HashMapFeedInfoCache(), new AsyncRequester(), + "http://localhost/webapp/subscriptions/", new InMemorySubDAO()); + + return subs; + } + }, + new ServletModule() { + @Override + protected void configureServlets() { + serve("/hub*") + .with(HubServlet.class); + serve("/subscriptions/*") + .with(SubServlet.class); + serve("/test/sub") + .with(SubTest.class); + serve("/test/pub") + .with(NotifyTest.class); + } + }); + } +} diff --git a/src/main/java/org/rometools/certiorem/example/SubServlet.java b/src/main/java/org/rometools/certiorem/example/SubServlet.java new file mode 100644 index 0000000..97c6d6b --- /dev/null +++ b/src/main/java/org/rometools/certiorem/example/SubServlet.java @@ -0,0 +1,26 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.rometools.certiorem.example; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.name.Named; +import org.rometools.certiorem.sub.Subscriptions; +import org.rometools.certiorem.web.AbstractSubServlet; + +/** + * + * @author robert.cooper + */ +@Singleton +public class SubServlet extends AbstractSubServlet { + + @Inject + public SubServlet(final Subscriptions subscriptions){ + super(subscriptions); + } + +} diff --git a/src/main/java/org/rometools/certiorem/example/SubTest.java b/src/main/java/org/rometools/certiorem/example/SubTest.java new file mode 100644 index 0000000..ba4c2c3 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/example/SubTest.java @@ -0,0 +1,61 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.rometools.certiorem.example; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.rometools.certiorem.sub.Subscriptions; +import org.rometools.certiorem.sub.data.Subscription; +import org.rometools.certiorem.sub.data.SubscriptionCallback; +import org.rometools.fetcher.impl.SyndFeedInfo; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +/** + * + * @author robert.cooper + */ +@Singleton +public class SubTest extends HttpServlet { + + private final Subscriptions subs; + + @Inject + public SubTest(final Subscriptions subs) { + this.subs = subs; + } + + @Override + public void doGet(final HttpServletRequest request, final HttpServletResponse response) { + subs.subscribe("http://localhost/webapp/hub", "http://localhost/webapp/research-atom.xml", true, -1L, null, new SubscriptionCallback() { + + @Override + public void onFailure(final Exception e) { + e.printStackTrace(); + } + + @Override + public void onSubscribe(final Subscription subscribed) { + System.out.println("Subscribed " + subscribed.getId() + " " + subscribed.getSourceUrl()); + } + + @Override + public void onNotify(final Subscription subscribed, final SyndFeedInfo feedInfo) { + // TODO Auto-generated method stub + } + + @Override + public void onUnsubscribe(final Subscription subscribed) { + // TODO Auto-generated method stub + } + + }); + } + +} diff --git a/src/main/webapp/WEB-INF/sun-web.xml b/src/main/webapp/WEB-INF/sun-web.xml new file mode 100644 index 0000000..0599c81 --- /dev/null +++ b/src/main/webapp/WEB-INF/sun-web.xml @@ -0,0 +1,11 @@ + + + + /webapp + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..5bc7954 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,31 @@ + + + + rome-certiorem-webapp + + + 30 + + + + index.jsp + + + + guiceFilter + com.google.inject.servlet.GuiceFilter + + + + guiceFilter + /* + + + + Guice config + org.rometools.certiorem.example.ServerModule + + + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..ab292c3 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,13 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + JSP Page + + +

Hello World!

+ + diff --git a/src/main/webapp/research-atom.xml b/src/main/webapp/research-atom.xml new file mode 100644 index 0000000..d3b6359 --- /dev/null +++ b/src/main/webapp/research-atom.xml @@ -0,0 +1,59 @@ + + + + +The name of your feed + + +2003-12-13T18:30:02Z + + + The name of the author + + + + + Analysis of tsunami on the economy + Analysis of the recent tsumani on the economy + + tag:providers-website-item1.com,2003:3.2397 + 2003-12-13T08:29:29-04:00 + 2003-12-13T18:30:02Z + http://www.providers-website.com/image1.jpg + 2005-12-20 + Economy + Tsunami + + 2005-02-25 + James Smith + Tsunami and the Economy + III + 5 + + + + + + Google and the internet + Analysis of Google's impact on the internet + + tag:providers-website-item1.com,2003:3.2397 + 2003-12-13T08:29:29-04:00 + 2003-12-13T18:30:02Z + http://www.providers-website.com/image2.jpg + 2005-12-20 + Internet + Search Engine + + 2004-01-29 + Sue Smith + Google and the Internet + VI + 23 + + +