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/README.md b/README.md new file mode 100644 index 0000000..4679522 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +rome-certiorem-webapp +===================== + +Example project using rome-certiorem diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8288c2c --- /dev/null +++ b/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + + com.rometools + rome-parent + 1.6.0-SNAPSHOT + + + rome-certiorem-webapp + war + + rome-certiorem-webapp + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + scm:git:git@github.com:rometools/rome-certiorem-webapp.git + scm:git:git@github.com:rometools/rome-certiorem-webapp.git + https://github.com/rometools/rome-certiorem-webapp/ + + + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + + + com.rometools + rome-certiorem + 1.5.0 + + + com.google.inject.extensions + guice-servlet + + + javax.servlet + servlet-api + provided + + + + diff --git a/src/main/java/com/rometools/certiorem/webapp/HubServlet.java b/src/main/java/com/rometools/certiorem/webapp/HubServlet.java new file mode 100644 index 0000000..ea4e3bc --- /dev/null +++ b/src/main/java/com/rometools/certiorem/webapp/HubServlet.java @@ -0,0 +1,27 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.rometools.certiorem.webapp; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.rometools.certiorem.hub.Hub; +import com.rometools.certiorem.web.AbstractHubServlet; + +/** + * + * @author robert.cooper + */ +@Singleton +public class HubServlet extends AbstractHubServlet { + + private static final long serialVersionUID = 1L; + + @Inject + public HubServlet(final Hub hub) { + super(hub); + } + +} diff --git a/src/main/java/com/rometools/certiorem/webapp/NotifyTest.java b/src/main/java/com/rometools/certiorem/webapp/NotifyTest.java new file mode 100644 index 0000000..3430e0f --- /dev/null +++ b/src/main/java/com/rometools/certiorem/webapp/NotifyTest.java @@ -0,0 +1,42 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.rometools.certiorem.webapp; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.inject.Singleton; +import com.rometools.certiorem.pub.NotificationException; +import com.rometools.certiorem.pub.Publisher; + +/** + * + * @author robert.cooper + */ +@Singleton +public class NotifyTest extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOG = LoggerFactory.getLogger(NotifyTest.class); + + @Override + public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { + final Publisher pub = new Publisher(); + try { + pub.sendUpdateNotification("http://localhost/webapp/hub", "http://localhost/webapp/research-atom.xml"); + } catch (final NotificationException ex) { + LOG.error(null, ex); + throw new ServletException(ex); + } + } + +} diff --git a/src/main/java/com/rometools/certiorem/webapp/ServerModule.java b/src/main/java/com/rometools/certiorem/webapp/ServerModule.java new file mode 100644 index 0000000..865cc55 --- /dev/null +++ b/src/main/java/com/rometools/certiorem/webapp/ServerModule.java @@ -0,0 +1,71 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rometools.certiorem.webapp; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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 com.rometools.certiorem.hub.Hub; +import com.rometools.certiorem.hub.data.ram.InMemoryHubDAO; +import com.rometools.certiorem.hub.notify.standard.UnthreadedNotifier; +import com.rometools.certiorem.hub.verify.standard.UnthreadedVerifier; +import com.rometools.certiorem.sub.Subscriptions; +import com.rometools.certiorem.sub.data.ram.InMemorySubDAO; +import com.rometools.certiorem.sub.request.AsyncRequester; +import com.rometools.fetcher.FeedFetcher; +import com.rometools.fetcher.impl.HashMapFeedInfoCache; +import com.rometools.fetcher.impl.HttpURLFeedFetcher; + +/** + * + * @author robert.cooper + */ +public class ServerModule extends GuiceServletContextListener { + + private static final Logger LOG = LoggerFactory.getLogger(ServerModule.class); + + @Override + protected Injector getInjector() { + return Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + } + + @Provides + @Singleton + public Hub buildHub() { + final FeedFetcher fetcher = new HttpURLFeedFetcher(new HashMapFeedInfoCache()); + final Hub hub = new Hub(new InMemoryHubDAO(), new UnthreadedVerifier(), new UnthreadedNotifier(), fetcher); + + return hub; + } + + @Provides + @Singleton + public Subscriptions buildSubs() { + LOG.debug("buildSubs"); + final 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/com/rometools/certiorem/webapp/SubServlet.java b/src/main/java/com/rometools/certiorem/webapp/SubServlet.java new file mode 100644 index 0000000..8e78ece --- /dev/null +++ b/src/main/java/com/rometools/certiorem/webapp/SubServlet.java @@ -0,0 +1,27 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.rometools.certiorem.webapp; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.rometools.certiorem.sub.Subscriptions; +import com.rometools.certiorem.web.AbstractSubServlet; + +/** + * + * @author robert.cooper + */ +@Singleton +public class SubServlet extends AbstractSubServlet { + + private static final long serialVersionUID = 1L; + + @Inject + public SubServlet(final Subscriptions subscriptions) { + super(subscriptions); + } + +} diff --git a/src/main/java/com/rometools/certiorem/webapp/SubTest.java b/src/main/java/com/rometools/certiorem/webapp/SubTest.java new file mode 100644 index 0000000..c728b16 --- /dev/null +++ b/src/main/java/com/rometools/certiorem/webapp/SubTest.java @@ -0,0 +1,67 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.rometools.certiorem.webapp; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.rometools.certiorem.sub.Subscriptions; +import com.rometools.certiorem.sub.data.Subscription; +import com.rometools.certiorem.sub.data.SubscriptionCallback; +import com.rometools.fetcher.impl.SyndFeedInfo; + +/** + * + * @author robert.cooper + */ +@Singleton +public class SubTest extends HttpServlet { + + private static final Logger LOG = LoggerFactory.getLogger(SubTest.class); + + private static final long serialVersionUID = 1L; + + 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) { + LOG.debug("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/resources/.gitignore b/src/main/resources/.gitignore new file mode 100644 index 0000000..53b845b --- /dev/null +++ b/src/main/resources/.gitignore @@ -0,0 +1 @@ +# needed to commit empty folder \ No newline at end of file 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..bec632b --- /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 + com.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 + + + diff --git a/src/test/java/.gitignore b/src/test/java/.gitignore new file mode 100644 index 0000000..53b845b --- /dev/null +++ b/src/test/java/.gitignore @@ -0,0 +1 @@ +# needed to commit empty folder \ No newline at end of file diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore new file mode 100644 index 0000000..53b845b --- /dev/null +++ b/src/test/resources/.gitignore @@ -0,0 +1 @@ +# needed to commit empty folder \ No newline at end of file