Initial commit

This commit is contained in:
Patrick Gotthard 2013-10-11 23:46:36 +02:00
parent 8c16767249
commit e8b6acab4c
11 changed files with 404 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/.classpath
/.project
/.settings
/target

67
pom.xml Normal file
View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rometools</groupId>
<artifactId>rome-certiorem-webapp</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-certiorem</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -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);
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
});
}
}

View file

@ -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);
}
}

View file

@ -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
}
});
}
}

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
<context-root>/webapp</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</sun-web-app>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>rome-certiorem-webapp</display-name>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<display-name>Guice config</display-name>
<listener-class>org.rometools.certiorem.example.ServerModule</listener-class>
</listener>
</web-app>

13
src/main/webapp/index.jsp Normal file
View file

@ -0,0 +1,13 @@
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

View file

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#"
xmlns:g="http://base.google.com/ns/1.0">
<title>The name of your feed</title>
<link href="The URL to the HTML website"
rel="alternate" type="text/html"/>
<modified>2003-12-13T18:30:02Z</modified>
<author>
<name>The name of the author</name>
</author>
<entry>
<title>Analysis of tsunami on the economy</title>
<summary>Analysis of the recent tsumani on the economy</summary>
<link rel="alternate" type="text/html"
href="http://provider-website.com/item1-info-page.html"/>
<id>tag:providers-website-item1.com,2003:3.2397</id>
<issued>2003-12-13T08:29:29-04:00</issued>
<modified>2003-12-13T18:30:02Z</modified>
<g:image_link>http://www.providers-website.com/image1.jpg</g:image_link>
<g:expiration_date>2005-12-20</g:expiration_date>
<g:label>Economy</g:label>
<g:label>Tsunami</g:label>
<g:publish_date>2005-02-25</g:publish_date>
<g:author>James Smith</g:author>
<g:publication_name>Tsunami and the Economy</g:publication_name>
<g:publication_volume>III</g:publication_volume>
<g:pages>5</g:pages>
</entry>
<entry>
<title>Google and the internet</title>
<summary>Analysis of Google's impact on the internet</summary>
<link rel="alternate" type="text/html"
href="http://provider-website.com/item2-info-page.html"/>
<id>tag:providers-website-item1.com,2003:3.2397</id>
<issued>2003-12-13T08:29:29-04:00</issued>
<modified>2003-12-13T18:30:02Z</modified>
<g:image_link>http://www.providers-website.com/image2.jpg</g:image_link>
<g:expiration_date>2005-12-20</g:expiration_date>
<g:label>Internet</g:label>
<g:label>Search Engine</g:label>
<g:publish_date>2004-01-29</g:publish_date>
<g:author>Sue Smith</g:author>
<g:publication_name>Google and the Internet</g:publication_name>
<g:publication_volume>VI</g:publication_volume>
<g:pages>23</g:pages>
</entry>
</feed>