From 62c5c1fd435bdfec4b425bb9e50ac866f11087e0 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 11 Oct 2013 23:39:43 +0200 Subject: [PATCH 01/23] Initial commit --- .gitignore | 4 + LICENSE | 202 ++++++++++++ README | 9 + pom.xml | 157 +++++++++ .../certiorem/HttpStatusCodeException.java | 39 +++ .../certiorem/hub/DeltaFeedInfoCache.java | 51 +++ .../certiorem/hub/DeltaSyndFeedInfo.java | 122 +++++++ .../java/org/rometools/certiorem/hub/Hub.java | 257 +++++++++++++++ .../org/rometools/certiorem/hub/Notifier.java | 53 ++++ .../org/rometools/certiorem/hub/Verifier.java | 78 +++++ .../rometools/certiorem/hub/data/HubDAO.java | 42 +++ .../certiorem/hub/data/Subscriber.java | 221 +++++++++++++ .../hub/data/SubscriptionSummary.java | 86 +++++ .../certiorem/hub/data/jpa/JPADAO.java | 131 ++++++++ .../certiorem/hub/data/jpa/JPASubscriber.java | 111 +++++++ .../certiorem/hub/data/jpa/package.html | 28 ++ .../rometools/certiorem/hub/data/package.html | 29 ++ .../hub/data/ram/InMemoryHubDAO.java | 138 ++++++++ .../certiorem/hub/data/ram/package.html | 25 ++ .../hub/notify/standard/AbstractNotifier.java | 170 ++++++++++ .../hub/notify/standard/Notification.java | 38 +++ .../notify/standard/ThreadPoolNotifier.java | 114 +++++++ .../notify/standard/UnthreadedNotifier.java | 49 +++ .../hub/notify/standard/package.html | 32 ++ .../org/rometools/certiorem/hub/package.html | 30 ++ .../hub/verify/standard/AbstractVerifier.java | 108 +++++++ .../verify/standard/ThreadPoolVerifier.java | 68 ++++ .../standard/ThreadpoolVerifierAdvanced.java | 33 ++ .../verify/standard/UnthreadedVerifier.java | 41 +++ .../hub/verify/standard/package.html | 32 ++ .../java/org/rometools/certiorem/package.html | 30 ++ .../certiorem/pub/NotificationException.java | 36 +++ .../rometools/certiorem/pub/Publisher.java | 248 +++++++++++++++ .../org/rometools/certiorem/pub/package.html | 29 ++ .../rometools/certiorem/sub/Requester.java | 40 +++ .../certiorem/sub/Subscriptions.java | 298 ++++++++++++++++++ .../rometools/certiorem/sub/data/SubDAO.java | 36 +++ .../certiorem/sub/data/Subscription.java | 158 ++++++++++ .../sub/data/SubscriptionCallback.java | 23 ++ .../rometools/certiorem/sub/data/package.html | 28 ++ .../sub/data/ram/InMemorySubDAO.java | 74 +++++ .../certiorem/sub/data/ram/package.html | 28 ++ .../org/rometools/certiorem/sub/package.html | 30 ++ .../sub/request/AbstractRequester.java | 85 +++++ .../certiorem/sub/request/AsyncRequester.java | 74 +++++ .../certiorem/sub/request/SyncRequester.java | 68 ++++ .../certiorem/sub/request/package.html | 28 ++ .../certiorem/web/AbstractHubServlet.java | 86 +++++ .../certiorem/web/AbstractSubServlet.java | 79 +++++ .../org/rometools/certiorem/web/package.html | 31 ++ src/main/resources/META-INF/persistence.xml | 30 ++ src/site/apt/Certiorem.apt | 47 +++ src/site/apt/CertioremTutorial.apt | 124 ++++++++ src/site/apt/index.apt | 15 + src/site/resources/.nojekyll | 0 src/site/resources/css/site.css | 8 + src/site/resources/images/romelogo.png | Bin 0 -> 10835 bytes src/site/site.xml | 33 ++ .../certiorem/hub/AlwaysVerifier.java | 50 +++ .../certiorem/hub/ControllerTest.java | 124 ++++++++ .../certiorem/hub/DeltaSyndFeedInfoTest.java | 77 +++++ .../certiorem/hub/ExceptionVerifier.java | 50 +++ .../certiorem/hub/NeverVerifier.java | 50 +++ .../certiorem/hub/data/AbstractDAOTest.java | 89 ++++++ .../hub/data/ram/InMemoryDAOTest.java | 44 +++ 65 files changed, 4748 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README create mode 100644 pom.xml create mode 100644 src/main/java/org/rometools/certiorem/HttpStatusCodeException.java create mode 100644 src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java create mode 100644 src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java create mode 100644 src/main/java/org/rometools/certiorem/hub/Hub.java create mode 100644 src/main/java/org/rometools/certiorem/hub/Notifier.java create mode 100644 src/main/java/org/rometools/certiorem/hub/Verifier.java create mode 100644 src/main/java/org/rometools/certiorem/hub/data/HubDAO.java create mode 100644 src/main/java/org/rometools/certiorem/hub/data/Subscriber.java create mode 100644 src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java create mode 100644 src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java create mode 100644 src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java create mode 100644 src/main/java/org/rometools/certiorem/hub/data/jpa/package.html create mode 100644 src/main/java/org/rometools/certiorem/hub/data/package.html create mode 100644 src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java create mode 100644 src/main/java/org/rometools/certiorem/hub/data/ram/package.html create mode 100644 src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java create mode 100644 src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java create mode 100644 src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java create mode 100644 src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java create mode 100644 src/main/java/org/rometools/certiorem/hub/notify/standard/package.html create mode 100644 src/main/java/org/rometools/certiorem/hub/package.html create mode 100644 src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java create mode 100644 src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java create mode 100644 src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java create mode 100644 src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java create mode 100644 src/main/java/org/rometools/certiorem/hub/verify/standard/package.html create mode 100644 src/main/java/org/rometools/certiorem/package.html create mode 100644 src/main/java/org/rometools/certiorem/pub/NotificationException.java create mode 100644 src/main/java/org/rometools/certiorem/pub/Publisher.java create mode 100644 src/main/java/org/rometools/certiorem/pub/package.html create mode 100644 src/main/java/org/rometools/certiorem/sub/Requester.java create mode 100644 src/main/java/org/rometools/certiorem/sub/Subscriptions.java create mode 100644 src/main/java/org/rometools/certiorem/sub/data/SubDAO.java create mode 100644 src/main/java/org/rometools/certiorem/sub/data/Subscription.java create mode 100644 src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java create mode 100644 src/main/java/org/rometools/certiorem/sub/data/package.html create mode 100644 src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java create mode 100644 src/main/java/org/rometools/certiorem/sub/data/ram/package.html create mode 100644 src/main/java/org/rometools/certiorem/sub/package.html create mode 100644 src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java create mode 100644 src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java create mode 100644 src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java create mode 100644 src/main/java/org/rometools/certiorem/sub/request/package.html create mode 100644 src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java create mode 100644 src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java create mode 100644 src/main/java/org/rometools/certiorem/web/package.html create mode 100644 src/main/resources/META-INF/persistence.xml create mode 100644 src/site/apt/Certiorem.apt create mode 100644 src/site/apt/CertioremTutorial.apt create mode 100644 src/site/apt/index.apt create mode 100644 src/site/resources/.nojekyll create mode 100644 src/site/resources/css/site.css create mode 100644 src/site/resources/images/romelogo.png create mode 100644 src/site/site.xml create mode 100644 src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java create mode 100644 src/test/java/org/rometools/certiorem/hub/ControllerTest.java create mode 100644 src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java create mode 100644 src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java create mode 100644 src/test/java/org/rometools/certiorem/hub/NeverVerifier.java create mode 100644 src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java create mode 100644 src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java 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/LICENSE b/LICENSE new file mode 100644 index 0000000..9b5e401 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..7b08171 --- /dev/null +++ b/README @@ -0,0 +1,9 @@ +ROME Certiorem + +Build Instructions +------------------------------------------------------------------------------- + +To build with Maven 2+: + +> mvn package + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f1fa07c --- /dev/null +++ b/pom.xml @@ -0,0 +1,157 @@ + + + + 4.0.0 + + + rome-push + com.rometools + 1.0.0-SNAPSHOT + + + rome-certiorem + + rome-certiorem + + A PubSubHubub implementation for Java based on ROME + + + scm:svn:https://rometools.jira.com/svn/INCUBATOR/trunk/pubsubhubub/certiorem/ + scm:svn:https://rometools.jira.com/svn/INCUBATOR/trunk/pubsubhubub/certiorem/ + https://rometools.jira.com/svn/INCUBATOR/trunk/pubsubhubub/certiorem/ + + + + + Apache 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + kebernet + Robert Cooper + kebernet@gmail.comM + http://www.kebernet.net + + + fnajmi + Farrukh Najmi + http://wellfleetsoftware.com + + + + + UTF-8 + UTF-8 + + + + + central.staging + http://oss.sonatype.org/service/local/staging/deploy/maven2 + + + sonatype.snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + + + + sonatype.snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + false + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + + + + + com.rometools + rome-fetcher + 2.0.0-SNAPSHOT + + + commons-httpclient + commons-httpclient + + + commons-logging + commons-logging-api + + + commons-logging + commons-logging + + + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.persistence + persistence-api + 1.0 + provided + + + junit + junit + 4.11 + test + + + + diff --git a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java b/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java new file mode 100644 index 0000000..1bdeb0f --- /dev/null +++ b/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java @@ -0,0 +1,39 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem; + +/** + * + * @author robert.cooper + */ +public class HttpStatusCodeException extends RuntimeException { + + private final int status; + + public HttpStatusCodeException(int status, String message, Throwable cause){ + super(message, cause); + this.status = status; + } + + public int getStatus(){ + return this.status; + } + +} diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java new file mode 100644 index 0000000..a0702f3 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java @@ -0,0 +1,51 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.rometools.certiorem.hub; + +import java.net.URL; +import org.rometools.fetcher.impl.FeedFetcherCache; +import org.rometools.fetcher.impl.SyndFeedInfo; + +/** + * Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure that + * any SyndFeedInfo used within it are replaced with a DeltaSyndFeedInfo which is capable of + * tracking changes to entries in the underlying feed. + * + * @author najmi + */ +public class DeltaFeedInfoCache implements FeedFetcherCache { + + FeedFetcherCache backingCache; + + + public DeltaFeedInfoCache(FeedFetcherCache backingCache) { + this.backingCache = backingCache; + } + + @Override + public SyndFeedInfo getFeedInfo(URL feedUrl) { + return backingCache.getFeedInfo(feedUrl); + } + + @Override + public void setFeedInfo(URL feedUrl, SyndFeedInfo syndFeedInfo) { + //Make sure that syndFeedInfo is an instance of DeltaSyndFeedInfo + if (!(syndFeedInfo instanceof DeltaSyndFeedInfo)) { + syndFeedInfo = new DeltaSyndFeedInfo(syndFeedInfo); + } + backingCache.setFeedInfo(feedUrl, syndFeedInfo); + } + + @Override + public void clear() { + backingCache.clear(); + } + + @Override + public SyndFeedInfo remove(URL feedUrl) { + return backingCache.remove(feedUrl); + } + +} diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java new file mode 100644 index 0000000..0bb13c5 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java @@ -0,0 +1,122 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.rometools.certiorem.hub; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; +import java.math.BigInteger; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.rometools.fetcher.impl.SyndFeedInfo; + +/** + * Extends SyndFeedInfo to also track etags for individual entries. + * This may be used with DeltaFeedInfoCache to only return feed with a subset of entries that have changed since last fetch. + * + * @author najmi + */ +public class DeltaSyndFeedInfo extends SyndFeedInfo { + Map entryTagsMap = new HashMap(); + Map changedMap = new HashMap(); + + private DeltaSyndFeedInfo() { + } + + public DeltaSyndFeedInfo(SyndFeedInfo backingFeedInfo) { + this.setETag(backingFeedInfo.getETag()); + this.setId(backingFeedInfo.getId()); + this.setLastModified(backingFeedInfo.getLastModified()); + this.setSyndFeed(backingFeedInfo.getSyndFeed()); + } + + /** + * Gets a filtered version of the SyndFeed that only has entries that were changed in the last setSyndFeed() call. + * + * @return + */ + @Override + public synchronized SyndFeed getSyndFeed() { + try { + SyndFeed feed = (SyndFeed) super.getSyndFeed().clone(); + + List changedEntries = new ArrayList(); + + List entries = feed.getEntries(); + for (SyndEntry entry : entries) { + if (changedMap.containsKey(entry.getUri())) { + changedEntries.add(entry); + } + } + + feed.setEntries(changedEntries); + + return feed; + } catch (CloneNotSupportedException ex) { + throw new RuntimeException(ex); + } + } + + /** + * Overrides super class method to update changedMap and entryTagsMap for tracking changed entries. + * + * @param feed + */ + @Override + public final synchronized void setSyndFeed(SyndFeed feed) { + super.setSyndFeed(feed); + + changedMap.clear(); + List entries = feed.getEntries(); + for (SyndEntry entry : entries) { + String currentEntryTag = computeEntryTag(entry); + String previousEntryTag = entryTagsMap.get(entry.getUri()); + + if ((previousEntryTag == null) || (!(currentEntryTag.equals(previousEntryTag)))) { + //Entry has changed + changedMap.put(entry.getUri(), Boolean.TRUE); + } + entryTagsMap.put(entry.getUri(), currentEntryTag); + } + } + + private String computeEntryTag(SyndEntry entry) { + + //Following hash algorithm suggested by Robert Cooper needs to be evaluated in future. +// int hash = ( entry.getUri() != null ? entry.getUri().hashCode() : entry.getLink().hashCode() ) ^ +// (entry.getUpdatedDate() != null ? entry.getUpdatedDate().hashCode() : entry.getPublishedDate().hashCode()) ^ +// entry.getTitle().hashCode() ^ +// entry.getDescription().hashCode(); + + + String id = entry.getUri(); + Date updateDate = entry.getUpdatedDate(); + Date publishedDate = entry.getPublishedDate(); + if (updateDate == null) { + if (publishedDate != null) { + updateDate = publishedDate; + } else { + //For misbehaving feeds that do not set updateDate or publishedDate we use current tiem which pretty mucg assures that it will be viewed as changed even when it is not + updateDate = new Date(); + } + } + String key = id + ":" + entry.getUpdatedDate(); + return computeDigest(key); + } + + private String computeDigest(String content) { + try { + MessageDigest md = MessageDigest.getInstance("SHA"); + byte[] digest = md.digest(content.getBytes()); + BigInteger bi = new BigInteger(digest); + return bi.toString(16); + } catch (Exception e) { + return ""; + } + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/Hub.java b/src/main/java/org/rometools/certiorem/hub/Hub.java new file mode 100644 index 0000000..480359b --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/Hub.java @@ -0,0 +1,257 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub; + +import com.sun.syndication.feed.synd.SyndFeed; + +import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; +import org.rometools.certiorem.hub.Verifier.VerificationCallback; +import org.rometools.certiorem.hub.data.HubDAO; +import org.rometools.certiorem.hub.data.Subscriber; +import org.rometools.certiorem.hub.data.SubscriptionSummary; + +import org.rometools.fetcher.FeedFetcher; + +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * The basic business logic controller for the Hub implementation. It is intended + * to be usable under a very thin servlet wrapper, or other, non-HTTP notification + * methods you might want to use. + * + * @author robert.cooper + */ +public class Hub { + private static final HashSet STANDARD_SCHEMES = new HashSet(); + + static { + STANDARD_SCHEMES.add("http"); + STANDARD_SCHEMES.add("https"); + } + + private final FeedFetcher fetcher; + private final HubDAO dao; + private final Notifier notifier; + private final Set validPorts; + private final Set validSchemes; + private final Set validTopics; + private final Verifier verifier; + + /** + * Constructs a new Hub instance + * @param dao The persistence HubDAO to use + * @param verifier The verification strategy to use. + */ + public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher) { + this.dao = dao; + this.verifier = verifier; + this.notifier = notifier; + this.fetcher = fetcher; + this.validSchemes = STANDARD_SCHEMES; + this.validPorts = Collections.EMPTY_SET; + this.validTopics = Collections.EMPTY_SET; + } + + /** + * Constructs a new Hub instance. + * @param dao The persistence HubDAO to use + * @param verifier The verification strategy to use + * @param validSchemes A list of valid URI schemes for callbacks (default: http, https) + * @param validPorts A list of valid port numbers for callbacks (default: any) + * @param validTopics A set of valid topic URIs which can be subscribed to (default: any) + */ + public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher, + final Set validSchemes, final Set validPorts, final Set validTopics) { + this.dao = dao; + this.verifier = verifier; + this.notifier = notifier; + this.fetcher = fetcher; + + Set readOnlySchemes = Collections.unmodifiableSet(validSchemes); + this.validSchemes = (readOnlySchemes == null) ? STANDARD_SCHEMES : readOnlySchemes; + + Set readOnlyPorts = Collections.unmodifiableSet(validPorts); + this.validPorts = (readOnlyPorts == null) ? Collections.EMPTY_SET : readOnlyPorts; + + Set readOnlyTopics = Collections.unmodifiableSet(validTopics); + this.validTopics = (readOnlyTopics == null) ? Collections.EMPTY_SET : readOnlyTopics; + } + + /** + * Sends a notification to the subscribers + * @param requestHost the host name the hub is running on. (Used for the user agent) + * @param topic the URL of the topic that was updated. + * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the request. + */ + public void sendNotification(String requestHost, final String topic) { + assert this.validTopics.isEmpty() || this.validTopics.contains(topic) : "That topic is not supported by this hub. " + + topic; + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Sending notification for {0}", topic); + try { + List subscribers = dao.subscribersForTopic(topic); + + if (subscribers.isEmpty()) { + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "No subscribers to notify for {0}", topic); + return; + } + + List summaries = (List) dao.summariesForTopic(topic); + int total = 0; + StringBuilder hosts = new StringBuilder(); + + for (SubscriptionSummary s : summaries) { + if (s.getSubscribers() > 0) { + total += s.getSubscribers(); + hosts.append(" (") + .append(s.getHost()) + .append("; ") + .append(s.getSubscribers()) + .append(" subscribers)"); + } + } + + StringBuilder userAgent = new StringBuilder("ROME-Certiorem (+http://").append(requestHost) + .append("; ") + .append(total) + .append(" subscribers)") + .append(hosts); + SyndFeed feed = fetcher.retrieveFeed(userAgent.toString(), new URL(topic)); + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Got feed for {0} Sending to {1} subscribers.", new Object[]{topic, subscribers.size()}); + this.notifier.notifySubscribers((List) subscribers, feed, + new SubscriptionSummaryCallback() { + @Override + public void onSummaryInfo(SubscriptionSummary summary) { + dao.handleSummary(topic, summary); + } + }); + } catch (Exception ex) { + Logger.getLogger(Hub.class.getName()) + .log(Level.SEVERE, "Exception getting " + topic, ex); + throw new HttpStatusCodeException(500, ex.getMessage(), ex); + } + } + + /** + * Subscribes to a topic. + * @param callback Callback URI + * @param topic Topic URI + * @param verify Verification Type + * @param lease_seconds Duration of the lease + * @param secret Secret value + * @param verify_token verify_token; + * @return Boolean.TRUE if the subscription succeeded synchronously, + * Boolean.FALSE if the subscription failed synchronously, or null if the request is asynchronous. + * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the request. + */ + public Boolean subscribe(String callback, String topic, String verify, long lease_seconds, String secret, + String verify_token) { + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "{0} wants to subscribe to {1}", new Object[]{callback, topic}); + try { + try { + assert callback != null : "Callback URL is required."; + assert topic != null : "Topic URL is required."; + + URI uri = new URI(callback); + assert this.validSchemes.contains(uri.getScheme()) : "Not a valid protocol " + uri.getScheme(); + assert this.validPorts.isEmpty() || this.validPorts.contains(uri.getPort()) : "Not a valid port " + + uri.getPort(); + assert this.validTopics.isEmpty() || this.validTopics.contains(topic) : "Not a supported topic " + + topic; + } catch (URISyntaxException ex) { + assert false : "Not a valid URI " + callback; + } + assert (verify != null) && + (verify.equals(Subscriber.VERIFY_ASYNC) || verify.equals(Subscriber.VERIFY_SYNC)) : "Unexpected verify value " + + verify; + + final Subscriber subscriber = new Subscriber(); + subscriber.setCallback(callback); + subscriber.setLeaseSeconds(lease_seconds); + subscriber.setSecret(secret); + subscriber.setTopic(topic); + subscriber.setVerify(verify); + subscriber.setVertifyToken(verify_token); + + VerificationCallback verified = new VerificationCallback() { + @Override + public void onVerify(boolean verified) { + if (verified) { + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Verified {0} subscribed to {1}", new Object[]{subscriber.getCallback(), subscriber.getTopic()}); + dao.addSubscriber(subscriber); + } + } + }; + + if (Subscriber.VERIFY_SYNC.equals(subscriber.getVerify())) { + boolean result = verifier.verifySubcribeSyncronously(subscriber); + verified.onVerify(result); + + return result; + } else { + verifier.verifySubscribeAsyncronously(subscriber, verified); + + return null; + } + } catch (AssertionError ae) { + throw new HttpStatusCodeException(400, ae.getMessage(), ae); + } catch (Exception e) { + throw new HttpStatusCodeException(500, e.getMessage(), e); + } + } + + public Boolean unsubscribe(final String callback, final String topic, String verify, String secret, String verifyToken) { + final Subscriber subscriber = dao.findSubscriber(topic, callback); + if(subscriber == null){ + throw new HttpStatusCodeException(400, "Not a valid subscription.", null); + } + subscriber.setVertifyToken(verifyToken); + subscriber.setSecret(secret); + if(Subscriber.VERIFY_SYNC.equals(verify)){ + + boolean ret = verifier.verifyUnsubcribeSyncronously(subscriber); + if(ret){ + dao.removeSubscriber(topic, callback); + } + } else { + verifier.verifyUnsubscribeAsyncronously(subscriber, new VerificationCallback(){ + + @Override + public void onVerify(boolean verified) { + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Unsubscribe for {0} at {1} verified {2}", new Object[]{subscriber.getTopic(), subscriber.getCallback(), verified}); + if(verified){ + dao.removeSubscriber(topic, callback); + } + } + + }); + } + return null; + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/Notifier.java b/src/main/java/org/rometools/certiorem/hub/Notifier.java new file mode 100644 index 0000000..cebd93f --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/Notifier.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub; + +import com.sun.syndication.feed.synd.SyndFeed; + +import org.rometools.certiorem.hub.data.Subscriber; +import org.rometools.certiorem.hub.data.SubscriptionSummary; + +import java.util.List; + + +/** + * + * @author robert.cooper + */ +public interface Notifier { + /** + * Instructs the notifier to begin sending notifications to the list of subscribers + * + * @param subscribers Subscribers to notify + * @param value The SyndFeed to send them + * @param callback A callback that is invoked each time a subscriber is notified. + */ + public void notifySubscribers(List subscribers, SyndFeed value, SubscriptionSummaryCallback callback); + + /** + * A callback that is invoked each time a subscriber is notified. + */ + public static interface SubscriptionSummaryCallback { + /** + * + * @param summary A summary of the data received from the subscriber + */ + public void onSummaryInfo(SubscriptionSummary summary); + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/Verifier.java b/src/main/java/org/rometools/certiorem/hub/Verifier.java new file mode 100644 index 0000000..ddc15ed --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/Verifier.java @@ -0,0 +1,78 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub; + +import org.rometools.certiorem.hub.data.Subscriber; + + +/** + * A strategy interface for verification of subscriptions. + * @author robert.cooper + */ +public interface Verifier { + + /** + * Value for hub.mode = subscribe + */ + public static final String MODE_SUBSCRIBE = "subscribe"; + /** + * Value for hub.mode = unsubscribe + */ + public static final String MODE_UNSUBSCRIBE = "unsubscribe"; + + /** + * Verifies a subscriber (possibly) asyncronously + * @param subscriber the Subscriber to verify + * @param callback a callback with the result of the verification. + */ + public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback); + + /** + * Verifies a subscriber syncronously + * @param subscriber The subscriber data + * @return boolean result; + */ + public boolean verifySubcribeSyncronously(Subscriber subscriber); + + /** + * Verifies am unsubscribe (possibly) asyncronously + * @param subscriber The subscriber data + * @param callback result + */ + public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback); + + /** + * Verifies an unsubscribe syncronously + * @param subscriber The subscriber data + * @return boolean result; + */ + public boolean verifyUnsubcribeSyncronously(Subscriber subscriber); + + + /** + * An interface for capturing the result of a verification (subscribe or unsubscribe) + */ + public static interface VerificationCallback { + /** + * + * @param verified success state of the verification + */ + public void onVerify(boolean verified); + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java b/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java new file mode 100644 index 0000000..95c255f --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java @@ -0,0 +1,42 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.data; + +import java.util.List; + +/** + * + * @author robert.cooper + */ +public interface HubDAO { + + public List subscribersForTopic(String topic); + + public Subscriber addSubscriber(Subscriber subscriber); + + public Subscriber findSubscriber(String topic, String callbackUrl); + + public void removeSubscriber(String topic, String callback); + + public void handleSummary(String topic, SubscriptionSummary summary); + + public List summariesForTopic(String topic); + +} diff --git a/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java b/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java new file mode 100644 index 0000000..fb3e4a3 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java @@ -0,0 +1,221 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.data; + +import java.io.Serializable; + + +/** + * + * @author robert.cooper + */ +public class Subscriber implements Serializable { + public static final String VERIFY_SYNC = "sync"; + public static final String VERIFY_ASYNC = "async"; + private String callback; + private String secret; + private String topic; + private String verify; + private String vertifyToken; + private long creationTime = System.currentTimeMillis(); + private long leaseSeconds; + + /** + * Set the value of callback + * + * @param newcallback new value of callback + */ + public void setCallback(String newcallback) { + this.callback = newcallback; + } + + /** + * Get the value of callback + * + * @return the value of callback + */ + public String getCallback() { + return this.callback; + } + + /** + * Set the value of creationTime + * + * @param newcreationTime new value of creationTime + */ + public void setCreationTime(long newcreationTime) { + this.creationTime = newcreationTime; + } + + /** + * Get the value of creationTime + * + * @return the value of creationTime + */ + public long getCreationTime() { + return this.creationTime; + } + + /** + * Set the value of leaseSeconds + * + * @param newleaseSeconds new value of leaseSeconds + */ + public void setLeaseSeconds(long newleaseSeconds) { + this.leaseSeconds = newleaseSeconds; + } + + /** + * Get the value of leaseSeconds + * + * @return the value of leaseSeconds + */ + public long getLeaseSeconds() { + return this.leaseSeconds; + } + + /** + * Set the value of secret + * + * @param newsecret new value of secret + */ + public void setSecret(String newsecret) { + this.secret = newsecret; + } + + /** + * Get the value of secret + * + * @return the value of secret + */ + public String getSecret() { + return this.secret; + } + + /** + * Set the value of topic + * + * @param newtopic new value of topic + */ + public void setTopic(String newtopic) { + this.topic = newtopic; + } + + /** + * Get the value of topic + * + * @return the value of topic + */ + public String getTopic() { + return this.topic; + } + + /** + * Set the value of verify + * + * @param newverify new value of verify + */ + public void setVerify(String newverify) { + this.verify = newverify; + } + + /** + * Get the value of verify + * + * @return the value of verify + */ + public String getVerify() { + return this.verify; + } + + /** + * Set the value of vertifyToken + * + * @param newvertifyToken new value of vertifyToken + */ + public void setVertifyToken(String newvertifyToken) { + this.vertifyToken = newvertifyToken; + } + + /** + * Get the value of vertifyToken + * + * @return the value of vertifyToken + */ + public String getVertifyToken() { + return this.vertifyToken; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (!(obj instanceof Subscriber)) { + return false; + } + + final Subscriber other = (Subscriber) obj; + + if ((this.callback == null) ? (other.callback != null) : (!this.callback.equals(other.callback))) { + return false; + } + + if ((this.secret == null) ? (other.secret != null) : (!this.secret.equals(other.secret))) { + return false; + } + + if ((this.topic == null) ? (other.topic != null) : (!this.topic.equals(other.topic))) { + return false; + } + + if ((this.verify == null) ? (other.verify != null) : (!this.verify.equals(other.verify))) { + return false; + } + + if ((this.vertifyToken == null) ? (other.vertifyToken != null) : (!this.vertifyToken.equals(other.vertifyToken))) { + return false; + } + + if (this.creationTime != other.creationTime) { + return false; + } + + if (this.leaseSeconds != other.leaseSeconds) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = (67 * hash) + ((this.callback != null) ? this.callback.hashCode() : 0); + hash = (67 * hash) + ((this.secret != null) ? this.secret.hashCode() : 0); + hash = (67 * hash) + ((this.topic != null) ? this.topic.hashCode() : 0); + hash = (67 * hash) + ((this.verify != null) ? this.verify.hashCode() : 0); + hash = (67 * hash) + ((this.vertifyToken != null) ? this.vertifyToken.hashCode() : 0); + hash = (67 * hash) + (int) (this.creationTime ^ (this.creationTime >>> 32)); + hash = (67 * hash) + (int) (this.leaseSeconds ^ (this.leaseSeconds >>> 32)); + + return hash; + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java b/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java new file mode 100644 index 0000000..c826f40 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java @@ -0,0 +1,86 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.data; + +import java.io.Serializable; + + +/** + * + * @author robert.cooper + */ +public class SubscriptionSummary implements Serializable { + private String host; + private boolean lastPublishSuccessful = true; + private int subscribers = 0; + + /** + * Set the value of host + * + * @param newhost new value of host + */ + public void setHost(String newhost) { + this.host = newhost; + } + + /** + * Get the value of host + * + * @return the value of host + */ + public String getHost() { + return this.host; + } + + /** + * Set the value of lastPublishSuccessful + * + * @param newlastPublishSuccessful new value of lastPublishSuccessful + */ + public void setLastPublishSuccessful(boolean newlastPublishSuccessful) { + this.lastPublishSuccessful = newlastPublishSuccessful; + } + + /** + * Get the value of lastPublishSuccessful + * + * @return the value of lastPublishSuccessful + */ + public boolean isLastPublishSuccessful() { + return this.lastPublishSuccessful; + } + + /** + * Set the value of subscribers + * + * @param newsubscribers new value of subscribers + */ + public void setSubscribers(int newsubscribers) { + this.subscribers = newsubscribers; + } + + /** + * Get the value of subscribers + * + * @return the value of subscribers + */ + public int getSubscribers() { + return this.subscribers; + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java new file mode 100644 index 0000000..c33eca3 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java @@ -0,0 +1,131 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.data.jpa; + +import org.rometools.certiorem.hub.data.HubDAO; +import org.rometools.certiorem.hub.data.Subscriber; + +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.rometools.certiorem.hub.data.SubscriptionSummary; + +/** + * + * @author robert.cooper + */ +public class JPADAO implements HubDAO { + + private final EntityManagerFactory factory; + private final boolean purgeExpired; + + public JPADAO(final EntityManagerFactory factory, final boolean purgeExpired) { + this.factory = factory; + this.purgeExpired = purgeExpired; + } + + @Override + public List subscribersForTopic(String topic) { + LinkedList result = new LinkedList(); + EntityManager em = factory.createEntityManager(); + EntityTransaction tx = em.getTransaction(); + tx.begin(); + + Query query = em.createNamedQuery("Subcriber.forTopic"); + query.setParameter("topic", topic); + + try { + for (JPASubscriber subscriber : (List) query.getResultList()) { + if (subscriber.getLeaseSeconds() == -1) { + result.add(subscriber); + continue; + } + + if (subscriber.getSubscribedAt().getTime() < (System.currentTimeMillis() - (1000 * subscriber.getLeaseSeconds()))) { + subscriber.setExpired(true); + } else { + result.add(subscriber); + } + + if (subscriber.isExpired() && this.purgeExpired) { + em.remove(subscriber); + } + } + } catch (NoResultException e) { + tx.rollback(); + em.close(); + + return result; + } + + + + if (!tx.getRollbackOnly()) { + tx.commit(); + } else { + tx.rollback(); + } + + em.close(); + + return result; + } + + @Override + public Subscriber addSubscriber(Subscriber subscriber) { + assert subscriber != null : "Attempt to store a null subscriber"; + EntityManager em = factory.createEntityManager(); + EntityTransaction tx = em.getTransaction(); + tx.begin(); + JPASubscriber data = new JPASubscriber(); + data.copyFrom(subscriber); + data.setId(UUID.randomUUID().toString()); + em.persist(data); + tx.commit(); + em.close(); + return data; + } + + @Override + public Subscriber findSubscriber(String topic, String callbackUrl) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void handleSummary(String topic, SubscriptionSummary summary) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public List summariesForTopic(String topic) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removeSubscriber(String topic, String callback) { + throw new UnsupportedOperationException("Not supported yet."); + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java new file mode 100644 index 0000000..5980f48 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java @@ -0,0 +1,111 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.data.jpa; + +import org.rometools.certiorem.hub.data.Subscriber; + +import java.io.Serializable; + +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + + +/** + * + * @author robert.cooper + */ +@Entity +@NamedQueries({@NamedQuery(name = "Subcriber.forTopic", query = "SELECT o FROM JPASubscriber o WHERE o.topic = :topic AND o.expired = false ORDER BY o.subscribedAt") +}) +public class JPASubscriber extends Subscriber implements Serializable { + private Date subscribedAt = new Date(); + private String id; + private boolean expired = false; + + /** + * Set the value of expired + * + * @param newexpired new value of expired + */ + public void setExpired(boolean newexpired) { + this.expired = newexpired; + } + + /** + * Get the value of expired + * + * @return the value of expired + */ + public boolean isExpired() { + return this.expired; + } + + /** + * Set the value of id + * + * @param newid new value of id + */ + public void setId(String newid) { + this.id = newid; + } + + /** + * Get the value of id + * + * @return the value of id + */ + @Id + public String getId() { + return this.id; + } + + /** + * Set the value of subscribedAt + * + * @param newsubscribedAt new value of subscribedAt + */ + public void setSubscribedAt(Date newsubscribedAt) { + this.subscribedAt = newsubscribedAt; + } + + /** + * Get the value of subscribedAt + * + * @return the value of subscribedAt + */ + @Temporal(TemporalType.TIMESTAMP) + public Date getSubscribedAt() { + return this.subscribedAt; + } + + public void copyFrom(Subscriber source) { + this.setLeaseSeconds(source.getLeaseSeconds()); + this.setSecret(source.getSecret()); + this.setTopic(source.getTopic()); + this.setVerify(source.getVerify()); + this.setVertifyToken(source.getVertifyToken()); + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/package.html b/src/main/java/org/rometools/certiorem/hub/data/jpa/package.html new file mode 100644 index 0000000..64caa18 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/jpa/package.html @@ -0,0 +1,28 @@ + + + + + jpa + + + A stock data implementation based on the Java Persistence API. + + \ No newline at end of file diff --git a/src/main/java/org/rometools/certiorem/hub/data/package.html b/src/main/java/org/rometools/certiorem/hub/data/package.html new file mode 100644 index 0000000..753d66e --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/package.html @@ -0,0 +1,29 @@ + + + + + data + + + This package defines the basic data types and persistence mechanisms + that are required for a hub implementation. + + \ No newline at end of file diff --git a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java b/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java new file mode 100644 index 0000000..a7f484d --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java @@ -0,0 +1,138 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.data.ram; + +import org.rometools.certiorem.hub.data.HubDAO; +import org.rometools.certiorem.hub.data.Subscriber; +import org.rometools.certiorem.hub.data.SubscriptionSummary; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + + +/** + * A Simple In-Memory HubDAO for subscribers. + * + * @author robert.cooper + */ +public class InMemoryHubDAO implements HubDAO { + private ConcurrentHashMap> subscribers = new ConcurrentHashMap>(); + private ConcurrentHashMap> summaries = new ConcurrentHashMap>(); + + @Override + public Subscriber addSubscriber(Subscriber subscriber) { + assert subscriber != null : "Attempt to store a null subscriber"; + + List subList = this.subscribers.get(subscriber.getTopic()); + + if (subList == null) { + synchronized (this) { + subList = new CopyOnWriteArrayList(); + this.subscribers.put(subscriber.getTopic(), subList); + } + } + + subList.add(subscriber); + + return subscriber; + } + + @Override + public void handleSummary(String topic, SubscriptionSummary summary) { + ConcurrentHashMap hostsToSummaries = this.summaries.get(topic); + + if (hostsToSummaries == null) { + synchronized (this) { + hostsToSummaries = new ConcurrentHashMap(); + this.summaries.put(topic, hostsToSummaries); + } + } + + hostsToSummaries.put(summary.getHost(), summary); + } + + @Override + public List subscribersForTopic(String topic) { + if (subscribers.containsKey(topic)) { + List result = new LinkedList(); + LinkedList expired = new LinkedList(); + + for (Subscriber s : subscribers.get(topic)) { + if ((s.getLeaseSeconds() > 0) && + (System.currentTimeMillis() >= (s.getCreationTime() + (s.getLeaseSeconds() * 1000L)))) { + expired.add(s); + } else { + result.add(s); + } + } + + if (!expired.isEmpty()) { + subscribers.get(topic) + .removeAll(expired); + } + + return result; + } else { + return Collections.EMPTY_LIST; + } + } + + @Override + public List summariesForTopic(String topic) { + LinkedList result = new LinkedList(); + + if (this.summaries.containsKey(topic)) { + result.addAll(this.summaries.get(topic).values()); + } + + return result; + } + + @Override + public Subscriber findSubscriber(String topic, String callbackUrl) { + + for (Subscriber s : this.subscribersForTopic(topic)) { + if (callbackUrl.equals(s.getCallback())) { + return s; + } + } + return null; + } + + @Override + public void removeSubscriber(String topic, String callback) { + List subs = this.subscribers.get(topic); + if(subs == null){ + return; + } + Subscriber match = null; + for(Subscriber s: subs){ + if(s.getCallback().equals(callback)){ + match = s; + break; + } + } + if(match != null){ + subs.remove(match); + } + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/data/ram/package.html b/src/main/java/org/rometools/certiorem/hub/data/ram/package.html new file mode 100644 index 0000000..daecce8 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/data/ram/package.html @@ -0,0 +1,25 @@ + + + + Contains a Memory-Resident implemtnation of the Hub DAO. + + + diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java new file mode 100644 index 0000000..193063c --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java @@ -0,0 +1,170 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.notify.standard; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; + +import org.rometools.certiorem.hub.Notifier; +import org.rometools.certiorem.hub.data.Subscriber; +import org.rometools.certiorem.hub.data.SubscriptionSummary; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.rometools.certiorem.sub.data.ram.InMemorySubDAO; + + +/** + * + * @author robert.cooper + */ +public abstract class AbstractNotifier implements Notifier { + /** + * This method will serialize the synd feed and build Notifications for the + * implementation class to handle. + * @see enqueueNotification + * + * @param subscribers List of subscribers to notify + * @param value The SyndFeed object to send + * @param callback A callback that will be invoked each time a subscriber is notified. + * + */ + @Override + public void notifySubscribers(List subscribers, SyndFeed value, SubscriptionSummaryCallback callback) { + String mimeType = null; + + if (value.getFeedType() + .startsWith("rss")) { + mimeType = "application/rss+xml"; + } else { + mimeType = "application/atom+xml"; + } + + SyndFeedOutput output = new SyndFeedOutput(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + try { + output.output(value, new OutputStreamWriter(baos)); + baos.close(); + } catch (IOException ex) { + Logger.getLogger(AbstractNotifier.class.getName()) + .log(Level.SEVERE, null, ex); + throw new RuntimeException("Unable to output the feed.", ex); + } catch (FeedException ex) { + Logger.getLogger(AbstractNotifier.class.getName()) + .log(Level.SEVERE, null, ex); + throw new RuntimeException("Unable to output the feed.", ex); + } + + byte[] payload = baos.toByteArray(); + + for (Subscriber s : subscribers) { + Notification not = new Notification(); + not.callback = callback; + not.lastRun = 0; + not.mimeType = mimeType; + not.payload = payload; + not.retryCount = 0; + not.subscriber = s; + this.enqueueNotification(not); + } + } + /** Implementation method that queues/sends a notification + * + * @param not notification to send. + */ + protected abstract void enqueueNotification(Notification not); + + /** + * POSTs the payload to the subscriber's callback and returns a + * SubscriptionSummary with subscriber counts (where possible) and the + * success state of the notification. + * @param subscriber subscriber data. + * @param mimeType MIME type for the request + * @param payload payload of the feed to send + * @return SubscriptionSummary with the returned data. + */ + protected SubscriptionSummary postNotification(Subscriber subscriber, String mimeType, byte[] payload) { + SubscriptionSummary result = new SubscriptionSummary(); + + try { + URL target = new URL(subscriber.getCallback()); + Logger.getLogger(AbstractNotifier.class.getName()).log(Level.INFO, "Posting notification to subscriber {0}", subscriber.getCallback()); + result.setHost(target.getHost()); + + HttpURLConnection connection = (HttpURLConnection) target.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", mimeType); + connection.setDoOutput(true); + connection.connect(); + + OutputStream os = connection.getOutputStream(); + os.write(payload); + os.close(); + + int responseCode = connection.getResponseCode(); + String subscribers = connection.getHeaderField("X-Hub-On-Behalf-Of"); + connection.disconnect(); + + if (responseCode != 200) { + Logger.getLogger(AbstractNotifier.class.getName()) + .log(Level.WARNING, "Got code " + responseCode + " from " + target); + result.setLastPublishSuccessful(false); + + return result; + } + + + + if (subscribers != null) { + try { + result.setSubscribers(Integer.parseInt(subscribers)); + } catch (NumberFormatException nfe) { + Logger.getLogger(AbstractNotifier.class.getName()) + .log(Level.WARNING, "Invalid subscriber value " + subscribers + " " + target, nfe); + result.setSubscribers(-1); + } + } else { + result.setSubscribers(-1); + } + } catch (MalformedURLException ex) { + Logger.getLogger(AbstractNotifier.class.getName()) + .log(Level.WARNING, null, ex); + result.setLastPublishSuccessful(false); + } catch (IOException ex) { + Logger.getLogger(AbstractNotifier.class.getName()) + .log(Level.SEVERE, null, ex); + result.setLastPublishSuccessful(false); + } + + return result; + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java new file mode 100644 index 0000000..470956b --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java @@ -0,0 +1,38 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.notify.standard; + +import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; +import org.rometools.certiorem.hub.data.Subscriber; + +/** + * + * @author robert.cooper + */ +public class Notification { + + int retryCount = 0; + long lastRun = 0; + Subscriber subscriber; + String mimeType; + byte[] payload; + SubscriptionSummaryCallback callback; + +} diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java new file mode 100644 index 0000000..7f1c724 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java @@ -0,0 +1,114 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.notify.standard; + +import org.rometools.certiorem.hub.data.SubscriptionSummary; + +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + + +/** + * A notifier implementation that uses a thread pool to deliver notifications to + * subscribers + * + * @author robert.cooper + */ +public class ThreadPoolNotifier extends AbstractNotifier { + private static final long TWO_MINUTES = 2 * 60 * 1000; + protected final ThreadPoolExecutor exeuctor; + private final Timer timer = new Timer(); + private final ConcurrentSkipListSet pendings = new ConcurrentSkipListSet(); + + public ThreadPoolNotifier() { + this(2, 5, 5); + } + + public ThreadPoolNotifier(int startPoolSize, int maxPoolSize, int queueSize) { + this.exeuctor = new ThreadPoolExecutor(startPoolSize, maxPoolSize, 300, TimeUnit.SECONDS, + new LinkedBlockingQueue(queueSize)); + } + + protected ThreadPoolNotifier(final ThreadPoolExecutor executor) { + this.exeuctor = executor; + } + + /** + * Enqueues a notification to run. If the notification fails, it will be + * retried every two minutes until 5 attempts are completed. Notifications + * to the same callback should be delivered successfully in order. + * @param not + */ + @Override + protected void enqueueNotification(final Notification not) { + Runnable r = new Runnable() { + @Override + public void run() { + not.lastRun = System.currentTimeMillis(); + + SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload); + + if (!summary.isLastPublishSuccessful()) { + not.retryCount++; + + if (not.retryCount <= 5) { + retry(not); + } + } + + not.callback.onSummaryInfo(summary); + } + }; + + this.exeuctor.execute(r); + } + + /** + * Schedules a notification to retry in two minutes. + * @param not Notification to retry + */ + protected void retry(final Notification not) { + if (!pendings.contains(not.subscriber.getCallback())) { + // We don't have a current retry for this callback pending, so we + // will schedule the retry + pendings.add(not.subscriber.getCallback()); + timer.schedule(new TimerTask() { + @Override + public void run() { + pendings.remove(not.subscriber.getCallback()); + enqueueNotification(not); + } + }, TWO_MINUTES); + } else { + // There is a retry in front of this one, so we will just schedule + // it to retry again in a bit + timer.schedule(new TimerTask() { + @Override + public void run() { + retry(not); + } + }, TWO_MINUTES); + } + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java new file mode 100644 index 0000000..df5a19b --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java @@ -0,0 +1,49 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.notify.standard; + +import org.rometools.certiorem.hub.data.SubscriptionSummary; + +import java.util.concurrent.ConcurrentSkipListSet; + + +/** + * A notifier that does not use threads. All calls are blocking and synchronous. + * + * @author robert.cooper + */ +public class UnthreadedNotifier extends AbstractNotifier { + private final ConcurrentSkipListSet retries = new ConcurrentSkipListSet(); + + /** + * A blocking call that performs a notification. + * If there are pending retries that are older than two minutes old, they will + * be retried before the method returns. + * + * @param not + */ + @Override + protected void enqueueNotification(Notification not) { + not.lastRun = System.currentTimeMillis(); + + SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload); + + not.callback.onSummaryInfo(summary); + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/package.html b/src/main/java/org/rometools/certiorem/hub/notify/standard/package.html new file mode 100644 index 0000000..19b986f --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/package.html @@ -0,0 +1,32 @@ + + + + + verify + + + This package contains a set of standard Verifier implementations. +

+ These implementations all use the standard java.net.* classes for + making requests to URLs. +

+ + \ No newline at end of file diff --git a/src/main/java/org/rometools/certiorem/hub/package.html b/src/main/java/org/rometools/certiorem/hub/package.html new file mode 100644 index 0000000..70dbeb7 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/package.html @@ -0,0 +1,30 @@ + + + + + hub + + + This package contains the core of the Hub implementation. +

Getting Started

+

The Hub implementation

+ + \ No newline at end of file diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java new file mode 100644 index 0000000..6a8c9a1 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java @@ -0,0 +1,108 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.verify.standard; + +import org.rometools.certiorem.hub.Verifier; +import org.rometools.certiorem.hub.data.Subscriber; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; + +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; + +import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * An abstract verifier based on the java.net HTTP classes. This implements only + * synchronous operations, and expects a child class to do Async ops. + * + * @author robert.cooper + */ +public abstract class AbstractVerifier implements Verifier { + @Override + public boolean verifySubcribeSyncronously(Subscriber subscriber) { + return doOp(Verifier.MODE_SUBSCRIBE, subscriber); + } + + @Override + public boolean verifyUnsubcribeSyncronously(Subscriber subscriber) { + return doOp(Verifier.MODE_UNSUBSCRIBE, subscriber); + } + + private boolean doOp(String mode, Subscriber subscriber){ + try { + String challenge = UUID.randomUUID() + .toString(); + StringBuilder queryString = new StringBuilder(); + queryString.append("hub.mode=") + .append(mode) + .append("&hub.topic=") + .append(URLEncoder.encode(subscriber.getTopic(), "UTF-8")) + .append("&hub.challenge=") + .append(challenge); + + if (subscriber.getLeaseSeconds() != -1) { + queryString.append("&hub.lease_seconds=") + .append(subscriber.getLeaseSeconds()); + } + + if (subscriber.getVertifyToken() != null) { + queryString.append("&hub.verify_token=") + .append(URLEncoder.encode(subscriber.getVertifyToken(), "UTF-8")); + } + + URL url = new URL(subscriber.getCallback() + "?" + queryString.toString()); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); +// connection.setRequestProperty("Host", url.getHost()); +// connection.setRequestProperty("Port", Integer.toString(url.getPort())); + connection.setRequestProperty("User-Agent", "ROME-Certiorem"); + connection.connect(); + int rc = connection.getResponseCode(); + InputStream is = connection.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + String result = reader.readLine(); + reader.close(); + connection.disconnect(); + if ((rc != 200) || !challenge.equals(result.trim())) { + return false; + } else { + return true; + } + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(AbstractVerifier.class.getName()) + .log(Level.SEVERE, null, ex); + throw new RuntimeException("Should not happen. UTF-8 threw unsupported encoding", ex); + } catch (IOException ex) { + Logger.getLogger(AbstractVerifier.class.getName()) + .log(Level.SEVERE, null, ex); + + return false; + } + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java new file mode 100644 index 0000000..8bd864c --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java @@ -0,0 +1,68 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.verify.standard; + +import org.rometools.certiorem.hub.data.Subscriber; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + + +/** + * Uses a ThreadPoolExecutor to do async verifications. + * @author robert.cooper + */ +public class ThreadPoolVerifier extends AbstractVerifier { + protected final ThreadPoolExecutor exeuctor; + + protected ThreadPoolVerifier(final ThreadPoolExecutor executor){ + this.exeuctor = executor; + } + + public ThreadPoolVerifier() { + this(2, 5, 5); + } + + public ThreadPoolVerifier(int startPoolSize, int maxPoolSize, int queueSize) { + this.exeuctor = new ThreadPoolExecutor(startPoolSize, maxPoolSize, 300, TimeUnit.SECONDS, + new LinkedBlockingQueue(queueSize)); + } + + @Override + public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { + this.exeuctor.execute(new Runnable() { + @Override + public void run() { + callback.onVerify(verifySubcribeSyncronously(subscriber)); + } + }); + } + + @Override + public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { + this.exeuctor.execute(new Runnable() { + @Override + public void run() { + callback.onVerify(verifyUnsubcribeSyncronously(subscriber)); + } + }); + } +} diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java new file mode 100644 index 0000000..a8cd755 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java @@ -0,0 +1,33 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.verify.standard; + +import java.util.concurrent.ThreadPoolExecutor; + +/** + * + * @author robert.cooper + */ +public class ThreadpoolVerifierAdvanced extends ThreadPoolVerifier{ + + public ThreadpoolVerifierAdvanced(ThreadPoolExecutor executor){ + super(executor); + } + +} diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java new file mode 100644 index 0000000..d0859ee --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java @@ -0,0 +1,41 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.verify.standard; + +import org.rometools.certiorem.hub.data.Subscriber; + +/** + * A verifier that does not use threads. Suitable for Google App Engine. + * @author robert.cooper + */ +public class UnthreadedVerifier extends AbstractVerifier{ + + @Override + public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + callback.onVerify(verifySubcribeSyncronously(subscriber)); + } + + @Override + public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + callback.onVerify(verifyUnsubcribeSyncronously(subscriber)); + } + +} diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/package.html b/src/main/java/org/rometools/certiorem/hub/verify/standard/package.html new file mode 100644 index 0000000..19b986f --- /dev/null +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/package.html @@ -0,0 +1,32 @@ + + + + + verify + + + This package contains a set of standard Verifier implementations. +

+ These implementations all use the standard java.net.* classes for + making requests to URLs. +

+ + \ No newline at end of file diff --git a/src/main/java/org/rometools/certiorem/package.html b/src/main/java/org/rometools/certiorem/package.html new file mode 100644 index 0000000..3da23c0 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/package.html @@ -0,0 +1,30 @@ + + + + + A pub sub hubub implementation for Java. + + + + + + + diff --git a/src/main/java/org/rometools/certiorem/pub/NotificationException.java b/src/main/java/org/rometools/certiorem/pub/NotificationException.java new file mode 100644 index 0000000..8075e5f --- /dev/null +++ b/src/main/java/org/rometools/certiorem/pub/NotificationException.java @@ -0,0 +1,36 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.pub; + +/** + * + * @author robert.cooper + */ +public class NotificationException extends Exception { + + public NotificationException(String message){ + super(message); + } + + public NotificationException(String message, Throwable cause){ + super(message, cause); + } + +} diff --git a/src/main/java/org/rometools/certiorem/pub/Publisher.java b/src/main/java/org/rometools/certiorem/pub/Publisher.java new file mode 100644 index 0000000..bc9f21a --- /dev/null +++ b/src/main/java/org/rometools/certiorem/pub/Publisher.java @@ -0,0 +1,248 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.pub; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndLink; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; + +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; + +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * A class for sending update notifications to a hub. + * @author robert.cooper + */ +public class Publisher { + private ThreadPoolExecutor executor; + + /** + * Constructs a new publisher. This publisher will spawn a new thread for each async send. + */ + public Publisher() { + } + + /** + * Constructs a new publisher with an optional ThreadPoolExector for sending updates. + */ + public Publisher(ThreadPoolExecutor executor) { + this.executor = executor; + } + + /** + * Sends the HUB url a notification of a change in topic + * @param hub URL of the hub to notify. + * @param topic The Topic that has changed + * @throws NotificationException Any failure + */ + public void sendUpdateNotification(String hub, String topic) + throws NotificationException { + try { + StringBuilder sb = new StringBuilder("hub.mode=publish&hub.url=").append(URLEncoder.encode(topic, "UTF-8")); + URL hubUrl = new URL(hub); + HttpURLConnection connection = (HttpURLConnection) hubUrl.openConnection(); +// connection.setRequestProperty("Host", hubUrl.getHost()); + connection.setRequestProperty("User-Agent", "ROME-Certiorem"); + connection.setRequestProperty("ContentType", "application/x-www-form-urlencoded"); + connection.setDoOutput(true); + connection.connect(); + + OutputStream os = connection.getOutputStream(); + os.write(sb.toString().getBytes("UTF-8")); + os.close(); + + int rc = connection.getResponseCode(); + connection.disconnect(); + + if (rc != 204) { + throw new NotificationException("Server returned an unexcepted response code: " + rc + " " + + connection.getResponseMessage()); + } + + + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(Publisher.class.getName()) + .log(Level.SEVERE, null, ex); + throw new NotificationException("Could not encode URL", ex); + } catch (IOException ex) { + Logger.getLogger(Publisher.class.getName()) + .log(Level.SEVERE, null, ex); + throw new NotificationException("Unable to communicate with " + hub, ex); + } + } + + /** + * Sends a notification for a feed located at "topic". The feed MUST contain rel="hub". + * @param topic URL for the feed + * @param feed The feed itself + * @throws NotificationException Any failure + */ + public void sendUpdateNotification(String topic, SyndFeed feed) + throws NotificationException { + for (SyndLink link : (List) feed.getLinks()) { + if ("hub".equals(link.getRel())) { + sendUpdateNotification(link.getRel(), topic); + + return; + } + } + throw new NotificationException("Hub link not found."); + } + + /** + * Sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links. + * @param feed The feed to notify + * @throws NotificationException Any failure + */ + public void sendUpdateNotification(SyndFeed feed) throws NotificationException { + SyndLink hub = null; + SyndLink self = null; + + for (SyndLink link : (List) feed.getLinks()) { + if ("hub".equals(link.getRel())) { + hub = link; + } + + if ("self".equals(link.getRel())) { + self = link; + } + + if ((hub != null) && (self != null)) { + break; + } + } + + if (hub == null) { + throw new NotificationException("A link rel='hub' was not found in the feed."); + } + + if (self == null) { + throw new NotificationException("A link rel='self' was not found in the feed."); + } + + sendUpdateNotification(hub.getRel(), self.getHref()); + } + + /** + * Sends the HUB url a notification of a change in topic asynchronously + * @param hub URL of the hub to notify. + * @param topic The Topic that has changed + * @param callback A callback invoked when the notification completes. + * @throws NotificationException Any failure + */ + public void sendUpdateNotificationAsyncronously(final String hub, final String topic, + final AsyncNotificationCallback callback) { + Runnable r = new Runnable() { + @Override + public void run() { + try { + sendUpdateNotification(hub, topic); + callback.onSuccess(); + } catch (Throwable t) { + callback.onFailure(t); + } + } + }; + + if (this.executor != null) { + this.executor.execute(r); + } else { + new Thread(r).start(); + } + } + + /** + * Asynchronously sends a notification for a feed located at "topic". The feed MUST contain rel="hub". + * @param topic URL for the feed + * @param feed The feed itself + * @param callback A callback invoked when the notification completes. + * @throws NotificationException Any failure + */ + public void sendUpdateNotificationAsyncronously(final String topic, final SyndFeed feed, + final AsyncNotificationCallback callback) { + Runnable r = new Runnable() { + @Override + public void run() { + try { + sendUpdateNotification(topic, feed); + callback.onSuccess(); + } catch (Throwable t) { + callback.onFailure(t); + } + } + }; + + if (this.executor != null) { + this.executor.execute(r); + } else { + new Thread(r).start(); + } + } + + /** + * Asyncronously sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links. + * @param feed The feed to notify + * @param callback A callback invoked when the notification completes. + * @throws NotificationException Any failure + */ + public void sendUpdateNotificationAsyncronously(final SyndFeed feed, final AsyncNotificationCallback callback) { + Runnable r = new Runnable() { + @Override + public void run() { + try { + sendUpdateNotification(feed); + callback.onSuccess(); + } catch (Throwable t) { + callback.onFailure(t); + } + } + }; + + if (this.executor != null) { + this.executor.execute(r); + } else { + new Thread(r).start(); + } + } + /** + * A callback interface for asynchronous notifications. + */ + public static interface AsyncNotificationCallback { + /** + * Called when a notification fails + * @param thrown Whatever was thrown during the failure + */ + public void onFailure(Throwable thrown); + /** + * Invoked with the asyncronous notification completes successfully. + */ + public void onSuccess(); + } +} diff --git a/src/main/java/org/rometools/certiorem/pub/package.html b/src/main/java/org/rometools/certiorem/pub/package.html new file mode 100644 index 0000000..9f56bb1 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/pub/package.html @@ -0,0 +1,29 @@ + + + + + pub + + + This package contains a utility class to send update notifications. + + + \ No newline at end of file diff --git a/src/main/java/org/rometools/certiorem/sub/Requester.java b/src/main/java/org/rometools/certiorem/sub/Requester.java new file mode 100644 index 0000000..72d9481 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/Requester.java @@ -0,0 +1,40 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.sub; + +import org.rometools.certiorem.sub.data.Subscription; + + +/** + * + * @author robert.cooper + */ +public interface Requester { + public void sendSubscribeRequest(String hubUrl, Subscription subscription, String verifySync, long leaseSeconds, + String secret, String callbackUrl, RequestCallback callback); + + public void sendUnsubscribeRequest(String hubUrl, Subscription subscription, String verifySync, String secret, + String callbackUrl, RequestCallback callback); + + public static interface RequestCallback { + public void onFailure(Exception e); + + public void onSuccess(); + } +} diff --git a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java new file mode 100644 index 0000000..32492d2 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java @@ -0,0 +1,298 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.sub; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndLink; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; + +import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.certiorem.sub.Requester.RequestCallback; +import org.rometools.certiorem.sub.data.SubDAO; +import org.rometools.certiorem.sub.data.Subscription; + +import org.rometools.fetcher.impl.FeedFetcherCache; +import org.rometools.fetcher.impl.SyndFeedInfo; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import java.util.List; +import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.rometools.certiorem.sub.data.SubscriptionCallback; + + +/** + * + * @author robert.cooper + */ +public class Subscriptions { + //TODO unsubscribe. + private FeedFetcherCache cache; + private Requester requester; + private String callbackPrefix; + private SubDAO dao; + + public Subscriptions() { + } + + public Subscriptions(final FeedFetcherCache cache, final Requester requester, final String callbackPrefix, + final SubDAO dao) { + this.cache = cache; + this.requester = requester; + this.callbackPrefix = callbackPrefix; + this.dao = dao; + } + + public void callback(String callbackPath, String feed) { + try { + this.callback(callbackPath, feed.getBytes("UTF-8")); + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(Subscriptions.class.getName()) + .log(Level.SEVERE, null, ex); + throw new HttpStatusCodeException(400, "Unable to parse feed.", ex); + } + } + + public void callback(String callbackPath, InputStream feed) { + SyndFeedInput input = new SyndFeedInput(); + + try { + this.callback(callbackPath, input.build(new InputStreamReader(feed))); + } catch (IllegalArgumentException ex) { + Logger.getLogger(Subscriptions.class.getName()) + .log(Level.SEVERE, null, ex); + throw new HttpStatusCodeException(500, "Unable to parse feed.", ex); + } catch (FeedException ex) { + Logger.getLogger(Subscriptions.class.getName()) + .log(Level.SEVERE, null, ex); + throw new HttpStatusCodeException(400, "Unable to parse feed.", ex); + } + } + + public void callback(String callbackPath, byte[] feed) { + this.callback(callbackPath, new ByteArrayInputStream(feed)); + } + + public void callback(String callbackPath, SyndFeed feed) { + + if (!callbackPath.startsWith(callbackPrefix)) { + throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath+" doesnt start with "+callbackPrefix)); + } + + String id = callbackPath.substring(callbackPrefix.length()); + Logger.getLogger(Subscriptions.class.getName()).log(Level.FINE, "Got callback for {0}", id); + Subscription s = dao.findById(id); + + if (s == null) { + throw new HttpStatusCodeException(404, "Not a valid callback.", null); + } + + this.validateLink(feed, s.getSourceUrl()); + + SyndFeedInfo info = null; + URL url = null; + + try { + url = new URL(s.getSourceUrl()); + info = cache.getFeedInfo(url); + } catch (MalformedURLException ex) { + Logger.getLogger(Subscriptions.class.getName()) + .log(Level.SEVERE, null, ex); + } + + if (info == null) { + info = new SyndFeedInfo(); + info.setId(s.getId()); + info.setUrl(url); + } + + info.setLastModified(System.currentTimeMillis()); + info.setSyndFeed(feed); + cache.setFeedInfo(url, info); + + s.getCallback().onNotify(s, info); + } + + public void unsubscribe(final Subscription subscription, String hubUrl, boolean sync, String secret, + final SubscriptionCallback callback) { + + subscription.setUnsubscribed(true); + this.requester.sendUnsubscribeRequest(hubUrl, subscription, (sync ? "sync" : "async"), secret, + this.callbackPrefix + subscription.getId(), + new RequestCallback() { + @Override + public void onSuccess() { + callback.onUnsubscribe(subscription); + } + + @Override + public void onFailure(Exception e) { + callback.onFailure(e); + } + }); + } + + public void subscribe(String hubUrl, String topic, boolean sync, long leaseSeconds, String secret, + final SubscriptionCallback callback) { + Subscription s = new Subscription(); + s.setId(UUID.randomUUID().toString()); + s.setVerifyToken(UUID.randomUUID().toString()); + s.setSourceUrl(topic); + s.setCallback(callback); + if (leaseSeconds > 0) { + s.setExpirationTime(System.currentTimeMillis() + (leaseSeconds * 1000)); + } + + final Subscription stored = this.dao.addSubscription(s); + + this.requester.sendSubscribeRequest(hubUrl, stored, (sync ? "sync" : "async"), leaseSeconds, secret, + this.callbackPrefix + stored.getId(), + new RequestCallback() { + @Override + public void onSuccess() { + callback.onSubscribe(stored); + } + + @Override + public void onFailure(Exception e) { + callback.onFailure(e); + } + }); + } + + public void subscribe(String topic, boolean sync, long leaseSeconds, String secret, + final SubscriptionCallback callback) throws IllegalArgumentException, IOException, FeedException { + SyndFeedInput input = new SyndFeedInput(); + SyndFeed feed = input.build(new InputStreamReader(new URL(topic).openStream())); + String hubUrl = this.findHubUrl(feed); + + if (hubUrl == null) { + throw new FeedException("No hub link"); + } + + this.subscribe(hubUrl, topic, sync, leaseSeconds, secret, callback); + } + + public String validate(String callbackPath, String topic, String mode, String challenge, String leaseSeconds, + String verifyToken) { + if (!callbackPath.startsWith(callbackPrefix)) { + throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath+" doesnt start with "+callbackPrefix)); + } + + String id = callbackPath.substring(callbackPrefix.length()); + Logger.getLogger(Subscriptions.class.getName()).log(Level.FINE, "Handling validation request for id {0}", id); + Subscription s = dao.findById(id); + if(s == null){ + throw new HttpStatusCodeException(404, "Not a valid subscription id", null); + } + if (!s.getVerifyToken() + .equals(verifyToken)) { + throw new HttpStatusCodeException(403, "Verification Token Mismatch.", null); + } + + if ("unsubscribe".equals(mode)) { + if (!s.isUnsubscribed()) { + throw new HttpStatusCodeException(400, "Unsubscribe not requested.", null); + } + + dao.removeSubscription(s); + } else if ("subscribe".equals(mode)) { + if (s.isValidated()) { + throw new HttpStatusCodeException(400, "Duplicate validation.", null); + } + + s.setValidated(true); + dao.updateSubscription(s); + } else { + throw new HttpStatusCodeException(400, "Unsupported mode " + mode, null); + } + Logger.getLogger(Subscriptions.class.getName()).log(Level.FINE, "Validated. Returning {0}", challenge); + return challenge; + } + + private String findHubUrl(SyndFeed feed) { + for (SyndLink l : (List) feed.getLinks()) { + if ("hub".equals(l.getRel())) { + return l.getHref(); + } + } + + return null; + } + + private void validateLink(SyndFeed feed, String source) { + for (SyndLink l : (List) feed.getLinks()) { + if ("self".equalsIgnoreCase(l.getRel())) { + try { + URI u = new URI(l.getHref()); + URI t = new URI(source); + + if (!u.equals(t)) { + throw new HttpStatusCodeException(400, "Feed self link does not match the subscribed URI.", null); + } + + break; + } catch (URISyntaxException ex) { + Logger.getLogger(Subscriptions.class.getName()) + .log(Level.SEVERE, null, ex); + } + } + } + } + + /** + * @param cache the cache to set + */ + public void setCache(FeedFetcherCache cache) { + this.cache = cache; + } + + /** + * @param requester the requester to set + */ + public void setRequester(Requester requester) { + this.requester = requester; + } + + /** + * @param callbackPrefix the callbackPrefix to set + */ + public void setCallbackPrefix(String callbackPrefix) { + this.callbackPrefix = callbackPrefix; + } + + /** + * @param dao the dao to set + */ + public void setDao(SubDAO dao) { + this.dao = dao; + } +} diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java b/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java new file mode 100644 index 0000000..0eb12d0 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java @@ -0,0 +1,36 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.sub.data; + +/** + * + * @author robert.cooper + */ +public interface SubDAO { + + public Subscription findById(String id); + + public Subscription addSubscription(Subscription s); + + public Subscription updateSubscription(Subscription s); + + public void removeSubscription(Subscription s); + +} diff --git a/src/main/java/org/rometools/certiorem/sub/data/Subscription.java b/src/main/java/org/rometools/certiorem/sub/data/Subscription.java new file mode 100644 index 0000000..5aa1de2 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/data/Subscription.java @@ -0,0 +1,158 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.sub.data; + +import java.io.Serializable; + + +/** + * + * @author robert.cooper + */ +public class Subscription implements Serializable { + private String id; + private String sourceUrl; + private String verifyToken; + private boolean unsubscribed; + private boolean validated; + private long expirationTime; + private SubscriptionCallback callback; + + /** + * Set the value of expirationTime + * + * @param newexpirationTime new value of expirationTime + */ + public void setExpirationTime(long newexpirationTime) { + this.expirationTime = newexpirationTime; + } + + /** + * Get the value of expirationTime + * + * @return the value of expirationTime + */ + public long getExpirationTime() { + return this.expirationTime; + } + + /** + * Set the value of id + * + * @param newid new value of id + */ + public void setId(String newid) { + this.id = newid; + } + + /** + * Get the value of id + * + * @return the value of id + */ + public String getId() { + return this.id; + } + + /** + * Set the value of sourceUrl + * + * @param newsourceUrl new value of sourceUrl + */ + public void setSourceUrl(String newsourceUrl) { + this.sourceUrl = newsourceUrl; + } + + /** + * Get the value of sourceUrl + * + * @return the value of sourceUrl + */ + public String getSourceUrl() { + return this.sourceUrl; + } + + /** + * Set the value of unsubscribed + * + * @param newunsubscribed new value of unsubscribed + */ + public void setUnsubscribed(boolean newunsubscribed) { + this.unsubscribed = newunsubscribed; + } + + /** + * Get the value of unsubscribed + * + * @return the value of unsubscribed + */ + public boolean isUnsubscribed() { + return this.unsubscribed; + } + + /** + * Set the value of validated + * + * @param newvalidated new value of validated + */ + public void setValidated(boolean newvalidated) { + this.validated = newvalidated; + } + + /** + * Get the value of validated + * + * @return the value of validated + */ + public boolean isValidated() { + return this.validated; + } + + /** + * Set the value of verifyToken + * + * @param newverifyToken new value of verifyToken + */ + public void setVerifyToken(String newverifyToken) { + this.verifyToken = newverifyToken; + } + + /** + * Get the value of verifyToken + * + * @return the value of verifyToken + */ + public String getVerifyToken() { + return this.verifyToken; + } + + /** + * @return the callback + */ + public SubscriptionCallback getCallback() { + return callback; + } + + /** + * @param callback the callback to set + */ + public void setCallback(SubscriptionCallback callback) { + this.callback = callback; + } +} diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java b/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java new file mode 100644 index 0000000..6c050a5 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java @@ -0,0 +1,23 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.rometools.certiorem.sub.data; + +import org.rometools.fetcher.impl.SyndFeedInfo; + +/** + * + * @author najmi + */ +public interface SubscriptionCallback { + + void onNotify(Subscription subscribed, SyndFeedInfo feedInfo); + + void onFailure(Exception e); + + void onSubscribe(Subscription subscribed); + + void onUnsubscribe(Subscription subscribed); +} diff --git a/src/main/java/org/rometools/certiorem/sub/data/package.html b/src/main/java/org/rometools/certiorem/sub/data/package.html new file mode 100644 index 0000000..625b5a4 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/data/package.html @@ -0,0 +1,28 @@ + + + + + data + + + Data classes for the Subscription management. + + diff --git a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java b/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java new file mode 100644 index 0000000..9cb0587 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java @@ -0,0 +1,74 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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. + */ + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.rometools.certiorem.sub.data.ram; + +import java.util.Date; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.rometools.certiorem.sub.data.SubDAO; +import org.rometools.certiorem.sub.data.Subscription; + +/** + * + * @author robert.cooper + */ +public class InMemorySubDAO implements SubDAO { + + private ConcurrentHashMap subscriptions = new ConcurrentHashMap(); + + @Override + public Subscription findById(String id) { + Subscription s = subscriptions.get(id); + if(s == null){ + return null; + } + if(s.getExpirationTime() > 0 && s.getExpirationTime() <= System.currentTimeMillis()){ + Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Subscription {0} expired at {1}", new Object[]{s.getSourceUrl(), new Date(s.getExpirationTime())}); + subscriptions.remove(id); + + return null; + } + return s; + } + + @Override + public Subscription addSubscription(Subscription s) { + subscriptions.put(s.getId(), s); + Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Stored subscription {0} {1}", new Object[]{s.getSourceUrl(), s.getId()}); + return s; + } + + @Override + public Subscription updateSubscription(Subscription s) { + subscriptions.put(s.getId(), s); + return s; + } + + @Override + public void removeSubscription(Subscription s) { + subscriptions.remove(s.getId()); + } + +} diff --git a/src/main/java/org/rometools/certiorem/sub/data/ram/package.html b/src/main/java/org/rometools/certiorem/sub/data/ram/package.html new file mode 100644 index 0000000..d5ae051 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/data/ram/package.html @@ -0,0 +1,28 @@ + + + + + ram + + + An In-Memory DAO for subscriptions. + + \ No newline at end of file diff --git a/src/main/java/org/rometools/certiorem/sub/package.html b/src/main/java/org/rometools/certiorem/sub/package.html new file mode 100644 index 0000000..44aab1c --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/package.html @@ -0,0 +1,30 @@ + + + + + sub + + + This package contains the business class Subscriptions that manages subscriptions and updates a + FeedInfoCache. + + + diff --git a/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java b/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java new file mode 100644 index 0000000..ff32ca5 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java @@ -0,0 +1,85 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.sub.request; + +import org.rometools.certiorem.sub.Requester; +import org.rometools.certiorem.sub.data.Subscription; + +import java.io.IOException; + +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; + + +/** + * + * @author robert.cooper + */ +public abstract class AbstractRequester implements Requester { + + protected boolean sendRequest(String hubUrl, String mode, Subscription subscription, String verifySync, + long leaseSeconds, String secret, String callbackUrl, RequestCallback callback) + throws IOException { + StringBuilder sb = new StringBuilder("hub.callback=").append(URLEncoder.encode(callbackUrl, "UTF-8")) + .append("&hub.topic=") + .append(URLEncoder.encode(subscription.getSourceUrl(), + "UTF-8")) + .append("&hub.verify=") + .append(URLEncoder.encode(verifySync, "UTF-8")) + .append("&hub.mode=") + .append(URLEncoder.encode(mode, "UTF-8")); + + if (leaseSeconds > 0) { + sb.append("&hub.lease_seconds=") + .append(Long.toString(leaseSeconds)); + } + + if (secret != null) { + sb.append("&hub.secret=") + .append(URLEncoder.encode(secret, "UTF-8")); + } + + if (subscription.getVerifyToken() != null) { + sb.append("&hub.verify_token=") + .append(URLEncoder.encode(subscription.getVerifyToken(), "UTF-8")); + } + + URL url = new URL(hubUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setDoOutput(true); +// connection.setRequestProperty("Host", url.getHost()); + connection.setRequestProperty("User-Agent", "ROME-Certiorem"); + connection.connect(); + connection.getOutputStream() + .write(sb.toString().getBytes("UTF-8")); + + int rc = connection.getResponseCode(); + connection.disconnect(); + + if (rc != 204) { + throw new RuntimeException("Unexpected repsonse code. " + rc); + } + + return true; + } +} diff --git a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java b/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java new file mode 100644 index 0000000..c345410 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java @@ -0,0 +1,74 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.sub.request; + +import org.rometools.certiorem.sub.data.Subscription; + +import java.io.IOException; + +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * A simple requester implementation that always makes requests as Async. + * @author robert.cooper + */ +public class AsyncRequester extends AbstractRequester { + @Override + public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, + final long leaseSeconds, final String secret, final String callbackUrl, final RequestCallback callback) { + Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending subscribe request to {0} for {1} to {2}", new Object[]{hubUrl, subscription.getSourceUrl(), callbackUrl}); + Runnable r = new Runnable() { + @Override + public void run() { + try { + sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, + callback); + } catch (Exception ex) { + Logger.getLogger(AsyncRequester.class.getName()) + .log(Level.SEVERE, null, ex); + callback.onFailure(ex); + } + } + }; + new Thread(r).start(); + } + + @Override + public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, + final String secret, + final String callbackUrl, final RequestCallback callback) { + Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending unsubscribe request to {0} for {1} to {2}", new Object[]{hubUrl, subscription.getSourceUrl(), callbackUrl}); + Runnable r = new Runnable() { + @Override + public void run() { + try { + sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, + callback); + } catch (IOException ex) { + Logger.getLogger(AsyncRequester.class.getName()) + .log(Level.SEVERE, null, ex); + callback.onFailure(ex); + } + } + }; + new Thread(r).start(); + } +} diff --git a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java b/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java new file mode 100644 index 0000000..2f25229 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java @@ -0,0 +1,68 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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. + */ + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.rometools.certiorem.sub.request; + +import org.rometools.certiorem.sub.data.Subscription; + +import java.io.IOException; + +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * A simple requester implementation that always makes requests as Async. + * @author Farrukh Najmi + */ +public class SyncRequester extends AbstractRequester { + @Override + public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, + final long leaseSeconds, final String secret, final String callbackUrl, final RequestCallback callback) { + Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending subscribe request to {0} for {1} to {2}", new Object[]{hubUrl, subscription.getSourceUrl(), callbackUrl}); + try { + sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, + callback); + callback.onSuccess(); + } catch (Exception ex) { + Logger.getLogger(SyncRequester.class.getName()) + .log(Level.SEVERE, null, ex); + callback.onFailure(ex); + } + } + + @Override + public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, + final String secret, + final String callbackUrl, final RequestCallback callback) { + Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending unsubscribe request to {0} for {1} to {2}", new Object[]{hubUrl, subscription.getSourceUrl(), callbackUrl}); + try { + sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, + callback); + callback.onSuccess(); + } catch (IOException ex) { + Logger.getLogger(SyncRequester.class.getName()) + .log(Level.SEVERE, null, ex); + callback.onFailure(ex); + } + } +} diff --git a/src/main/java/org/rometools/certiorem/sub/request/package.html b/src/main/java/org/rometools/certiorem/sub/request/package.html new file mode 100644 index 0000000..b2bd746 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/sub/request/package.html @@ -0,0 +1,28 @@ + + + + + request + + + Standard requester implementations. + + \ No newline at end of file diff --git a/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java b/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java new file mode 100644 index 0000000..091bc6d --- /dev/null +++ b/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java @@ -0,0 +1,86 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.web; + +import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.certiorem.hub.Hub; + +import java.io.IOException; + +import java.util.Arrays; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * + * @author robert.cooper + */ +public abstract class AbstractHubServlet extends HttpServlet { + public static final String HUBMODE = "hub.mode"; + private final Hub hub; + + protected AbstractHubServlet(final Hub hub) { + super(); + this.hub = hub; + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + try { + if ("publish".equals(req.getParameter(HUBMODE))) { + hub.sendNotification(req.getServerName(), req.getParameter("hub.url")); + } else { + String callback = req.getParameter("hub.callback"); + String topic = req.getParameter("hub.topic"); + String[] verifies = req.getParameterValues("hub.verify"); + String leaseString = req.getParameter("hub.lease_seconds"); + String secret = req.getParameter("hub.secret"); + String verifyToken = req.getParameter("hub.verify_token"); + String verifyMode = Arrays.asList(verifies) + .contains("async") ? "async" : "sync"; + Boolean result = null; + + if ("subscribe".equals(req.getParameter(HUBMODE))) { + long leaseSeconds = (leaseString != null) ? Long.parseLong(leaseString) : (-1); + result = hub.subscribe(callback, topic, verifyMode, leaseSeconds, secret, verifyToken); + } else if ("unsubscribe".equals(req.getParameter(HUBMODE))) { + result = hub.unsubscribe(callback, topic, verifyMode, secret, verifyToken); + } + + if ((result != null) && !result) { + throw new HttpStatusCodeException(500, "Operation failed.", null); + } + } + } catch (HttpStatusCodeException sc) { + resp.setStatus(sc.getStatus()); + resp.getWriter() + .println(sc.getMessage()); + + return; + } + + resp.setStatus(204); + } +} diff --git a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java b/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java new file mode 100644 index 0000000..5c74657 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java @@ -0,0 +1,79 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.web; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpUtils; +import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.certiorem.sub.Subscriptions; + +/** + * + * @author robert.cooper + */ +public class AbstractSubServlet extends HttpServlet { + + private final Subscriptions subscriptions; + + protected AbstractSubServlet(final Subscriptions subscriptions){ + super(); + this.subscriptions = subscriptions; + + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String mode = req.getParameter("hub.mode"); + String topic = req.getParameter("hub.topic"); + String challenge = req.getParameter("hub.challenge"); + String leaseString = req.getParameter("hub.lease_seconds"); + String verifyToken = req.getParameter("hub.verify_token"); + try{ + String result = subscriptions.validate(HttpUtils.getRequestURL(req).toString(), topic, mode, challenge, leaseString, verifyToken); + resp.setStatus(200); + resp.getWriter().print(result); + return; + } catch(HttpStatusCodeException e){ + e.printStackTrace(); + resp.setStatus(e.getStatus()); + resp.getWriter().print(e.getMessage()); + } + + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + try{ + this.subscriptions.callback(HttpUtils.getRequestURL(req).toString(), req.getInputStream()); + return; + } catch(HttpStatusCodeException e){ + e.printStackTrace(); + resp.setStatus(e.getStatus()); + resp.getWriter().println(e.getMessage()); + } + } + + + +} diff --git a/src/main/java/org/rometools/certiorem/web/package.html b/src/main/java/org/rometools/certiorem/web/package.html new file mode 100644 index 0000000..17f6703 --- /dev/null +++ b/src/main/java/org/rometools/certiorem/web/package.html @@ -0,0 +1,31 @@ + + + + + web + + + Contains base servlet implementations for doing hub and sub services. +

+ Extends these as needed in your web application. +

+ + \ No newline at end of file diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..f4a7eba --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,30 @@ + + + + + + jdbc/certiorem-datasource + + + + + + \ No newline at end of file diff --git a/src/site/apt/Certiorem.apt b/src/site/apt/Certiorem.apt new file mode 100644 index 0000000..d240e48 --- /dev/null +++ b/src/site/apt/Certiorem.apt @@ -0,0 +1,47 @@ + ----- + certiorem + ----- + kebernet + ----- + 2011-03-19 10:30:35.292 + ----- + +Certiorem + + Certiorem is an implementation of the {{{http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub\-core\-0.3.html}PubSubHubub }}protocol for ROME. + + It is dependent on ROME and ROME\-Fetcher for the base implementations, and will provide standard plugins for Propono to allow for publish eventing, where applicable. + +*Primary Components + +*Hub Implementation and Scaffolding (Done) + + The first part of Certiorem is a basic set of scaffolding classes that can be used to create a PSH notification hub. Initially, this will include a non\-guaranteed delivery hub, with standard implementations suitable for deployment on most JavaEE application servers or Google App Engine. It is intended that there should be at least one simple, drop in WAR file, utilizing JavaEE classes that can work in a default configuration for various standard web containers. Subsequently,  each of the classes in the PSH implementation up through the primary Controller class use constructor\-time composition/configuration so that the user/developer can easily construct a custom configuration of the Hub. + +**Client Implementation Integrated with ROME\-Fetcher (Done) + + For web\-based applications that use ROME\-Fetcher, an extended push\-notified store wrapper that will update based on callbacks from a Hub of change notifications. This will include a highly configurable callback servlet to write into the Fetcher cache as changes are made. Additionally, the system should support (semi\-)real time notifications of changes in the form of a listener that exectutes in a TBD thread state relative to the callback servlet. This should be packaged as a simple JAR with no more deps than fetcher that defines the callback servlet, and automagically does subscribes where link\=rel appropriate. + +**Notification Implementation for Propono based and JAX\-RS based Servers (In Progress) + + This should be a simple API call to notify a Hub of changes to topics. Again, this should provide real\-time notifications either synchronously or asynchronously. Importantly for Asynchronous notifications, they should block subsequent change notifications pending a notification to the Hub. + + References:  + + {{{https://github.com/nlothian/RTUpdates/blob/master/src/com/nicklothian/pubsubhub/PubSubHubSubscriptionServlet.java}https://github.com/nlothian/RTUpdates/blob/master/src/com/nicklothian/pubsubhub/PubSubHubSubscriptionServlet.java}} + + {{{http://grack.com/blog/2009/09/09/parsing\-the\-pubsubhubbub\-notifications/}http://grack.com/blog/2009/09/09/parsing\-the\-pubsubhubbub\-notifications/}} + +Notes on the Code + + It is still mostly a rough sketch, but the big outlines are there: + + There are three main packages: pub, sub and hub. + + The pub package is basically just a single utility class for pushing notifications to a hub. + + The hub package contains the Hub class. This is a general business controller that is intended to allow you to build a servlet around it with a very, very thin veneer, but you could also use it to drive an XMPP or JMS version too. It is basically built by composition of a number of classes, for which there are some default implementations: A Verifier, which makes the callback to verify new subscriptions, the HubDAO which stores the current subscriptions and subscriber statistics, and a Notifier which actually sends notifications to the subscribers. There are a couple of implementations of each of these (though the JPA HubDAO is still in process). Mostly the implementations for the Verifier and Notifier support threadpooling or no\-threads (for App Engine use). + + I have just started sketching out the sub package, but it basically has a "Subscriptions" class that will take in notifications (using the same "thin veneer" pattern that the Hub class uses). It is also constructed with some impls: A SubscriptionDAO that stores you current subscription information, a FeedFetcherCache that holds the received data, and a Requester that makes the subscription requests to hubs. + + I am hoping to have a basic end to end example working sometime in the next week or so, but if anyone wants to look over what is there, feel free. diff --git a/src/site/apt/CertioremTutorial.apt b/src/site/apt/CertioremTutorial.apt new file mode 100644 index 0000000..6a81dfc --- /dev/null +++ b/src/site/apt/CertioremTutorial.apt @@ -0,0 +1,124 @@ + ----- + Certiorem Tutorial + ----- + kebernet + ----- + 2011-12-06 19:23:15.220 + ----- + +Certiorem Tutorial + + Certiorem is a PubSubHubub (PSH) implementation for ROME. It isn't an application, but an API for building each of the three components (Publisher, Subscriber and Hub) into your web apps. + + You can see an {{{https://github.com/rometools/rome-incubator/tree/master/pubsubhubub/webapp}example webapp here}}. + +Creating a Hub + + Hubs take notifications, or "Pings" that tell it the content of a feed has been updated, fetch the feed, then notify each of the subscribers of the change. As you will begin to see, Certiorem is very much about "Composition" of classes. The Hub class is a prime example of this. + + Looking at the example webapp we see: + ++------+ +@Provides +@Singleton +public Hub buildHub() { + FeedFetcher fetcher = new HttpURLFeedFetcher(new DeltaFeedInfoCache()); +    Hub hub = new Hub(new InMemoryHubDAO(), new UnthreadedVerifier(), new UnthreadedNotifier(), fetcher); + +    return hub; +} ++------+ + + First we construct an instance of FeedFetcher, from the Fetcher subproject. This will be used to fetch feeds from remote hosts. There are a number of implementations for FeedFetcher and FeedInfoCache in the Fetcher project. Please look there for info on what is what. + + Next we need a HubDAO implementation. This is a DAO for managing Subscriber and SubscriptionSummary classes. Here we are using an in\-memory DAO, which like the HashMapFeedInfoCache will evaporate if we restart our web application. A JPA implementation for persistence is also available, but incomplete at time of writing. + + Next we need two implementations of network client interfaces: a Verifier, and a Notifier. The Verifier calls back to the Subscribers and verifies their subscribe/unsubscribe operations. A Notifier is used to send updates to to the clients. There are two basic implementations of these provided: A ThreadPool\* and Unthreaded\* version of each. The thread pool version uses a ThreadPoolExecutor to run queues of outbound calls. The Unthreaded version of each, makes the network calls in\-line with the request to the hub. These are suitable for environments like Google App Engine where spawning threads from servlets is absolutely verboten. + + There are other constructors that contain lists of restrictions for what the hub will support: acceptable topic feeds, ports, protocols, etc. + + The hub here is just a business logic class. In order to have a functioning hub, we need a servlet exposing the Hub. In the "web" package, there is an abstract servlet you can use to do just this. In the Guice wired example, we simply create a servlet with an injected Hub implementation. + ++------+ +@Singleton +public class HubServlet extends AbstractHubServlet { + + @Inject + public HubServlet(final Hub hub){ + super(hub); + } +} +//... in the ServerModule... + +serve("/hub*").with(HubServlet.class); ++------+ + + We can now include a \ value in our feeds and publish notifications of changes.  + +Publishing Ping Notifications + + This is perhaps the easiest thing to do. The Publisher class will take various combinations of URLs and SyndFeeds and send the appropriate notification. If your SyndFeed contains a \ and \ you can just pass the SyndFeed object. Otherwise, you can use the URL strings where appropriate. + + The example couldn't be simpler: + ++------+ +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); +} ++------+ + + Once this notification is sent, the hub will make a request to the feed and notify the clients of new entries. + +Subscribing to Feeds + + To set up a feed subscriber, you need to go through a process very much like setting up a Hub. First, create the Subscriptions class by composition: + ++------+ +@Provides +@Singleton +public Subscriptions buildSubs(){ +    Subscriptions subs = new Subscriptions(new HashMapFeedInfoCache(), new AsyncRequester(), +            "http://localhost/webapp/subscriptions/", new InMemorySubDAO()); +    return subs; +} ++------+ + + First we need a FeedInfoCache implementation. This will be updated as notifications come in, so in your web app, you want to make sure this is shared with the FeedFetcher implementation you are using to read feeds. Next you need a Requester, this is a network class that makes subscription requests to remote hubs. Next, a URL prefix for where the callbacks will live. This really means the URL to the SubServlet that is resolvable externally. Finally, a DAO for storing and retrieving Subscription objects. + + As in the Hub, we need a wrapper servlet to call into the Subscriptions class + ++------+ +@Singleton +public class SubServlet extends AbstractSubServlet { + + @Inject + public SubServlet(final Subscriptions subscriptions){ + super(subscriptions); + } +} + +// In the ServerModule... +serve("/subscriptions/*").with(SubServlet.class) ++------+ + + Now if we want to subscribe to a feed, we get a reference to the Subscriptions object, and pass in either the SyndFeed (with appropriate rel\="hub" and rel\="self" links) or simply a couple of URLs: + ++------+ + subs.subscribe("http://localhost/webapp/hub", "http://localhost/webapp/research-atom.xml", true, -1, null, new SubscriptionCallback(){ + + public void onFailure(Exception e) { + e.printStackTrace(); + } + + public void onSubscribe(Subscription subscribed) { + System.out.println("Subscribed "+subscribed.getId() +" "+subscribed.getSourceUrl()); + } + + }); ++------+ + + Here we pass in the URL of the Hub, the URL of the feed, a boolean indicating we want to make the subscription request synchronously, the lease seconds we want to keep the subscription for, a null cryptographic secret, and a Callback invoked when the subscribe request completes. diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt new file mode 100644 index 0000000..c6ce1c1 --- /dev/null +++ b/src/site/apt/index.apt @@ -0,0 +1,15 @@ + ----- + Home + ----- + kebernet + ----- + 2011-02-28 21:38:15.537 + ----- + +ROME Incubator + + This is the home of the Incubator space. + + To help you on your way, we've inserted some of our favourite macros on this home page. As you start creating pages, blogging and commenting you'll see the macros below fill up with all the activity in your space. + + {{{./Certiorem.html}certiorem (incubator)}} The Certiorem project – A PubSubHubub implementation for ROME diff --git a/src/site/resources/.nojekyll b/src/site/resources/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/src/site/resources/css/site.css b/src/site/resources/css/site.css new file mode 100644 index 0000000..43c3cd8 --- /dev/null +++ b/src/site/resources/css/site.css @@ -0,0 +1,8 @@ +h1 { + padding: 4px 4px 4px 6px; + border: 1px solid #999; + color: #900; + background-color: #ddd; + font-weight:900; + font-size: x-large; +} \ No newline at end of file diff --git a/src/site/resources/images/romelogo.png b/src/site/resources/images/romelogo.png new file mode 100644 index 0000000000000000000000000000000000000000..2c90608448e52857b31df02fa934de010996491f GIT binary patch literal 10835 zcmV-ZDy-FsP)EQkAMsI;g%@JeHXd!QkoO34|vxbt^eu#7yT)hP%6~4xtu?mRfO#vYxE!mwN zp+5h7uYrh<7DPsphQvNU#ho31-VTw*%bgveKL30_MEX1gtPMb~fyi!cM$=D4tRcYa z@4W>gC2Ng2<5c1*WRZBQL(pHq@(A=Ah`1Yb$MX=$8BMAq`w`H|5$H7#@z91y&EZZC zQ2*oo5b4K&l@aJQ5LwwzMY;&=y#yl0f^US}30ktqp)MM@zEf>)fk?iKkULQYk+GzF zSKpb-F6wEofyfMPh*bD=(ZKbcYE2Mn&J@bF3FST-xokUWOqPeEIzlMhAykJ6HHU?o zLvqIV4T(ZSk|Nh9kd`9qj+b*jX(=RvK!i3Xw|0KGjrq1h#F+J^DGxE`&ot)EFy-k& z$tt1P!<5~G3h(xD@Roau4%SBt4VO(FOe9Siv?H`%`J}Ce2u9i+qXRn9`Jr%l4JL>* zBp9>4f^||O!=GLqF2A*SsWE$mF=q@s?|jZ4Y1GKWjoGT4H56`oWgfzWdWbO}XwPV4 zzH9p|igW2A6fP7>R?@jFn8%IwQQ)0_}LN) z+11D_HpLpV0fo6v?W@Rz3hd(IDRvi1*9zsn?I`pWfWqo91vhA`6{J0+NI(j5TD0wJdrKBRZLWGoP7}VTOEa`4D>hSjTO^7gNQ=v^CA_~QaLZm_?KF#4%(%mZTjSyjs3L3gx_Ha_ZouMLj zK|~`~zPrt+!`suv5UFOIrFycS_KdP-%60>hY#kaQ8z^OCt7M&&4CK>=qGdvfXc79s zY!NEkMw-(5A!0j{x)>t0$K}Z=`i`2$x-Zf?q)0RaFX7WCZN+T zx(Eq5~xJ3sUAO4}~M`BH1HJV+v!HDmOH zWJiT9`Fe&RW7ZdZJyjvF9-2@tZ2;E$@THLoyqup%^cG2(wS0??Ky`MfrtxygFQery zr9M=64I>rKQPxo^epYxBl}=OHhsrKL$%mRpS}VE^BHezslKz?i4tR*bD+_X^bVJwy z$KFxY(Nv^&L8N!gaVLAx_aIWJ&uCOsq?3c&J09&F@P3W%VGcT+XJ|5mMybURl5tiFzqJ^>LzgwhR^iP#m8K~Fy$(vJ^1 z0zH(92nfY*s;R6m%CES6qu^pn&Z)CE{M+=c@>Kp%ZLhKb8tjcAO=3I-2dc`|5 zVcou%#r_wU1zcPn5W6BU&i!EA%7gK%{Gz`%8ryUywY9{U`MHgRgi2>@h)H)vN@YQI z!S%$#8_6`MrPP)c)sz$<*OnFu0tTbCt+l1Cxv8_wzh6`YWT3vOy0j+Ot`1z!k3JCR z9+vonIs-J8AcEIa1zM2ICG?m?5S2gAu2$Zw!f9v156&AFw#Z4$p$o@|Ib`9O;Q6D1 z=a1a${BccjzSZW$`fW%G^GS)=b1BeMP%pEthDc?7@tu<78wD{5nMcmv2snDxJ1k*6 z$iV)Xr9NlpRW+1ocA%lT77uFvv^RQj2O$EXB!9O0OaKLG$(;n-tJN{>CIxPvKODYz zLX?M#W)5FG{`v`d`-0f!`ijzPQU1x{zR3~0k*`Gh#q3@OcttFognVGm5M!&#;p$+B zG$e4t7keiHXaFw=ieD9cX-&wbwcr$?3G1=w>+V*m$GXkf7L~GnU(6El5&SK$hGEhlYlG~ch3n-UxL z{Wwj09Cn|EiRT)Y5ab1_6TW1k2naDpE}tUR0NNw8sdkb&6e7b(E5GzXJOB=EM)6Hj z<}uBY-50%BLI9BDcVSUWn}VC($d3l#ItUTGvhJLAya+v=cLbP`h525$gRIy{+&2@q zP4oluvJIyE16jJBEM7-8`Ov&$AMp<(`$92Iewl1TNe|_joTDn89AiF1h3{6 z(q`-wx{A|MfCFt3^8NVq7{v%D26=^kH%5=-h~M8Ei13R(G3%%rB7w2)#nqYW;W=@A zckrdv?DPj+S`Af&Em>BZ7Z~f-afpE36fHL9IB|r8syqdAEzj6y9|Dy8uv3xojmH)< zXz&65uH8=7Y@>O#Cs~EOm8{%CGqAYI$A3*lCK{S z*|YKJQMd6T2*71RzZ=W8Dk;Ppbft$u1hZ>WZPv0q$*;HtJD8e0z$})MeTpp^d3j4n z!a6lXY8uOJm}t3(kT;PU<_j0v_>^}5l{46h1Qn^QRy=(shOFG`7>J-}m6ATLnI{?{b*EG#ykanRKu_YreZ*~Yo z5PeP0KCn5dDFo1PDq8V;ZUGftJ5NO*mq652C$D`xOesXRT$UgLH8}68d<=C%b$Q7A zQMTZtdodc30Ki_t4#CZWSWRuV3n7Bn;}8{_(|#2b0WS!N;-6o#o);H7fEa-9%teis zX^6~9h`^}I8r?JFPQixOQy~KD8S8kvRTyt0L?SP5bqp1;8609kKm?dr=S9|d(Z85@ zh#h-Ftn-2nKm>-C29svXCCd;2Ly25Ag?;2w;MT}xlY1~kST*%>_6dj`YFR{0MIgXx zimUd@B6cE#c!iVYo@CQbA#m3fFYhv-1c(upQZ~T?3;Rb0U?DvMiD$c?cIzxd1Zar! z-@-l_wQ|NGx2Zi9A~3NxG|5VhrX3cDIT*k4O70o9+nP!*G@6=5W`mHu^DmZ%Wu>Kw zRNf-_CrM@?xweSJjwPo*CP!W-2YyBZ48-3+{{|Qm_RL-BMa2bJx6}#BDyN#-g%}uD zlCE|HB5>K?nRXsO^Lx@rFYl` zk?$E*4@UYjMp3gYu0q`{&%Pt|x3;tZHj-u67&E?Mmrib zKiu*g0f=C^Uy{))R}5a$VZ8?O4TK&kq5do;VnVG|u^J8R?yXIY(zCf&JE^w|6F^rKew?H&31`OBb&u?AAiGQifTIDR1Rx2v zr;uM#;-Qa{n|@;f5y%|3G<;3;HL#I)jMo5L8QF3}QOQl2E)bZ`AONv6NrDKBWUQM*ts) zVzMg%WDIBFDlgyv(h4|!H<4oPh!+xel)CZk;x8x+K%h=3H8fJc3`?jW`al5Egb2Ja zCpRd}fCv<_(XQG#Pp^Ckl+{fV!$=$NC9wbz*x-w+<@KUj5|U|Sa~(Ugc#2bJ4qo1t zdSZ|+L@>=e45X>jE_l$wrEyd!(Scprz5##;NQLNhMT$*QydkfUy4>uA2&Vt=Nx7aA z=jkg>GuF9talG|bq9RadV)t%j8xifZh7AX?DwOC@krYe&Xy|#hGMTpq5$tAD`C8B1 z(D2cSYy#%?{0cdQSPc>I9Rv`ueXgo62H)Wni9IyZpaG&ts@c2NWSlDlfSG&9dhJw$B{zTL z4l0vMX-^RGJ*apUlpVYLH8dW;ORnMOZCXEE$Ge&ELWn+`(M5s?#E$f6g{}9{ifJ}_ zXDl(An!{ZSk?^EVYD*|XMRXwoneo(zrK;zJg#A#7Y8oTLqyZ%W)&jv0|#GH_<_;$gbZ!1 z7!b)n^pXZdptxT6N`Vg;8Gr*#Facip9tshc3eQkQNd>-E{|6U)DzsAsCaTRO;xyZc z64cPz9ytm@Re~43ml8xDFe6S}_1so`%xw&U6pPXnQ8@6|Sd~9|Bt#JZygz1%Q7P6S z;7Bj_Juum;H2e=56AvEIq!gb6eq>4U0S-V*qF&%p0*I(pn*hVYEwX79*hB0H^bv3Y zHi22#Xp9F#@nHgIA*dpvQG^0wW7&j%RS+ozL|`Su4jQQ>0+m4(dLcx>mB39nEe7f; zv|m6+b9+QU^3Ix&$9RZ_P-EIc! zmK4|w83K}olxpkg77EMa2#jnI%yFdPIDne;2x^9|D8n;h^ zXP~D4uO1DM%xm2pBI*ttySfW>MXkbcaNqyal~UC}fhqR7 z;(ijMemub7vC-JrY<|hHb26!b3~}sjOph255c zi1i?TjX_>FSF)Y-B#4yPYXA}A{~rp7P%d*+9*&wEs;XFY%PD>ZuQ~Lr zQXKgQFOCEl+}6t**8(Esl?|@J37FT@ED5dP8hAuXYWpb{mBJN}Ai_ClG-(F+W!{x| zcK=mRf(Uw&QIY~5uT>I40~}NKP!|k~0O&GoN}kUbunZRvBybisU0crAu-~wMSE^J5 z1`=$6kyry{&#N~S6<82jIdh2GCJVJ0k=0U4xj{Ubkfjboq^+$jWWng3B(ADapH>*p zIdwIu$i5Umh3_8bjo?QVwS_-nMb}j$24?$m<|OK(^Sm~+&u}zEw);V%WYrc-D)!Z} z>DXCap%og6q~Pb|Yj}20GkA@Z;Qe8R*^WV^p}OM8Dpzj*RS%;g;)p=Ou}nxp6E}n; zZB;-7g2)Bs*@qB6ZRav#NsuM@Zlr{GHjY*K84^#+G9;WeoInb)QO0PhtSO8w3BePV zdnpA*@V1dlW<_Wxc&dU_sVFW)i?y;=<3;Fi^pT<6^tlq z_szY52*0n~cI#?x`OO;DF3z;VIK2Z!M2ZrUxFIrOodP0IP}7;)MJiHh1c|*6p#rb+ zNO(@E*<&bA3KgfVx<+H^LrFnA0Gl)|t)K^pKa!GOL?h(cM&{f`Rz=c-NOf^O&H<3N z|HD9nj5t=7vv7vBdjJuQ!@;aUME3L^yW+k3`~n;@!*Lu4t$Ic?5hCG<8x#EC8d0I>rp#fnEA2##uYe(IJfYK7rAkIhw=; zra;z__?jL>YDx<2ib~Y=^g7gZrg1>FC5T|NZf%}44Wh#jr$sckD$Y60D!Zn66o5!Y zf|E9#js8}lZg7%j{CKNTh8i>mXn>1{O$UCiP@6%kvJQy9CtuUv?G1ZIoHB@n6Giba z3~N$CbUQ2avM2#2uFH}S@!BtI(fSavFL3p~K_oI+W6ui{m?#HFh+smD$nk4F93g=? zqGvq=L{7&nlp%tt1zTYgVplDO80zvMPAxj}ibCcEQMqCc@xq2Y$)BPyjVqn|Xw{#fCBlHv1ikL5^PieAac#T z;S|9{Ts)~X(~uz~3#`~GN!ozcvz5_$EZgb1-59W>NuXT6lWg#6Ilf{P2N4{I*A3lx z8W4d`PS>}h3~!bo0)i2eu%06%Q7PLr-84Z-TN6(^$&-g!Jo>8Q*?s?NlWRr|7eIvF zM}A?jf*JuLDc_1O^49nGt9SPwIAq2Xw^;_hIt$)DE-d~s!`diBcD4Z`aQ(9#H$kM^ z1p_z+A~YZ^)-An6apOR}PA~u%H^B8Nf5bO4Dv zM@Zt*!_^yY_}FI5T!La#tA!9{D<}a(s+oHiFOK9P5<5z4q2*E#=U3g!coF*`0<0JY6ktBK84$U;NFIBm z&~b=Bt<4FQtKuL+LzZ5~uj*h@HOEm4t&17UExb9lM5e)_3cIS5B+S91d(H};n$n# z)+bnf3<(UfQc`cz)f8(WtmHB0QNnC5#*|19LF{Vb4aTp8Xq%HE;Y)PS?zMF{o;A~% zQ0yl4#p)&ryQv6!B)6uK4G80oamM~$oXslnBR;kn^O~nP(x~II2uDRAd9WLOX~4iA zF*J}fV6?CtF{HM%N@I%iw7KXIy{bTIuHBS@b@-IoFDO9-N6p-cWdf53DY|`C?_gFt z_Vm^qv9L)3moFIer*|ntWS@>EL_jbil9Um{gv8&8grs5)qvv9qF|XM0%_bOIZHY%z zE4`3K%9$e^AbGGRIM`Ya`~>f@CGHTjjtRb^3=a_7sNOndqxCE%!3<3aBJ?cHFdw$- zEe-W{>Al)MnhIY__gPbj%;+kJ?7yfu$V$&tkHE9+GC49sY>nv@8XE1)$2L=0odF^TAHa*?o3-VLM2HSxDC*=FY}4bw4QD-*qGctBz)N?|i&p~? z*o?!zZM3oKK*Z<%K}31hnI1$Sx8k%2Zg2~$GDIndk8P$J%@Rf7qXX;?77<|th*UBQ zKjKM6J)le=DukLV^c*W3J%A3vdTYf-+M>&d^>EfRSnkC=!xBW`!VOzAjvJ`>fKDG| zRdN3yf-T)_e=IosKr^o8DZ@eG???-T6PS-}hPZHfwqlr~hjhe^2Z%shW`msl|C2Z5 zo18dYFp&kJg!8lDS)BQ7`_^#IdM3h)g@~wY8fQl#sEKDuc(`Y~& zF!44*1cf1@s;M+|qW#Ic6tT^K2+W{ty6$FQRHDR*IFGT~N^2^h4kpq=3Fa85ytB!6 zK}3ukfEA8SVn~2QMF0`*L`|{q!Ee5{5F=uJH=e_&2*j2GjhlY-AOc4WPS~{(B48-6 ztHQdmfYH5? z**{^Us4HQPwb`R-;!(kp8xNCBCDsuB7^Z|kPn_3li#XE7R75G+N@J@Jk+p~uupJ^m z2@VQqZEN3^(EemZT7)8ENbTuG$qu+_xR9cfI1QZn8VU;9a45TFjhFqEy6%{0r+uNe z%Bo@|Fu}o?E2W5IbhiW`vSt^-eG&kH`gCs;Zmg|B_*plG$i-!vo?gU-;Is(4Afi5Q z1dr2g|7^&hI(Qug0{`3YcmNsz%LLJ>Bj7=G_84GFceiE~VIcyM6R?mH%wM)|3P(K< zTq>B;N2J{nxKBca2r|7RAeRYsG`%d|e`~~&iB?f^AE*e-=X)+Jq}LltIi6l`g$z~p z;%#QM2nogcnQcad@FApgO~}vz$Un4tsQU2yY#?iZZSme^amPoNqY@3 zXNy+ab14Az#xWZ+EsMJ1^&>E$N>|&!$d<}D7O&nU->oJqaLtXc3=y1F6t6sbRUC=X zMNU>-diMb$IC=M4?m3*?E#=hw=t~(jaL6z@AOqPXYp?nNMB! zyU0l-@NIIAI+(nQlmW0Mv35r|gEBQUssR_cDhe+94N)O!t8~HuSmFU>NO#R36bPRY zsD>{A5%wMvfb();GK#EG`F>7rjCFP{Lq#*cv=O}mcX++|o zc?zLgra*n6uGiVTh*-YNur2j&n!0eiK@8>{vP)9b1b93Op&9yoI?joyX^=L^mj zsHvl2ZZ_Y$WNu(>Nq*=;Md%QOR&0+@k9K2qdFZ0C@Y?7pIK31iux@dCAk@L@7%jVa z4F#F2JjAJMwbkZ*hV!9k51*x{jKEU^i+Fk#-SJRdN)OY8mF(W!tk~Lo7l%Y}az@ZM z!)uD<&~X+nNufTl%Ht4UV1;g>ST^a^=ZiciKMO{tr!&)N0o5e|*5}m0B@m3L8OBVH(_G2WLW{4x zc_t!a$%I}C5k&o{&xgS@AA6l26Y=;%s}cz)P%RUGpR!2TILpPRIC$#qs18TXNOyj- zmw$uZVB>#%B_rbM)CxPjzssk4r~bp(!dsq*Bdx29Q`nCFb+TwqIF%*EWBjF){57p3 zc+ur=tyo$y>(QeWErML4hbk_@t&<(;#N&Ba;tFphD{@*&ZCO!GNkLU%Zbh#0I9PjM z)Z-z7D?uWkC5NA<_OXM%pa=k|fXeD=An}tmMkDwkS_Tu33}A^_gcrU+C2UIHWeHMT zoUFY=-&4x>c!=l?G|t)8yHq580*U#W#EzlN=;&)C@{c6&ClnlEkMWg(>9Cg$h~%*SwnHNu`$=lnCBuCEfY#s3FW>* z<$j?$QmB`2YqSaxmBFevj8LENLu(lknr*b`S%L_Nk5Ig<&ktu`9{?*5VQ&=Z>qF(( z{u^8AWwD*i#=E2?kKTLV*<2*lCkPEm?Kx3skT)CJ0TH3F>kstZ$@Wx{!C-m5M$P0M`Y9kIiS-ydzdkMxP$UYDy5q9a9hPy z?p_jO#vp9IupyhIVh3a=lbG#*42j)Ad9uLV+tO=4+rCMHhe+1oo<1lfe~Q!v_Oqk< z#nssruW(dTE!AWDR;!*15mM+(8fS5%Kq_5YvL=bshQFkAntBRJl?$nJrGHDN(PF5l zdIn00RgtP0_{sb|idDKGn}0G@SerIps*{w_`sIJ|xn>3_pH3eyo=WOx^3B7G@Lv2a zbe3^k;7r?t2WwqP1$~x2UNN1PWZ+J}L}O4A#n@$lKBB^+spbcZrjiPCgXtr8vU*TjJ)O|xi$I#;$w7^ClI z{N?o*e>ru`Ghw?vK*{PG<34@=e*--SQam-znlkE-lScdjPu+%8LU{ zYFyuc`_VA(4@5lS@1flveeuz6FuP_%7Ek?T;A2}>yoqn(B0hiou^%g%S3LtY&zb!E zs4t$ZxaK6HgcLZ}rj2{y*$3uMe(s}pf9?LwD-;}eXRVm`@?cykphd=5^dK^Z92UAPtJ8j0K0Guek1nX+SZo z$ah}*6(&+7DyISm`E7hptPpVd=fM9ZWWn;eFYnp#9!P@Ms<-1JKNkT(3luqL$Bi5} z>}fMZYG%;MD=`xf)Euz&@6My25ogFmpIl~7`g7x*iTLK>2mim+Frb8xZ(scLFYuS* zqt12E-yf^G;Z%Qn{0q*?_pX`cPgfQR!FMp5Ed;euHY@%jK2{_2-MqSU2q z+WFv59(v$EMS8Pj_Diq+gv=MQ)i)qgHvNSEpas*OUpo6G(qdXD zB~xRDpIvtR|?|h*?4fP+gs;@KNY)x(fIJMkCMD8-fRCF=KbN#vqOQB{hR+b zYr>y5FMmTE91}$3U822^(U`dG?BDPw7&_SQj~Cyar&1 z8)wl4*UtN~OgAol;~VD}g1z1^y)p*B{`K`o8t+VK%b5&fF!GBhZ=4-ke|rLzFvMwV zn2B%ZPI->5%Z8bMeeG8O3f4VsK%sN_HK);EJ%txh%3tUD?rV=UWln6$oJ8MPKK<$6 z{xs6}qo;oRlLO#lnDX-J+gH6!A<{bM<>ww`v1@)8mV1FS-u~X}j}T!lG0y$lTmK_d zkxCbj`L9%@It}~e2~YPo@hgbO)4%&Er9F)^S1x$<+NmL^a~5FTJUhzo7+<%b& zmcLb{I$b?E1hazCY|fmBS;>HRM&$kF)3><2S#xtdCF!8>^)sJ&`e#%I1k)*-h84eY z+3R#&0wRsGUVi>TLKeRD%EOd@n+jhD`Se^cB@!Y;@)Ab@oprayUpB4mcVB;m&H-k+ z&h^80AEgo~fJNqE{*UW(2Q<*vr{XM+1c$7sfqSua5lITiR%yqdDkDwlu!?J@e^ zDi?|v5VJbhXP){wdUXBt&{1DLNr7b=2N*0!g?#X1FN6p>xd}AWB$UzFYM8ln&daH% zhUCPJT=)HJo0h*xC6YSVpzZH(T=s^?x36A3F<6xO0fp6z2IQG|xtS7N9gCp{u&8=c z=juG_nWb}Hs=GA-6A$?j#MziPnGy*+_}zekZ#@d~ZhmQjGbDzU^9KNPtG|1dqM^X~ zvkxBMyyA_TwDCbZ29mON^`v>W)6l1zvnD~59{%a?g0>F?uTcom#Zyzy40+|bUx<|h zi$3e$y>#ev1*IvQ=C|R!!lcm@tN?VS%Ttg41Z_Th@SjxH29+vsu1t0EUi*&tUa7yH z?v(SQYv0d&ap8;?a^gp#?e1q=Vw6D@Fp*SvhX5Q>*mpk#hdisWz}PhrvNV9A>>f^iVA&H~eCD^`CC#(qmCd?9y& zC9Awc2fb&l985H+mbU?@b{??)OreQ1*%Kp)9YwmXO9YJR`6LU;-CIHfyo-{jk^PV? z)E=WjE}9-hd|&RZ<1+LW$~<))fh8-A1>Yc)M%%YXJ$7GMbl2%G1}m<$4lf3*PYa7- zoCRl=MgPz#>E(>;CRdwHaG<7K4$rRgji^9q)V*oa{O)0jnZWsE*Ka zq#qWl0)_Hjx{IN7tx)W);}Un%b#&*u8sUz~`jTG^8G}gGK^;cZn`W`UFAf@kek$Ui df$Y82{2ymMg>RmA!D#>h002ovPDHLkV1j1dKi>cV literal 0 HcmV?d00001 diff --git a/src/site/site.xml b/src/site/site.xml new file mode 100644 index 0000000..c6a5c88 --- /dev/null +++ b/src/site/site.xml @@ -0,0 +1,33 @@ + + + + + org.apache.maven.skins + maven-fluido-skin + 1.3.0 + + + + ROME + images/romelogo.png + http://github.com/rometools/ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java b/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java new file mode 100644 index 0000000..447aed8 --- /dev/null +++ b/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java @@ -0,0 +1,50 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub; + +import org.rometools.certiorem.hub.data.Subscriber; + +/** + * + * @author robert.cooper + */ +public class AlwaysVerifier implements Verifier { + + @Override + public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + callback.onVerify(true); + } + + @Override + public boolean verifySubcribeSyncronously(Subscriber subscriber) { + return true; + } + + @Override + public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + callback.onVerify(true); + } + + @Override + public boolean verifyUnsubcribeSyncronously(Subscriber subscriber) { + return true; + } + +} diff --git a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java new file mode 100644 index 0000000..172d9b1 --- /dev/null +++ b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java @@ -0,0 +1,124 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub; + +import java.util.logging.Logger; +import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.fetcher.FeedFetcher; +import org.rometools.fetcher.impl.HashMapFeedInfoCache; +import org.rometools.fetcher.impl.HttpURLFeedFetcher; + +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import org.rometools.certiorem.hub.data.HubDAO; +import org.rometools.certiorem.hub.data.ram.InMemoryHubDAO; + +/** + * + * @author robert.cooper + */ +public class ControllerTest { + public ControllerTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of subscribe method, of class Hub. + */ + @Test + public void testSubscribe() { + Logger.getLogger(ControllerTest.class.getName()).info("subscribe"); + + String callback = "http://localhost/doNothing"; + String topic = "http://feeds.feedburner.com/screaming-penguin"; + long lease_seconds = -1; + String secret = null; + String verify_token = "MyVoiceIsMyPassport"; + HubDAO dao = new InMemoryHubDAO(); + Notifier notifier = null; + FeedFetcher fetcher = new HttpURLFeedFetcher(HashMapFeedInfoCache.getInstance()); + Hub instance = new Hub(dao, new AlwaysVerifier(), notifier, fetcher); + + Boolean result = instance.subscribe(callback, topic, "sync", lease_seconds, secret, verify_token); + assertEquals(true, result); + + instance = new Hub(dao, new NeverVerifier(), notifier, fetcher); + result = instance.subscribe(callback, topic, "sync", lease_seconds, secret, verify_token); + assertEquals(false, result); + + result = instance.subscribe(callback, topic, "async", lease_seconds, secret, verify_token); + assertEquals(null, result); + + // Test internal assertions + try { + instance.subscribe(null, topic, "async", lease_seconds, secret, verify_token); + fail(); + } catch (HttpStatusCodeException e) { + assertEquals(400, e.getStatus()); + Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); + } + + try { + instance.subscribe(callback, null, "async", lease_seconds, secret, verify_token); + fail(); + } catch (HttpStatusCodeException e) { + assertEquals(400, e.getStatus()); + Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); + } + + try { + instance.subscribe(callback, topic, "foo", lease_seconds, secret, verify_token); + fail(); + } catch (HttpStatusCodeException e) { + assertEquals(400, e.getStatus()); + Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); + } + + // test general exception + instance = new Hub(dao, new ExceptionVerifier(), notifier, fetcher); + + try { + result = instance.subscribe(callback, topic, "sync", lease_seconds, secret, verify_token); + fail(); + } catch (HttpStatusCodeException e) { + assertEquals(500, e.getStatus()); + } + } +} diff --git a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java new file mode 100644 index 0000000..a7786e1 --- /dev/null +++ b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java @@ -0,0 +1,77 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.rometools.certiorem.hub; + +import java.io.IOException; +import com.sun.syndication.feed.synd.SyndEntry; +import java.util.List; +import junit.framework.Assert; +import org.rometools.fetcher.impl.HashMapFeedInfoCache; +import org.rometools.fetcher.impl.HttpURLFeedFetcher; +import java.net.URL; +import com.sun.syndication.feed.synd.SyndFeed; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author najmi + */ +public class DeltaSyndFeedInfoTest { + + DeltaFeedInfoCache feedInfoCache; + HttpURLFeedFetcher feedFetcher; + SyndFeed feed; + + public DeltaSyndFeedInfoTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + + @Before + public void setUp() { + feedInfoCache = new DeltaFeedInfoCache(new HashMapFeedInfoCache()); + feedFetcher = new HttpURLFeedFetcher(feedInfoCache); + } + + @After + public void tearDown() { + } + + + /** + * Test of getSyndFeed method, of class DeltaSyndFeedInfo. + */ + @Test + public void testGetSyndFeed() throws Exception { + System.out.println("getSyndFeed"); + + feed = feedFetcher.retrieveFeed(getFeedUrl()); + List entries = feed.getEntries(); + Assert.assertTrue(!entries.isEmpty()); + + //Fetch again and this time the entries should be empty as none have changed. + feed = feedFetcher.retrieveFeed(getFeedUrl()); + entries = feed.getEntries(); + Assert.assertTrue(entries.isEmpty()); + } + + private URL getFeedUrl() throws IOException { + URL feedUrl = new URL("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss"); +// URL feedUrl = new URL("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml"); + + return feedUrl; + } +} diff --git a/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java b/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java new file mode 100644 index 0000000..9dfa920 --- /dev/null +++ b/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java @@ -0,0 +1,50 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub; + +import org.rometools.certiorem.hub.data.Subscriber; + +/** + * + * @author robert.cooper + */ +public class ExceptionVerifier implements Verifier{ + + @Override + public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean verifySubcribeSyncronously(Subscriber subscriber) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean verifyUnsubcribeSyncronously(Subscriber subscriber) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java b/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java new file mode 100644 index 0000000..86cd96d --- /dev/null +++ b/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java @@ -0,0 +1,50 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub; + +import org.rometools.certiorem.hub.data.Subscriber; + +/** + * + * @author robert.cooper + */ +public class NeverVerifier implements Verifier{ + + @Override + public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + callback.onVerify(false); + } + + @Override + public boolean verifySubcribeSyncronously(Subscriber subscriber) { + return false; + } + + @Override + public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + callback.onVerify(false); + } + + @Override + public boolean verifyUnsubcribeSyncronously(Subscriber subscriber) { + return false; + } + +} diff --git a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java new file mode 100644 index 0000000..ff39791 --- /dev/null +++ b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java @@ -0,0 +1,89 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.data; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +/** + * + * @author robert.cooper + */ +public abstract class AbstractDAOTest { + + protected abstract HubDAO get(); + + @Test + public void testSubscribe() { + HubDAO instance = get(); + Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testSubscribe", instance.getClass().getName()); + Subscriber subscriber = new Subscriber(); + subscriber.setCallback("http://localhost:9797/noop"); + subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); + subscriber.setLeaseSeconds(-1); + subscriber.setVerify("VerifyMe"); + + Subscriber result = instance.addSubscriber(subscriber); + + assert result.equals(subscriber) : "Subscriber not equal."; + + List subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); + + assert subscribers.contains(result) : "Subscriber not in result."; + } + + @Test + public void testLeaseExpire() throws InterruptedException { + HubDAO instance = get(); + Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testLeaseExpire", instance.getClass().getName()); + Subscriber subscriber = new Subscriber(); + subscriber.setCallback("http://localhost:9797/noop"); + subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); + subscriber.setLeaseSeconds(1); + subscriber.setVerify("VerifyMe"); + + Subscriber result = instance.addSubscriber(subscriber); + + assert subscriber.equals(result) : "Subscriber not equal."; + //quick test for store. + List subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); + assert subscribers.contains(result) : "Subscriber not in result."; + //sleep past expiration + Thread.sleep(1100); + subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); + assert !subscribers.contains(result) : "Subscriber should have expired"; + } + + @Test + public void testUnsubscribe() throws InterruptedException { + HubDAO instance = get(); + Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testUnsubscribe", instance.getClass().getName()); + Subscriber subscriber = new Subscriber(); + subscriber.setCallback("http://localhost:9797/noop"); + subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); + subscriber.setLeaseSeconds(1); + subscriber.setVerify("VerifyMe"); + + Subscriber result = instance.addSubscriber(subscriber); + // TODO + + } +} diff --git a/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java new file mode 100644 index 0000000..90db87f --- /dev/null +++ b/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java @@ -0,0 +1,44 @@ +/** + * + * Copyright (C) The ROME Team 2011 + * + * + * 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.rometools.certiorem.hub.data.ram; + +import org.rometools.certiorem.hub.data.AbstractDAOTest; +import org.rometools.certiorem.hub.data.HubDAO; + +/** + * + * @author robert.cooper + */ +public class InMemoryDAOTest extends AbstractDAOTest{ + private InMemoryHubDAO dao = new InMemoryHubDAO(); + + public InMemoryDAOTest() { + } + + @Override + protected HubDAO get() { + return dao; + } + + + + + +} \ No newline at end of file From ebcf32caea142c3e555375849c2049d53e3a1df4 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 11 Oct 2013 23:44:48 +0200 Subject: [PATCH 02/23] Removed parent Removed unused configuration --- pom.xml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index f1fa07c..ddb952a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,13 +4,9 @@ 4.0.0 - - rome-push - com.rometools - 1.0.0-SNAPSHOT - - + com.rometools rome-certiorem + 1.0.0-SNAPSHOT rome-certiorem @@ -77,14 +73,6 @@ 1.6 - - org.apache.maven.plugins - maven-war-plugin - 2.4 - - false - - org.apache.maven.plugins maven-source-plugin From 6ac4408ddf9307b4e1cdeef9c592e586aa09712c Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Oct 2013 15:04:12 +0200 Subject: [PATCH 03/23] Formatted code Added Eclipse formatter and cleanup configuration --- cleanup.xml | 56 ++++ formatter.xml | 291 ++++++++++++++++++ .../certiorem/HttpStatusCodeException.java | 9 +- .../certiorem/hub/DeltaFeedInfoCache.java | 25 +- .../certiorem/hub/DeltaSyndFeedInfo.java | 114 +++---- .../java/org/rometools/certiorem/hub/Hub.java | 170 +++++----- .../org/rometools/certiorem/hub/Notifier.java | 13 +- .../org/rometools/certiorem/hub/Verifier.java | 15 +- .../rometools/certiorem/hub/data/HubDAO.java | 3 +- .../certiorem/hub/data/Subscriber.java | 103 +++---- .../hub/data/SubscriptionSummary.java | 33 +- .../certiorem/hub/data/jpa/JPADAO.java | 45 ++- .../certiorem/hub/data/jpa/JPASubscriber.java | 52 ++-- .../hub/data/ram/InMemoryHubDAO.java | 65 ++-- .../hub/notify/standard/AbstractNotifier.java | 106 +++---- .../hub/notify/standard/Notification.java | 3 +- .../notify/standard/ThreadPoolNotifier.java | 73 +++-- .../notify/standard/UnthreadedNotifier.java | 18 +- .../hub/verify/standard/AbstractVerifier.java | 64 ++-- .../verify/standard/ThreadPoolVerifier.java | 40 ++- .../standard/ThreadpoolVerifierAdvanced.java | 6 +- .../verify/standard/UnthreadedVerifier.java | 9 +- .../certiorem/pub/NotificationException.java | 7 +- .../rometools/certiorem/pub/Publisher.java | 153 +++++---- .../rometools/certiorem/sub/Requester.java | 10 +- .../certiorem/sub/Subscriptions.java | 187 +++++------ .../rometools/certiorem/sub/data/SubDAO.java | 3 +- .../certiorem/sub/data/Subscription.java | 65 ++-- .../sub/data/SubscriptionCallback.java | 4 +- .../sub/data/ram/InMemorySubDAO.java | 24 +- .../sub/request/AbstractRequester.java | 47 +-- .../certiorem/sub/request/AsyncRequester.java | 68 ++-- .../certiorem/sub/request/SyncRequester.java | 36 +-- .../certiorem/web/AbstractHubServlet.java | 36 +-- .../certiorem/web/AbstractSubServlet.java | 39 ++- .../certiorem/hub/AlwaysVerifier.java | 11 +- .../certiorem/hub/ControllerTest.java | 48 +-- .../certiorem/hub/DeltaSyndFeedInfoTest.java | 43 +-- .../certiorem/hub/ExceptionVerifier.java | 13 +- .../certiorem/hub/NeverVerifier.java | 13 +- .../certiorem/hub/data/AbstractDAOTest.java | 27 +- .../hub/data/ram/InMemoryDAOTest.java | 11 +- src/test/resources/.gitignore | 1 + 43 files changed, 1196 insertions(+), 963 deletions(-) create mode 100644 cleanup.xml create mode 100644 formatter.xml create mode 100644 src/test/resources/.gitignore diff --git a/cleanup.xml b/cleanup.xml new file mode 100644 index 0000000..40f9b7a --- /dev/null +++ b/cleanup.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/formatter.xml b/formatter.xml new file mode 100644 index 0000000..e7ba7aa --- /dev/null +++ b/formatter.xml @@ -0,0 +1,291 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java b/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java index 1bdeb0f..d1ff1b0 100644 --- a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java +++ b/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java @@ -16,24 +16,23 @@ * limitations under the License. */ - package org.rometools.certiorem; /** - * + * * @author robert.cooper */ public class HttpStatusCodeException extends RuntimeException { private final int status; - public HttpStatusCodeException(int status, String message, Throwable cause){ + public HttpStatusCodeException(final int status, final String message, final Throwable cause) { super(message, cause); this.status = status; } - public int getStatus(){ - return this.status; + public int getStatus() { + return status; } } diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java index a0702f3..edf0c02 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java +++ b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java @@ -5,33 +5,32 @@ package org.rometools.certiorem.hub; import java.net.URL; + import org.rometools.fetcher.impl.FeedFetcherCache; import org.rometools.fetcher.impl.SyndFeedInfo; /** - * Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure that - * any SyndFeedInfo used within it are replaced with a DeltaSyndFeedInfo which is capable of - * tracking changes to entries in the underlying feed. + * Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure that any SyndFeedInfo used within it are replaced with a DeltaSyndFeedInfo + * which is capable of tracking changes to entries in the underlying feed. * * @author najmi */ public class DeltaFeedInfoCache implements FeedFetcherCache { - + FeedFetcherCache backingCache; - - - public DeltaFeedInfoCache(FeedFetcherCache backingCache) { + + public DeltaFeedInfoCache(final FeedFetcherCache backingCache) { this.backingCache = backingCache; } @Override - public SyndFeedInfo getFeedInfo(URL feedUrl) { + public SyndFeedInfo getFeedInfo(final URL feedUrl) { return backingCache.getFeedInfo(feedUrl); } @Override - public void setFeedInfo(URL feedUrl, SyndFeedInfo syndFeedInfo) { - //Make sure that syndFeedInfo is an instance of DeltaSyndFeedInfo + public void setFeedInfo(final URL feedUrl, SyndFeedInfo syndFeedInfo) { + // Make sure that syndFeedInfo is an instance of DeltaSyndFeedInfo if (!(syndFeedInfo instanceof DeltaSyndFeedInfo)) { syndFeedInfo = new DeltaSyndFeedInfo(syndFeedInfo); } @@ -40,12 +39,12 @@ public class DeltaFeedInfoCache implements FeedFetcherCache { @Override public void clear() { - backingCache.clear(); + backingCache.clear(); } @Override - public SyndFeedInfo remove(URL feedUrl) { + public SyndFeedInfo remove(final URL feedUrl) { return backingCache.remove(feedUrl); } - + } diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java index 0bb13c5..ed9284e 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java +++ b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java @@ -4,8 +4,6 @@ */ package org.rometools.certiorem.hub; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; import java.math.BigInteger; import java.security.MessageDigest; import java.util.ArrayList; @@ -13,51 +11,55 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; + import org.rometools.fetcher.impl.SyndFeedInfo; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; + /** - * Extends SyndFeedInfo to also track etags for individual entries. - * This may be used with DeltaFeedInfoCache to only return feed with a subset of entries that have changed since last fetch. + * Extends SyndFeedInfo to also track etags for individual entries. This may be used with DeltaFeedInfoCache to only return feed with a subset of entries that + * have changed since last fetch. * * @author najmi */ -public class DeltaSyndFeedInfo extends SyndFeedInfo { +public class DeltaSyndFeedInfo extends SyndFeedInfo { Map entryTagsMap = new HashMap(); Map changedMap = new HashMap(); - - private DeltaSyndFeedInfo() { + + private DeltaSyndFeedInfo() { } - - public DeltaSyndFeedInfo(SyndFeedInfo backingFeedInfo) { - this.setETag(backingFeedInfo.getETag()); - this.setId(backingFeedInfo.getId()); - this.setLastModified(backingFeedInfo.getLastModified()); - this.setSyndFeed(backingFeedInfo.getSyndFeed()); + + public DeltaSyndFeedInfo(final SyndFeedInfo backingFeedInfo) { + setETag(backingFeedInfo.getETag()); + setId(backingFeedInfo.getId()); + setLastModified(backingFeedInfo.getLastModified()); + setSyndFeed(backingFeedInfo.getSyndFeed()); } - + /** * Gets a filtered version of the SyndFeed that only has entries that were changed in the last setSyndFeed() call. * - * @return + * @return */ @Override public synchronized SyndFeed getSyndFeed() { try { - SyndFeed feed = (SyndFeed) super.getSyndFeed().clone(); - - List changedEntries = new ArrayList(); - - List entries = feed.getEntries(); - for (SyndEntry entry : entries) { + final SyndFeed feed = (SyndFeed) super.getSyndFeed().clone(); + + final List changedEntries = new ArrayList(); + + final List entries = feed.getEntries(); + for (final SyndEntry entry : entries) { if (changedMap.containsKey(entry.getUri())) { - changedEntries.add(entry); + changedEntries.add(entry); } } - + feed.setEntries(changedEntries); - + return feed; - } catch (CloneNotSupportedException ex) { + } catch (final CloneNotSupportedException ex) { throw new RuntimeException(ex); } } @@ -65,58 +67,58 @@ public class DeltaSyndFeedInfo extends SyndFeedInfo { /** * Overrides super class method to update changedMap and entryTagsMap for tracking changed entries. * - * @param feed + * @param feed */ @Override - public final synchronized void setSyndFeed(SyndFeed feed) { + public final synchronized void setSyndFeed(final SyndFeed feed) { super.setSyndFeed(feed); - - changedMap.clear(); - List entries = feed.getEntries(); - for (SyndEntry entry : entries) { - String currentEntryTag = computeEntryTag(entry); - String previousEntryTag = entryTagsMap.get(entry.getUri()); - if ((previousEntryTag == null) || (!(currentEntryTag.equals(previousEntryTag)))) { - //Entry has changed + changedMap.clear(); + final List entries = feed.getEntries(); + for (final SyndEntry entry : entries) { + final String currentEntryTag = computeEntryTag(entry); + final String previousEntryTag = entryTagsMap.get(entry.getUri()); + + if (previousEntryTag == null || !currentEntryTag.equals(previousEntryTag)) { + // Entry has changed changedMap.put(entry.getUri(), Boolean.TRUE); } entryTagsMap.put(entry.getUri(), currentEntryTag); } } - - private String computeEntryTag(SyndEntry entry) { - //Following hash algorithm suggested by Robert Cooper needs to be evaluated in future. -// int hash = ( entry.getUri() != null ? entry.getUri().hashCode() : entry.getLink().hashCode() ) ^ -// (entry.getUpdatedDate() != null ? entry.getUpdatedDate().hashCode() : entry.getPublishedDate().hashCode()) ^ -// entry.getTitle().hashCode() ^ -// entry.getDescription().hashCode(); + private String computeEntryTag(final SyndEntry entry) { - - String id = entry.getUri(); + // Following hash algorithm suggested by Robert Cooper needs to be evaluated in future. + // int hash = ( entry.getUri() != null ? entry.getUri().hashCode() : entry.getLink().hashCode() ) ^ + // (entry.getUpdatedDate() != null ? entry.getUpdatedDate().hashCode() : entry.getPublishedDate().hashCode()) ^ + // entry.getTitle().hashCode() ^ + // entry.getDescription().hashCode(); + + final String id = entry.getUri(); Date updateDate = entry.getUpdatedDate(); - Date publishedDate = entry.getPublishedDate(); + final Date publishedDate = entry.getPublishedDate(); if (updateDate == null) { if (publishedDate != null) { updateDate = publishedDate; - } else { - //For misbehaving feeds that do not set updateDate or publishedDate we use current tiem which pretty mucg assures that it will be viewed as changed even when it is not + } else { + // For misbehaving feeds that do not set updateDate or publishedDate we use current tiem which pretty mucg assures that it will be viewed as + // changed even when it is not updateDate = new Date(); } } - String key = id + ":" + entry.getUpdatedDate(); - return computeDigest(key); + final String key = id + ":" + entry.getUpdatedDate(); + return computeDigest(key); } - - private String computeDigest(String content) { + + private String computeDigest(final String content) { try { - MessageDigest md = MessageDigest.getInstance("SHA"); - byte[] digest = md.digest(content.getBytes()); - BigInteger bi = new BigInteger(digest); + final MessageDigest md = MessageDigest.getInstance("SHA"); + final byte[] digest = md.digest(content.getBytes()); + final BigInteger bi = new BigInteger(digest); return bi.toString(16); - } catch (Exception e) { + } catch (final Exception e) { return ""; } - } + } } diff --git a/src/main/java/org/rometools/certiorem/hub/Hub.java b/src/main/java/org/rometools/certiorem/hub/Hub.java index 480359b..da5b446 100644 --- a/src/main/java/org/rometools/certiorem/hub/Hub.java +++ b/src/main/java/org/rometools/certiorem/hub/Hub.java @@ -18,21 +18,9 @@ package org.rometools.certiorem.hub; -import com.sun.syndication.feed.synd.SyndFeed; - -import org.rometools.certiorem.HttpStatusCodeException; -import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; -import org.rometools.certiorem.hub.Verifier.VerificationCallback; -import org.rometools.certiorem.hub.data.HubDAO; -import org.rometools.certiorem.hub.data.Subscriber; -import org.rometools.certiorem.hub.data.SubscriptionSummary; - -import org.rometools.fetcher.FeedFetcher; - import java.net.URI; import java.net.URISyntaxException; import java.net.URL; - import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -40,12 +28,20 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; +import org.rometools.certiorem.hub.Verifier.VerificationCallback; +import org.rometools.certiorem.hub.data.HubDAO; +import org.rometools.certiorem.hub.data.Subscriber; +import org.rometools.certiorem.hub.data.SubscriptionSummary; +import org.rometools.fetcher.FeedFetcher; + +import com.sun.syndication.feed.synd.SyndFeed; /** - * The basic business logic controller for the Hub implementation. It is intended - * to be usable under a very thin servlet wrapper, or other, non-HTTP notification - * methods you might want to use. - * + * The basic business logic controller for the Hub implementation. It is intended to be usable under a very thin servlet wrapper, or other, non-HTTP + * notification methods you might want to use. + * * @author robert.cooper */ public class Hub { @@ -66,6 +62,7 @@ public class Hub { /** * Constructs a new Hub instance + * * @param dao The persistence HubDAO to use * @param verifier The verification strategy to use. */ @@ -74,122 +71,111 @@ public class Hub { this.verifier = verifier; this.notifier = notifier; this.fetcher = fetcher; - this.validSchemes = STANDARD_SCHEMES; - this.validPorts = Collections.EMPTY_SET; - this.validTopics = Collections.EMPTY_SET; + validSchemes = STANDARD_SCHEMES; + validPorts = Collections.EMPTY_SET; + validTopics = Collections.EMPTY_SET; } /** * Constructs a new Hub instance. + * * @param dao The persistence HubDAO to use * @param verifier The verification strategy to use * @param validSchemes A list of valid URI schemes for callbacks (default: http, https) * @param validPorts A list of valid port numbers for callbacks (default: any) * @param validTopics A set of valid topic URIs which can be subscribed to (default: any) */ - public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher, - final Set validSchemes, final Set validPorts, final Set validTopics) { + public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher, final Set validSchemes, + final Set validPorts, final Set validTopics) { this.dao = dao; this.verifier = verifier; this.notifier = notifier; this.fetcher = fetcher; - Set readOnlySchemes = Collections.unmodifiableSet(validSchemes); - this.validSchemes = (readOnlySchemes == null) ? STANDARD_SCHEMES : readOnlySchemes; + final Set readOnlySchemes = Collections.unmodifiableSet(validSchemes); + this.validSchemes = readOnlySchemes == null ? STANDARD_SCHEMES : readOnlySchemes; - Set readOnlyPorts = Collections.unmodifiableSet(validPorts); - this.validPorts = (readOnlyPorts == null) ? Collections.EMPTY_SET : readOnlyPorts; + final Set readOnlyPorts = Collections.unmodifiableSet(validPorts); + this.validPorts = readOnlyPorts == null ? Collections.EMPTY_SET : readOnlyPorts; - Set readOnlyTopics = Collections.unmodifiableSet(validTopics); - this.validTopics = (readOnlyTopics == null) ? Collections.EMPTY_SET : readOnlyTopics; + final Set readOnlyTopics = Collections.unmodifiableSet(validTopics); + this.validTopics = readOnlyTopics == null ? Collections.EMPTY_SET : readOnlyTopics; } /** * Sends a notification to the subscribers + * * @param requestHost the host name the hub is running on. (Used for the user agent) * @param topic the URL of the topic that was updated. * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the request. */ - public void sendNotification(String requestHost, final String topic) { - assert this.validTopics.isEmpty() || this.validTopics.contains(topic) : "That topic is not supported by this hub. " + - topic; + public void sendNotification(final String requestHost, final String topic) { + assert validTopics.isEmpty() || validTopics.contains(topic) : "That topic is not supported by this hub. " + topic; Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Sending notification for {0}", topic); try { - List subscribers = dao.subscribersForTopic(topic); + final List subscribers = dao.subscribersForTopic(topic); if (subscribers.isEmpty()) { Logger.getLogger(Hub.class.getName()).log(Level.FINE, "No subscribers to notify for {0}", topic); return; } - List summaries = (List) dao.summariesForTopic(topic); + final List summaries = (List) dao.summariesForTopic(topic); int total = 0; - StringBuilder hosts = new StringBuilder(); + final StringBuilder hosts = new StringBuilder(); - for (SubscriptionSummary s : summaries) { + for (final SubscriptionSummary s : summaries) { if (s.getSubscribers() > 0) { total += s.getSubscribers(); - hosts.append(" (") - .append(s.getHost()) - .append("; ") - .append(s.getSubscribers()) - .append(" subscribers)"); + hosts.append(" (").append(s.getHost()).append("; ").append(s.getSubscribers()).append(" subscribers)"); } } - StringBuilder userAgent = new StringBuilder("ROME-Certiorem (+http://").append(requestHost) - .append("; ") - .append(total) - .append(" subscribers)") - .append(hosts); - SyndFeed feed = fetcher.retrieveFeed(userAgent.toString(), new URL(topic)); - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Got feed for {0} Sending to {1} subscribers.", new Object[]{topic, subscribers.size()}); - this.notifier.notifySubscribers((List) subscribers, feed, - new SubscriptionSummaryCallback() { - @Override - public void onSummaryInfo(SubscriptionSummary summary) { - dao.handleSummary(topic, summary); - } - }); - } catch (Exception ex) { - Logger.getLogger(Hub.class.getName()) - .log(Level.SEVERE, "Exception getting " + topic, ex); + final StringBuilder userAgent = new StringBuilder("ROME-Certiorem (+http://").append(requestHost).append("; ").append(total) + .append(" subscribers)").append(hosts); + final SyndFeed feed = fetcher.retrieveFeed(userAgent.toString(), new URL(topic)); + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Got feed for {0} Sending to {1} subscribers.", new Object[] { topic, subscribers.size() }); + notifier.notifySubscribers((List) subscribers, feed, new SubscriptionSummaryCallback() { + @Override + public void onSummaryInfo(final SubscriptionSummary summary) { + dao.handleSummary(topic, summary); + } + }); + } catch (final Exception ex) { + Logger.getLogger(Hub.class.getName()).log(Level.SEVERE, "Exception getting " + topic, ex); throw new HttpStatusCodeException(500, ex.getMessage(), ex); } } /** * Subscribes to a topic. + * * @param callback Callback URI * @param topic Topic URI * @param verify Verification Type * @param lease_seconds Duration of the lease * @param secret Secret value * @param verify_token verify_token; - * @return Boolean.TRUE if the subscription succeeded synchronously, - * Boolean.FALSE if the subscription failed synchronously, or null if the request is asynchronous. + * @return Boolean.TRUE if the subscription succeeded synchronously, Boolean.FALSE if the subscription failed synchronously, or null if the request is + * asynchronous. * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the request. */ - public Boolean subscribe(String callback, String topic, String verify, long lease_seconds, String secret, - String verify_token) { - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "{0} wants to subscribe to {1}", new Object[]{callback, topic}); + public Boolean subscribe(final String callback, final String topic, final String verify, final long lease_seconds, final String secret, + final String verify_token) { + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "{0} wants to subscribe to {1}", new Object[] { callback, topic }); try { try { assert callback != null : "Callback URL is required."; assert topic != null : "Topic URL is required."; - URI uri = new URI(callback); - assert this.validSchemes.contains(uri.getScheme()) : "Not a valid protocol " + uri.getScheme(); - assert this.validPorts.isEmpty() || this.validPorts.contains(uri.getPort()) : "Not a valid port " + - uri.getPort(); - assert this.validTopics.isEmpty() || this.validTopics.contains(topic) : "Not a supported topic " + - topic; - } catch (URISyntaxException ex) { + final URI uri = new URI(callback); + assert validSchemes.contains(uri.getScheme()) : "Not a valid protocol " + uri.getScheme(); + assert validPorts.isEmpty() || validPorts.contains(uri.getPort()) : "Not a valid port " + uri.getPort(); + assert validTopics.isEmpty() || validTopics.contains(topic) : "Not a supported topic " + topic; + } catch (final URISyntaxException ex) { assert false : "Not a valid URI " + callback; } - assert (verify != null) && - (verify.equals(Subscriber.VERIFY_ASYNC) || verify.equals(Subscriber.VERIFY_SYNC)) : "Unexpected verify value " + - verify; + assert verify != null && (verify.equals(Subscriber.VERIFY_ASYNC) || verify.equals(Subscriber.VERIFY_SYNC)) : "Unexpected verify value " + verify; final Subscriber subscriber = new Subscriber(); subscriber.setCallback(callback); @@ -199,18 +185,19 @@ public class Hub { subscriber.setVerify(verify); subscriber.setVertifyToken(verify_token); - VerificationCallback verified = new VerificationCallback() { - @Override - public void onVerify(boolean verified) { - if (verified) { - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Verified {0} subscribed to {1}", new Object[]{subscriber.getCallback(), subscriber.getTopic()}); - dao.addSubscriber(subscriber); - } + final VerificationCallback verified = new VerificationCallback() { + @Override + public void onVerify(final boolean verified) { + if (verified) { + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Verified {0} subscribed to {1}", + new Object[] { subscriber.getCallback(), subscriber.getTopic() }); + dao.addSubscriber(subscriber); } - }; + } + }; if (Subscriber.VERIFY_SYNC.equals(subscriber.getVerify())) { - boolean result = verifier.verifySubcribeSyncronously(subscriber); + final boolean result = verifier.verifySubcribeSyncronously(subscriber); verified.onVerify(result); return result; @@ -219,33 +206,34 @@ public class Hub { return null; } - } catch (AssertionError ae) { + } catch (final AssertionError ae) { throw new HttpStatusCodeException(400, ae.getMessage(), ae); - } catch (Exception e) { + } catch (final Exception e) { throw new HttpStatusCodeException(500, e.getMessage(), e); } } - public Boolean unsubscribe(final String callback, final String topic, String verify, String secret, String verifyToken) { + public Boolean unsubscribe(final String callback, final String topic, final String verify, final String secret, final String verifyToken) { final Subscriber subscriber = dao.findSubscriber(topic, callback); - if(subscriber == null){ + if (subscriber == null) { throw new HttpStatusCodeException(400, "Not a valid subscription.", null); } subscriber.setVertifyToken(verifyToken); subscriber.setSecret(secret); - if(Subscriber.VERIFY_SYNC.equals(verify)){ + if (Subscriber.VERIFY_SYNC.equals(verify)) { - boolean ret = verifier.verifyUnsubcribeSyncronously(subscriber); - if(ret){ + final boolean ret = verifier.verifyUnsubcribeSyncronously(subscriber); + if (ret) { dao.removeSubscriber(topic, callback); } } else { - verifier.verifyUnsubscribeAsyncronously(subscriber, new VerificationCallback(){ + verifier.verifyUnsubscribeAsyncronously(subscriber, new VerificationCallback() { @Override - public void onVerify(boolean verified) { - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Unsubscribe for {0} at {1} verified {2}", new Object[]{subscriber.getTopic(), subscriber.getCallback(), verified}); - if(verified){ + public void onVerify(final boolean verified) { + Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Unsubscribe for {0} at {1} verified {2}", + new Object[] { subscriber.getTopic(), subscriber.getCallback(), verified }); + if (verified) { dao.removeSubscriber(topic, callback); } } diff --git a/src/main/java/org/rometools/certiorem/hub/Notifier.java b/src/main/java/org/rometools/certiorem/hub/Notifier.java index cebd93f..dfc01fb 100644 --- a/src/main/java/org/rometools/certiorem/hub/Notifier.java +++ b/src/main/java/org/rometools/certiorem/hub/Notifier.java @@ -18,22 +18,21 @@ package org.rometools.certiorem.hub; -import com.sun.syndication.feed.synd.SyndFeed; +import java.util.List; import org.rometools.certiorem.hub.data.Subscriber; import org.rometools.certiorem.hub.data.SubscriptionSummary; -import java.util.List; - +import com.sun.syndication.feed.synd.SyndFeed; /** - * + * * @author robert.cooper */ public interface Notifier { /** * Instructs the notifier to begin sending notifications to the list of subscribers - * + * * @param subscribers Subscribers to notify * @param value The SyndFeed to send them * @param callback A callback that is invoked each time a subscriber is notified. @@ -41,11 +40,11 @@ public interface Notifier { public void notifySubscribers(List subscribers, SyndFeed value, SubscriptionSummaryCallback callback); /** - * A callback that is invoked each time a subscriber is notified. + * A callback that is invoked each time a subscriber is notified. */ public static interface SubscriptionSummaryCallback { /** - * + * * @param summary A summary of the data received from the subscriber */ public void onSummaryInfo(SubscriptionSummary summary); diff --git a/src/main/java/org/rometools/certiorem/hub/Verifier.java b/src/main/java/org/rometools/certiorem/hub/Verifier.java index ddc15ed..fe79e78 100644 --- a/src/main/java/org/rometools/certiorem/hub/Verifier.java +++ b/src/main/java/org/rometools/certiorem/hub/Verifier.java @@ -20,9 +20,9 @@ package org.rometools.certiorem.hub; import org.rometools.certiorem.hub.data.Subscriber; - /** * A strategy interface for verification of subscriptions. + * * @author robert.cooper */ public interface Verifier { @@ -38,6 +38,7 @@ public interface Verifier { /** * Verifies a subscriber (possibly) asyncronously + * * @param subscriber the Subscriber to verify * @param callback a callback with the result of the verification. */ @@ -45,32 +46,34 @@ public interface Verifier { /** * Verifies a subscriber syncronously - * @param subscriber The subscriber data + * + * @param subscriber The subscriber data * @return boolean result; */ public boolean verifySubcribeSyncronously(Subscriber subscriber); /** * Verifies am unsubscribe (possibly) asyncronously + * * @param subscriber The subscriber data * @param callback result */ public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback); - /** + /** * Verifies an unsubscribe syncronously - * @param subscriber The subscriber data + * + * @param subscriber The subscriber data * @return boolean result; */ public boolean verifyUnsubcribeSyncronously(Subscriber subscriber); - /** * An interface for capturing the result of a verification (subscribe or unsubscribe) */ public static interface VerificationCallback { /** - * + * * @param verified success state of the verification */ public void onVerify(boolean verified); diff --git a/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java b/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java index 95c255f..bd23698 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java +++ b/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java @@ -16,13 +16,12 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.data; import java.util.List; /** - * + * * @author robert.cooper */ public interface HubDAO { diff --git a/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java b/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java index fb3e4a3..ed56456 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java +++ b/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java @@ -20,9 +20,8 @@ package org.rometools.certiorem.hub.data; import java.io.Serializable; - /** - * + * * @author robert.cooper */ public class Subscriber implements Serializable { @@ -38,132 +37,132 @@ public class Subscriber implements Serializable { /** * Set the value of callback - * + * * @param newcallback new value of callback */ - public void setCallback(String newcallback) { - this.callback = newcallback; + public void setCallback(final String newcallback) { + callback = newcallback; } /** * Get the value of callback - * + * * @return the value of callback */ public String getCallback() { - return this.callback; + return callback; } /** * Set the value of creationTime - * + * * @param newcreationTime new value of creationTime */ - public void setCreationTime(long newcreationTime) { - this.creationTime = newcreationTime; + public void setCreationTime(final long newcreationTime) { + creationTime = newcreationTime; } /** * Get the value of creationTime - * + * * @return the value of creationTime */ public long getCreationTime() { - return this.creationTime; + return creationTime; } /** * Set the value of leaseSeconds - * + * * @param newleaseSeconds new value of leaseSeconds */ - public void setLeaseSeconds(long newleaseSeconds) { - this.leaseSeconds = newleaseSeconds; + public void setLeaseSeconds(final long newleaseSeconds) { + leaseSeconds = newleaseSeconds; } /** * Get the value of leaseSeconds - * + * * @return the value of leaseSeconds */ public long getLeaseSeconds() { - return this.leaseSeconds; + return leaseSeconds; } /** * Set the value of secret - * + * * @param newsecret new value of secret */ - public void setSecret(String newsecret) { - this.secret = newsecret; + public void setSecret(final String newsecret) { + secret = newsecret; } /** * Get the value of secret - * + * * @return the value of secret */ public String getSecret() { - return this.secret; + return secret; } /** * Set the value of topic - * + * * @param newtopic new value of topic */ - public void setTopic(String newtopic) { - this.topic = newtopic; + public void setTopic(final String newtopic) { + topic = newtopic; } /** * Get the value of topic - * + * * @return the value of topic */ public String getTopic() { - return this.topic; + return topic; } /** * Set the value of verify - * + * * @param newverify new value of verify */ - public void setVerify(String newverify) { - this.verify = newverify; + public void setVerify(final String newverify) { + verify = newverify; } /** * Get the value of verify - * + * * @return the value of verify */ public String getVerify() { - return this.verify; + return verify; } /** * Set the value of vertifyToken - * + * * @param newvertifyToken new value of vertifyToken */ - public void setVertifyToken(String newvertifyToken) { - this.vertifyToken = newvertifyToken; + public void setVertifyToken(final String newvertifyToken) { + vertifyToken = newvertifyToken; } /** * Get the value of vertifyToken - * + * * @return the value of vertifyToken */ public String getVertifyToken() { - return this.vertifyToken; + return vertifyToken; } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (obj == null) { return false; } @@ -174,31 +173,31 @@ public class Subscriber implements Serializable { final Subscriber other = (Subscriber) obj; - if ((this.callback == null) ? (other.callback != null) : (!this.callback.equals(other.callback))) { + if (callback == null ? other.callback != null : !callback.equals(other.callback)) { return false; } - if ((this.secret == null) ? (other.secret != null) : (!this.secret.equals(other.secret))) { + if (secret == null ? other.secret != null : !secret.equals(other.secret)) { return false; } - if ((this.topic == null) ? (other.topic != null) : (!this.topic.equals(other.topic))) { + if (topic == null ? other.topic != null : !topic.equals(other.topic)) { return false; } - if ((this.verify == null) ? (other.verify != null) : (!this.verify.equals(other.verify))) { + if (verify == null ? other.verify != null : !verify.equals(other.verify)) { return false; } - if ((this.vertifyToken == null) ? (other.vertifyToken != null) : (!this.vertifyToken.equals(other.vertifyToken))) { + if (vertifyToken == null ? other.vertifyToken != null : !vertifyToken.equals(other.vertifyToken)) { return false; } - if (this.creationTime != other.creationTime) { + if (creationTime != other.creationTime) { return false; } - if (this.leaseSeconds != other.leaseSeconds) { + if (leaseSeconds != other.leaseSeconds) { return false; } @@ -208,13 +207,13 @@ public class Subscriber implements Serializable { @Override public int hashCode() { int hash = 7; - hash = (67 * hash) + ((this.callback != null) ? this.callback.hashCode() : 0); - hash = (67 * hash) + ((this.secret != null) ? this.secret.hashCode() : 0); - hash = (67 * hash) + ((this.topic != null) ? this.topic.hashCode() : 0); - hash = (67 * hash) + ((this.verify != null) ? this.verify.hashCode() : 0); - hash = (67 * hash) + ((this.vertifyToken != null) ? this.vertifyToken.hashCode() : 0); - hash = (67 * hash) + (int) (this.creationTime ^ (this.creationTime >>> 32)); - hash = (67 * hash) + (int) (this.leaseSeconds ^ (this.leaseSeconds >>> 32)); + hash = 67 * hash + (callback != null ? callback.hashCode() : 0); + hash = 67 * hash + (secret != null ? secret.hashCode() : 0); + hash = 67 * hash + (topic != null ? topic.hashCode() : 0); + hash = 67 * hash + (verify != null ? verify.hashCode() : 0); + hash = 67 * hash + (vertifyToken != null ? vertifyToken.hashCode() : 0); + hash = 67 * hash + (int) (creationTime ^ creationTime >>> 32); + hash = 67 * hash + (int) (leaseSeconds ^ leaseSeconds >>> 32); return hash; } diff --git a/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java b/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java index c826f40..90dd65d 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java +++ b/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java @@ -20,9 +20,8 @@ package org.rometools.certiorem.hub.data; import java.io.Serializable; - /** - * + * * @author robert.cooper */ public class SubscriptionSummary implements Serializable { @@ -32,55 +31,55 @@ public class SubscriptionSummary implements Serializable { /** * Set the value of host - * + * * @param newhost new value of host */ - public void setHost(String newhost) { - this.host = newhost; + public void setHost(final String newhost) { + host = newhost; } /** * Get the value of host - * + * * @return the value of host */ public String getHost() { - return this.host; + return host; } /** * Set the value of lastPublishSuccessful - * + * * @param newlastPublishSuccessful new value of lastPublishSuccessful */ - public void setLastPublishSuccessful(boolean newlastPublishSuccessful) { - this.lastPublishSuccessful = newlastPublishSuccessful; + public void setLastPublishSuccessful(final boolean newlastPublishSuccessful) { + lastPublishSuccessful = newlastPublishSuccessful; } /** * Get the value of lastPublishSuccessful - * + * * @return the value of lastPublishSuccessful */ public boolean isLastPublishSuccessful() { - return this.lastPublishSuccessful; + return lastPublishSuccessful; } /** * Set the value of subscribers - * + * * @param newsubscribers new value of subscribers */ - public void setSubscribers(int newsubscribers) { - this.subscribers = newsubscribers; + public void setSubscribers(final int newsubscribers) { + subscribers = newsubscribers; } /** * Get the value of subscribers - * + * * @return the value of subscribers */ public int getSubscribers() { - return this.subscribers; + return subscribers; } } diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java index c33eca3..b8d6c50 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java +++ b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java @@ -16,12 +16,8 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.data.jpa; -import org.rometools.certiorem.hub.data.HubDAO; -import org.rometools.certiorem.hub.data.Subscriber; - import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -31,10 +27,13 @@ import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.NoResultException; import javax.persistence.Query; + +import org.rometools.certiorem.hub.data.HubDAO; +import org.rometools.certiorem.hub.data.Subscriber; import org.rometools.certiorem.hub.data.SubscriptionSummary; /** - * + * * @author robert.cooper */ public class JPADAO implements HubDAO { @@ -48,41 +47,39 @@ public class JPADAO implements HubDAO { } @Override - public List subscribersForTopic(String topic) { - LinkedList result = new LinkedList(); - EntityManager em = factory.createEntityManager(); - EntityTransaction tx = em.getTransaction(); + public List subscribersForTopic(final String topic) { + final LinkedList result = new LinkedList(); + final EntityManager em = factory.createEntityManager(); + final EntityTransaction tx = em.getTransaction(); tx.begin(); - Query query = em.createNamedQuery("Subcriber.forTopic"); + final Query query = em.createNamedQuery("Subcriber.forTopic"); query.setParameter("topic", topic); try { - for (JPASubscriber subscriber : (List) query.getResultList()) { + for (final JPASubscriber subscriber : (List) query.getResultList()) { if (subscriber.getLeaseSeconds() == -1) { result.add(subscriber); continue; } - if (subscriber.getSubscribedAt().getTime() < (System.currentTimeMillis() - (1000 * subscriber.getLeaseSeconds()))) { + if (subscriber.getSubscribedAt().getTime() < System.currentTimeMillis() - 1000 * subscriber.getLeaseSeconds()) { subscriber.setExpired(true); } else { result.add(subscriber); } - if (subscriber.isExpired() && this.purgeExpired) { + if (subscriber.isExpired() && purgeExpired) { em.remove(subscriber); } } - } catch (NoResultException e) { + } catch (final NoResultException e) { tx.rollback(); em.close(); return result; } - - if (!tx.getRollbackOnly()) { tx.commit(); } else { @@ -95,12 +92,12 @@ public class JPADAO implements HubDAO { } @Override - public Subscriber addSubscriber(Subscriber subscriber) { + public Subscriber addSubscriber(final Subscriber subscriber) { assert subscriber != null : "Attempt to store a null subscriber"; - EntityManager em = factory.createEntityManager(); - EntityTransaction tx = em.getTransaction(); + final EntityManager em = factory.createEntityManager(); + final EntityTransaction tx = em.getTransaction(); tx.begin(); - JPASubscriber data = new JPASubscriber(); + final JPASubscriber data = new JPASubscriber(); data.copyFrom(subscriber); data.setId(UUID.randomUUID().toString()); em.persist(data); @@ -110,22 +107,22 @@ public class JPADAO implements HubDAO { } @Override - public Subscriber findSubscriber(String topic, String callbackUrl) { + public Subscriber findSubscriber(final String topic, final String callbackUrl) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public void handleSummary(String topic, SubscriptionSummary summary) { + public void handleSummary(final String topic, final SubscriptionSummary summary) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public List summariesForTopic(String topic) { + public List summariesForTopic(final String topic) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public void removeSubscriber(String topic, String callback) { + public void removeSubscriber(final String topic, final String callback) { throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java index 5980f48..6b8621a 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java +++ b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java @@ -16,13 +16,9 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.data.jpa; -import org.rometools.certiorem.hub.data.Subscriber; - import java.io.Serializable; - import java.util.Date; import javax.persistence.Entity; @@ -32,14 +28,14 @@ import javax.persistence.NamedQuery; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ @Entity -@NamedQueries({@NamedQuery(name = "Subcriber.forTopic", query = "SELECT o FROM JPASubscriber o WHERE o.topic = :topic AND o.expired = false ORDER BY o.subscribedAt") -}) +@NamedQueries({ @NamedQuery(name = "Subcriber.forTopic", query = "SELECT o FROM JPASubscriber o WHERE o.topic = :topic AND o.expired = false ORDER BY o.subscribedAt") }) public class JPASubscriber extends Subscriber implements Serializable { private Date subscribedAt = new Date(); private String id; @@ -47,65 +43,65 @@ public class JPASubscriber extends Subscriber implements Serializable { /** * Set the value of expired - * + * * @param newexpired new value of expired */ - public void setExpired(boolean newexpired) { - this.expired = newexpired; + public void setExpired(final boolean newexpired) { + expired = newexpired; } /** * Get the value of expired - * + * * @return the value of expired */ public boolean isExpired() { - return this.expired; + return expired; } /** * Set the value of id - * + * * @param newid new value of id */ - public void setId(String newid) { - this.id = newid; + public void setId(final String newid) { + id = newid; } /** * Get the value of id - * + * * @return the value of id */ @Id public String getId() { - return this.id; + return id; } /** * Set the value of subscribedAt - * + * * @param newsubscribedAt new value of subscribedAt */ - public void setSubscribedAt(Date newsubscribedAt) { - this.subscribedAt = newsubscribedAt; + public void setSubscribedAt(final Date newsubscribedAt) { + subscribedAt = newsubscribedAt; } /** * Get the value of subscribedAt - * + * * @return the value of subscribedAt */ @Temporal(TemporalType.TIMESTAMP) public Date getSubscribedAt() { - return this.subscribedAt; + return subscribedAt; } - public void copyFrom(Subscriber source) { - this.setLeaseSeconds(source.getLeaseSeconds()); - this.setSecret(source.getSecret()); - this.setTopic(source.getTopic()); - this.setVerify(source.getVerify()); - this.setVertifyToken(source.getVertifyToken()); + public void copyFrom(final Subscriber source) { + setLeaseSeconds(source.getLeaseSeconds()); + setSecret(source.getSecret()); + setTopic(source.getTopic()); + setVerify(source.getVerify()); + setVertifyToken(source.getVertifyToken()); } } diff --git a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java b/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java index a7f484d..44497db 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java +++ b/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java @@ -18,36 +18,35 @@ package org.rometools.certiorem.hub.data.ram; -import org.rometools.certiorem.hub.data.HubDAO; -import org.rometools.certiorem.hub.data.Subscriber; -import org.rometools.certiorem.hub.data.SubscriptionSummary; - import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; +import org.rometools.certiorem.hub.data.HubDAO; +import org.rometools.certiorem.hub.data.Subscriber; +import org.rometools.certiorem.hub.data.SubscriptionSummary; /** * A Simple In-Memory HubDAO for subscribers. - * + * * @author robert.cooper */ public class InMemoryHubDAO implements HubDAO { - private ConcurrentHashMap> subscribers = new ConcurrentHashMap>(); - private ConcurrentHashMap> summaries = new ConcurrentHashMap>(); + private final ConcurrentHashMap> subscribers = new ConcurrentHashMap>(); + private final ConcurrentHashMap> summaries = new ConcurrentHashMap>(); @Override - public Subscriber addSubscriber(Subscriber subscriber) { + public Subscriber addSubscriber(final Subscriber subscriber) { assert subscriber != null : "Attempt to store a null subscriber"; - List subList = this.subscribers.get(subscriber.getTopic()); + List subList = subscribers.get(subscriber.getTopic()); if (subList == null) { synchronized (this) { subList = new CopyOnWriteArrayList(); - this.subscribers.put(subscriber.getTopic(), subList); + subscribers.put(subscriber.getTopic(), subList); } } @@ -57,13 +56,13 @@ public class InMemoryHubDAO implements HubDAO { } @Override - public void handleSummary(String topic, SubscriptionSummary summary) { - ConcurrentHashMap hostsToSummaries = this.summaries.get(topic); + public void handleSummary(final String topic, final SubscriptionSummary summary) { + ConcurrentHashMap hostsToSummaries = summaries.get(topic); if (hostsToSummaries == null) { synchronized (this) { hostsToSummaries = new ConcurrentHashMap(); - this.summaries.put(topic, hostsToSummaries); + summaries.put(topic, hostsToSummaries); } } @@ -71,14 +70,13 @@ public class InMemoryHubDAO implements HubDAO { } @Override - public List subscribersForTopic(String topic) { + public List subscribersForTopic(final String topic) { if (subscribers.containsKey(topic)) { - List result = new LinkedList(); - LinkedList expired = new LinkedList(); + final List result = new LinkedList(); + final LinkedList expired = new LinkedList(); - for (Subscriber s : subscribers.get(topic)) { - if ((s.getLeaseSeconds() > 0) && - (System.currentTimeMillis() >= (s.getCreationTime() + (s.getLeaseSeconds() * 1000L)))) { + for (final Subscriber s : subscribers.get(topic)) { + if (s.getLeaseSeconds() > 0 && System.currentTimeMillis() >= s.getCreationTime() + s.getLeaseSeconds() * 1000L) { expired.add(s); } else { result.add(s); @@ -86,8 +84,7 @@ public class InMemoryHubDAO implements HubDAO { } if (!expired.isEmpty()) { - subscribers.get(topic) - .removeAll(expired); + subscribers.get(topic).removeAll(expired); } return result; @@ -97,41 +94,41 @@ public class InMemoryHubDAO implements HubDAO { } @Override - public List summariesForTopic(String topic) { - LinkedList result = new LinkedList(); + public List summariesForTopic(final String topic) { + final LinkedList result = new LinkedList(); - if (this.summaries.containsKey(topic)) { - result.addAll(this.summaries.get(topic).values()); + if (summaries.containsKey(topic)) { + result.addAll(summaries.get(topic).values()); } return result; } @Override - public Subscriber findSubscriber(String topic, String callbackUrl) { + public Subscriber findSubscriber(final String topic, final String callbackUrl) { - for (Subscriber s : this.subscribersForTopic(topic)) { + for (final Subscriber s : subscribersForTopic(topic)) { if (callbackUrl.equals(s.getCallback())) { - return s; + return s; } } return null; } @Override - public void removeSubscriber(String topic, String callback) { - List subs = this.subscribers.get(topic); - if(subs == null){ + public void removeSubscriber(final String topic, final String callback) { + final List subs = subscribers.get(topic); + if (subs == null) { return; } Subscriber match = null; - for(Subscriber s: subs){ - if(s.getCallback().equals(callback)){ + for (final Subscriber s : subs) { + if (s.getCallback().equals(callback)) { match = s; break; } } - if(match != null){ + if (match != null) { subs.remove(match); } } diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java index 193063c..7cf9cc0 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java @@ -16,152 +16,140 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.notify.standard; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.SyndFeedOutput; - -import org.rometools.certiorem.hub.Notifier; -import org.rometools.certiorem.hub.data.Subscriber; -import org.rometools.certiorem.hub.data.SubscriptionSummary; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; - import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; - import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import org.rometools.certiorem.sub.data.ram.InMemorySubDAO; +import org.rometools.certiorem.hub.Notifier; +import org.rometools.certiorem.hub.data.Subscriber; +import org.rometools.certiorem.hub.data.SubscriptionSummary; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; /** - * + * * @author robert.cooper */ public abstract class AbstractNotifier implements Notifier { /** - * This method will serialize the synd feed and build Notifications for the - * implementation class to handle. - * @see enqueueNotification - * + * This method will serialize the synd feed and build Notifications for the implementation class to handle. + * + * @see enqueueNotification + * * @param subscribers List of subscribers to notify * @param value The SyndFeed object to send * @param callback A callback that will be invoked each time a subscriber is notified. - * + * */ @Override - public void notifySubscribers(List subscribers, SyndFeed value, SubscriptionSummaryCallback callback) { + public void notifySubscribers(final List subscribers, final SyndFeed value, final SubscriptionSummaryCallback callback) { String mimeType = null; - if (value.getFeedType() - .startsWith("rss")) { + if (value.getFeedType().startsWith("rss")) { mimeType = "application/rss+xml"; } else { mimeType = "application/atom+xml"; } - SyndFeedOutput output = new SyndFeedOutput(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final SyndFeedOutput output = new SyndFeedOutput(); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { output.output(value, new OutputStreamWriter(baos)); baos.close(); - } catch (IOException ex) { - Logger.getLogger(AbstractNotifier.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final IOException ex) { + Logger.getLogger(AbstractNotifier.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException("Unable to output the feed.", ex); - } catch (FeedException ex) { - Logger.getLogger(AbstractNotifier.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final FeedException ex) { + Logger.getLogger(AbstractNotifier.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException("Unable to output the feed.", ex); } - byte[] payload = baos.toByteArray(); + final byte[] payload = baos.toByteArray(); - for (Subscriber s : subscribers) { - Notification not = new Notification(); + for (final Subscriber s : subscribers) { + final Notification not = new Notification(); not.callback = callback; not.lastRun = 0; not.mimeType = mimeType; not.payload = payload; not.retryCount = 0; not.subscriber = s; - this.enqueueNotification(not); + enqueueNotification(not); } } - /** Implementation method that queues/sends a notification - * + + /** + * Implementation method that queues/sends a notification + * * @param not notification to send. */ protected abstract void enqueueNotification(Notification not); /** - * POSTs the payload to the subscriber's callback and returns a - * SubscriptionSummary with subscriber counts (where possible) and the - * success state of the notification. + * POSTs the payload to the subscriber's callback and returns a SubscriptionSummary with subscriber counts (where possible) and the success state of the + * notification. + * * @param subscriber subscriber data. * @param mimeType MIME type for the request * @param payload payload of the feed to send * @return SubscriptionSummary with the returned data. */ - protected SubscriptionSummary postNotification(Subscriber subscriber, String mimeType, byte[] payload) { - SubscriptionSummary result = new SubscriptionSummary(); + protected SubscriptionSummary postNotification(final Subscriber subscriber, final String mimeType, final byte[] payload) { + final SubscriptionSummary result = new SubscriptionSummary(); try { - URL target = new URL(subscriber.getCallback()); + final URL target = new URL(subscriber.getCallback()); Logger.getLogger(AbstractNotifier.class.getName()).log(Level.INFO, "Posting notification to subscriber {0}", subscriber.getCallback()); result.setHost(target.getHost()); - HttpURLConnection connection = (HttpURLConnection) target.openConnection(); + final HttpURLConnection connection = (HttpURLConnection) target.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", mimeType); connection.setDoOutput(true); connection.connect(); - OutputStream os = connection.getOutputStream(); + final OutputStream os = connection.getOutputStream(); os.write(payload); os.close(); - int responseCode = connection.getResponseCode(); - String subscribers = connection.getHeaderField("X-Hub-On-Behalf-Of"); + final int responseCode = connection.getResponseCode(); + final String subscribers = connection.getHeaderField("X-Hub-On-Behalf-Of"); connection.disconnect(); - + if (responseCode != 200) { - Logger.getLogger(AbstractNotifier.class.getName()) - .log(Level.WARNING, "Got code " + responseCode + " from " + target); + Logger.getLogger(AbstractNotifier.class.getName()).log(Level.WARNING, "Got code " + responseCode + " from " + target); result.setLastPublishSuccessful(false); return result; } - - if (subscribers != null) { try { result.setSubscribers(Integer.parseInt(subscribers)); - } catch (NumberFormatException nfe) { - Logger.getLogger(AbstractNotifier.class.getName()) - .log(Level.WARNING, "Invalid subscriber value " + subscribers + " " + target, nfe); + } catch (final NumberFormatException nfe) { + Logger.getLogger(AbstractNotifier.class.getName()).log(Level.WARNING, "Invalid subscriber value " + subscribers + " " + target, nfe); result.setSubscribers(-1); } } else { result.setSubscribers(-1); } - } catch (MalformedURLException ex) { - Logger.getLogger(AbstractNotifier.class.getName()) - .log(Level.WARNING, null, ex); + } catch (final MalformedURLException ex) { + Logger.getLogger(AbstractNotifier.class.getName()).log(Level.WARNING, null, ex); result.setLastPublishSuccessful(false); - } catch (IOException ex) { - Logger.getLogger(AbstractNotifier.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final IOException ex) { + Logger.getLogger(AbstractNotifier.class.getName()).log(Level.SEVERE, null, ex); result.setLastPublishSuccessful(false); } diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java index 470956b..053e091 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java @@ -16,14 +16,13 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.notify.standard; import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ public class Notification { diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java index 7f1c724..d305f5a 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java @@ -16,11 +16,8 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.notify.standard; -import org.rometools.certiorem.hub.data.SubscriptionSummary; - import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.ConcurrentSkipListSet; @@ -28,11 +25,11 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.rometools.certiorem.hub.data.SubscriptionSummary; /** - * A notifier implementation that uses a thread pool to deliver notifications to - * subscribers - * + * A notifier implementation that uses a thread pool to deliver notifications to subscribers + * * @author robert.cooper */ public class ThreadPoolNotifier extends AbstractNotifier { @@ -45,47 +42,47 @@ public class ThreadPoolNotifier extends AbstractNotifier { this(2, 5, 5); } - public ThreadPoolNotifier(int startPoolSize, int maxPoolSize, int queueSize) { - this.exeuctor = new ThreadPoolExecutor(startPoolSize, maxPoolSize, 300, TimeUnit.SECONDS, - new LinkedBlockingQueue(queueSize)); + public ThreadPoolNotifier(final int startPoolSize, final int maxPoolSize, final int queueSize) { + exeuctor = new ThreadPoolExecutor(startPoolSize, maxPoolSize, 300, TimeUnit.SECONDS, new LinkedBlockingQueue(queueSize)); } protected ThreadPoolNotifier(final ThreadPoolExecutor executor) { - this.exeuctor = executor; + exeuctor = executor; } /** - * Enqueues a notification to run. If the notification fails, it will be - * retried every two minutes until 5 attempts are completed. Notifications - * to the same callback should be delivered successfully in order. + * Enqueues a notification to run. If the notification fails, it will be retried every two minutes until 5 attempts are completed. Notifications to the same + * callback should be delivered successfully in order. + * * @param not */ @Override protected void enqueueNotification(final Notification not) { - Runnable r = new Runnable() { - @Override - public void run() { - not.lastRun = System.currentTimeMillis(); + final Runnable r = new Runnable() { + @Override + public void run() { + not.lastRun = System.currentTimeMillis(); - SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload); + final SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload); - if (!summary.isLastPublishSuccessful()) { - not.retryCount++; + if (!summary.isLastPublishSuccessful()) { + not.retryCount++; - if (not.retryCount <= 5) { - retry(not); - } + if (not.retryCount <= 5) { + retry(not); } - - not.callback.onSummaryInfo(summary); } - }; - this.exeuctor.execute(r); + not.callback.onSummaryInfo(summary); + } + }; + + exeuctor.execute(r); } /** * Schedules a notification to retry in two minutes. + * * @param not Notification to retry */ protected void retry(final Notification not) { @@ -94,21 +91,21 @@ public class ThreadPoolNotifier extends AbstractNotifier { // will schedule the retry pendings.add(not.subscriber.getCallback()); timer.schedule(new TimerTask() { - @Override - public void run() { - pendings.remove(not.subscriber.getCallback()); - enqueueNotification(not); - } - }, TWO_MINUTES); + @Override + public void run() { + pendings.remove(not.subscriber.getCallback()); + enqueueNotification(not); + } + }, TWO_MINUTES); } else { // There is a retry in front of this one, so we will just schedule // it to retry again in a bit timer.schedule(new TimerTask() { - @Override - public void run() { - retry(not); - } - }, TWO_MINUTES); + @Override + public void run() { + retry(not); + } + }, TWO_MINUTES); } } } diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java index df5a19b..303bf9d 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java @@ -18,32 +18,30 @@ package org.rometools.certiorem.hub.notify.standard; -import org.rometools.certiorem.hub.data.SubscriptionSummary; - import java.util.concurrent.ConcurrentSkipListSet; +import org.rometools.certiorem.hub.data.SubscriptionSummary; /** * A notifier that does not use threads. All calls are blocking and synchronous. - * + * * @author robert.cooper */ public class UnthreadedNotifier extends AbstractNotifier { private final ConcurrentSkipListSet retries = new ConcurrentSkipListSet(); /** - * A blocking call that performs a notification. - * If there are pending retries that are older than two minutes old, they will - * be retried before the method returns. - * + * A blocking call that performs a notification. If there are pending retries that are older than two minutes old, they will be retried before the method + * returns. + * * @param not */ @Override - protected void enqueueNotification(Notification not) { + protected void enqueueNotification(final Notification not) { not.lastRun = System.currentTimeMillis(); - SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload); - + final SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload); + not.callback.onSummaryInfo(summary); } } diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java index 6a8c9a1..528505f 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java @@ -16,91 +16,77 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.verify.standard; -import org.rometools.certiorem.hub.Verifier; -import org.rometools.certiorem.hub.data.Subscriber; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; - import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; - import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; +import org.rometools.certiorem.hub.Verifier; +import org.rometools.certiorem.hub.data.Subscriber; /** - * An abstract verifier based on the java.net HTTP classes. This implements only - * synchronous operations, and expects a child class to do Async ops. + * An abstract verifier based on the java.net HTTP classes. This implements only synchronous operations, and expects a child class to do Async ops. * * @author robert.cooper */ public abstract class AbstractVerifier implements Verifier { @Override - public boolean verifySubcribeSyncronously(Subscriber subscriber) { + public boolean verifySubcribeSyncronously(final Subscriber subscriber) { return doOp(Verifier.MODE_SUBSCRIBE, subscriber); } @Override - public boolean verifyUnsubcribeSyncronously(Subscriber subscriber) { + public boolean verifyUnsubcribeSyncronously(final Subscriber subscriber) { return doOp(Verifier.MODE_UNSUBSCRIBE, subscriber); } - private boolean doOp(String mode, Subscriber subscriber){ + private boolean doOp(final String mode, final Subscriber subscriber) { try { - String challenge = UUID.randomUUID() - .toString(); - StringBuilder queryString = new StringBuilder(); - queryString.append("hub.mode=") - .append(mode) - .append("&hub.topic=") - .append(URLEncoder.encode(subscriber.getTopic(), "UTF-8")) - .append("&hub.challenge=") - .append(challenge); + final String challenge = UUID.randomUUID().toString(); + final StringBuilder queryString = new StringBuilder(); + queryString.append("hub.mode=").append(mode).append("&hub.topic=").append(URLEncoder.encode(subscriber.getTopic(), "UTF-8")) + .append("&hub.challenge=").append(challenge); if (subscriber.getLeaseSeconds() != -1) { - queryString.append("&hub.lease_seconds=") - .append(subscriber.getLeaseSeconds()); + queryString.append("&hub.lease_seconds=").append(subscriber.getLeaseSeconds()); } if (subscriber.getVertifyToken() != null) { - queryString.append("&hub.verify_token=") - .append(URLEncoder.encode(subscriber.getVertifyToken(), "UTF-8")); + queryString.append("&hub.verify_token=").append(URLEncoder.encode(subscriber.getVertifyToken(), "UTF-8")); } - URL url = new URL(subscriber.getCallback() + "?" + queryString.toString()); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + final URL url = new URL(subscriber.getCallback() + "?" + queryString.toString()); + final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); -// connection.setRequestProperty("Host", url.getHost()); -// connection.setRequestProperty("Port", Integer.toString(url.getPort())); + // connection.setRequestProperty("Host", url.getHost()); + // connection.setRequestProperty("Port", Integer.toString(url.getPort())); connection.setRequestProperty("User-Agent", "ROME-Certiorem"); connection.connect(); - int rc = connection.getResponseCode(); - InputStream is = connection.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - String result = reader.readLine(); + final int rc = connection.getResponseCode(); + final InputStream is = connection.getInputStream(); + final BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + final String result = reader.readLine(); reader.close(); connection.disconnect(); - if ((rc != 200) || !challenge.equals(result.trim())) { + if (rc != 200 || !challenge.equals(result.trim())) { return false; } else { return true; } - } catch (UnsupportedEncodingException ex) { - Logger.getLogger(AbstractVerifier.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final UnsupportedEncodingException ex) { + Logger.getLogger(AbstractVerifier.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException("Should not happen. UTF-8 threw unsupported encoding", ex); - } catch (IOException ex) { - Logger.getLogger(AbstractVerifier.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final IOException ex) { + Logger.getLogger(AbstractVerifier.class.getName()).log(Level.SEVERE, null, ex); return false; } diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java index 8bd864c..7bc7452 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java @@ -16,53 +16,51 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.verify.standard; -import org.rometools.certiorem.hub.data.Subscriber; - import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.rometools.certiorem.hub.data.Subscriber; /** * Uses a ThreadPoolExecutor to do async verifications. + * * @author robert.cooper */ public class ThreadPoolVerifier extends AbstractVerifier { protected final ThreadPoolExecutor exeuctor; - protected ThreadPoolVerifier(final ThreadPoolExecutor executor){ - this.exeuctor = executor; + protected ThreadPoolVerifier(final ThreadPoolExecutor executor) { + exeuctor = executor; } - + public ThreadPoolVerifier() { this(2, 5, 5); } - public ThreadPoolVerifier(int startPoolSize, int maxPoolSize, int queueSize) { - this.exeuctor = new ThreadPoolExecutor(startPoolSize, maxPoolSize, 300, TimeUnit.SECONDS, - new LinkedBlockingQueue(queueSize)); + public ThreadPoolVerifier(final int startPoolSize, final int maxPoolSize, final int queueSize) { + exeuctor = new ThreadPoolExecutor(startPoolSize, maxPoolSize, 300, TimeUnit.SECONDS, new LinkedBlockingQueue(queueSize)); } @Override public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { - this.exeuctor.execute(new Runnable() { - @Override - public void run() { - callback.onVerify(verifySubcribeSyncronously(subscriber)); - } - }); + exeuctor.execute(new Runnable() { + @Override + public void run() { + callback.onVerify(verifySubcribeSyncronously(subscriber)); + } + }); } @Override public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { - this.exeuctor.execute(new Runnable() { - @Override - public void run() { - callback.onVerify(verifyUnsubcribeSyncronously(subscriber)); - } - }); + exeuctor.execute(new Runnable() { + @Override + public void run() { + callback.onVerify(verifyUnsubcribeSyncronously(subscriber)); + } + }); } } diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java index a8cd755..4a206fe 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java @@ -21,12 +21,12 @@ package org.rometools.certiorem.hub.verify.standard; import java.util.concurrent.ThreadPoolExecutor; /** - * + * * @author robert.cooper */ -public class ThreadpoolVerifierAdvanced extends ThreadPoolVerifier{ +public class ThreadpoolVerifierAdvanced extends ThreadPoolVerifier { - public ThreadpoolVerifierAdvanced(ThreadPoolExecutor executor){ + public ThreadpoolVerifierAdvanced(final ThreadPoolExecutor executor) { super(executor); } diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java index d0859ee..69b1f19 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java @@ -16,25 +16,24 @@ * limitations under the License. */ - - package org.rometools.certiorem.hub.verify.standard; import org.rometools.certiorem.hub.data.Subscriber; /** * A verifier that does not use threads. Suitable for Google App Engine. + * * @author robert.cooper */ -public class UnthreadedVerifier extends AbstractVerifier{ +public class UnthreadedVerifier extends AbstractVerifier { @Override - public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { callback.onVerify(verifySubcribeSyncronously(subscriber)); } @Override - public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { callback.onVerify(verifyUnsubcribeSyncronously(subscriber)); } diff --git a/src/main/java/org/rometools/certiorem/pub/NotificationException.java b/src/main/java/org/rometools/certiorem/pub/NotificationException.java index 8075e5f..9138694 100644 --- a/src/main/java/org/rometools/certiorem/pub/NotificationException.java +++ b/src/main/java/org/rometools/certiorem/pub/NotificationException.java @@ -16,20 +16,19 @@ * limitations under the License. */ - package org.rometools.certiorem.pub; /** - * + * * @author robert.cooper */ public class NotificationException extends Exception { - public NotificationException(String message){ + public NotificationException(final String message) { super(message); } - public NotificationException(String message, Throwable cause){ + public NotificationException(final String message, final Throwable cause) { super(message, cause); } diff --git a/src/main/java/org/rometools/certiorem/pub/Publisher.java b/src/main/java/org/rometools/certiorem/pub/Publisher.java index bc9f21a..5ac17b6 100644 --- a/src/main/java/org/rometools/certiorem/pub/Publisher.java +++ b/src/main/java/org/rometools/certiorem/pub/Publisher.java @@ -16,28 +16,24 @@ * limitations under the License. */ - package org.rometools.certiorem.pub; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndLink; - import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; - import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; - -import java.util.List; import java.util.concurrent.ThreadPoolExecutor; import java.util.logging.Level; import java.util.logging.Logger; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndLink; /** * A class for sending update notifications to a hub. + * * @author robert.cooper */ public class Publisher { @@ -52,61 +48,57 @@ public class Publisher { /** * Constructs a new publisher with an optional ThreadPoolExector for sending updates. */ - public Publisher(ThreadPoolExecutor executor) { + public Publisher(final ThreadPoolExecutor executor) { this.executor = executor; } /** * Sends the HUB url a notification of a change in topic + * * @param hub URL of the hub to notify. - * @param topic The Topic that has changed + * @param topic The Topic that has changed * @throws NotificationException Any failure */ - public void sendUpdateNotification(String hub, String topic) - throws NotificationException { + public void sendUpdateNotification(final String hub, final String topic) throws NotificationException { try { - StringBuilder sb = new StringBuilder("hub.mode=publish&hub.url=").append(URLEncoder.encode(topic, "UTF-8")); - URL hubUrl = new URL(hub); - HttpURLConnection connection = (HttpURLConnection) hubUrl.openConnection(); -// connection.setRequestProperty("Host", hubUrl.getHost()); + final StringBuilder sb = new StringBuilder("hub.mode=publish&hub.url=").append(URLEncoder.encode(topic, "UTF-8")); + final URL hubUrl = new URL(hub); + final HttpURLConnection connection = (HttpURLConnection) hubUrl.openConnection(); + // connection.setRequestProperty("Host", hubUrl.getHost()); connection.setRequestProperty("User-Agent", "ROME-Certiorem"); connection.setRequestProperty("ContentType", "application/x-www-form-urlencoded"); connection.setDoOutput(true); connection.connect(); - OutputStream os = connection.getOutputStream(); + final OutputStream os = connection.getOutputStream(); os.write(sb.toString().getBytes("UTF-8")); os.close(); - int rc = connection.getResponseCode(); + final int rc = connection.getResponseCode(); connection.disconnect(); - + if (rc != 204) { - throw new NotificationException("Server returned an unexcepted response code: " + rc + " " + - connection.getResponseMessage()); + throw new NotificationException("Server returned an unexcepted response code: " + rc + " " + connection.getResponseMessage()); } - - } catch (UnsupportedEncodingException ex) { - Logger.getLogger(Publisher.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final UnsupportedEncodingException ex) { + Logger.getLogger(Publisher.class.getName()).log(Level.SEVERE, null, ex); throw new NotificationException("Could not encode URL", ex); - } catch (IOException ex) { - Logger.getLogger(Publisher.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final IOException ex) { + Logger.getLogger(Publisher.class.getName()).log(Level.SEVERE, null, ex); throw new NotificationException("Unable to communicate with " + hub, ex); } } /** * Sends a notification for a feed located at "topic". The feed MUST contain rel="hub". + * * @param topic URL for the feed * @param feed The feed itself * @throws NotificationException Any failure */ - public void sendUpdateNotification(String topic, SyndFeed feed) - throws NotificationException { - for (SyndLink link : (List) feed.getLinks()) { + public void sendUpdateNotification(final String topic, final SyndFeed feed) throws NotificationException { + for (final SyndLink link : feed.getLinks()) { if ("hub".equals(link.getRel())) { sendUpdateNotification(link.getRel(), topic); @@ -118,14 +110,15 @@ public class Publisher { /** * Sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links. + * * @param feed The feed to notify * @throws NotificationException Any failure */ - public void sendUpdateNotification(SyndFeed feed) throws NotificationException { + public void sendUpdateNotification(final SyndFeed feed) throws NotificationException { SyndLink hub = null; SyndLink self = null; - for (SyndLink link : (List) feed.getLinks()) { + for (final SyndLink link : feed.getLinks()) { if ("hub".equals(link.getRel())) { hub = link; } @@ -134,7 +127,7 @@ public class Publisher { self = link; } - if ((hub != null) && (self != null)) { + if (hub != null && self != null) { break; } } @@ -152,27 +145,27 @@ public class Publisher { /** * Sends the HUB url a notification of a change in topic asynchronously + * * @param hub URL of the hub to notify. - * @param topic The Topic that has changed - * @param callback A callback invoked when the notification completes. + * @param topic The Topic that has changed + * @param callback A callback invoked when the notification completes. * @throws NotificationException Any failure */ - public void sendUpdateNotificationAsyncronously(final String hub, final String topic, - final AsyncNotificationCallback callback) { - Runnable r = new Runnable() { - @Override - public void run() { - try { - sendUpdateNotification(hub, topic); - callback.onSuccess(); - } catch (Throwable t) { - callback.onFailure(t); - } + public void sendUpdateNotificationAsyncronously(final String hub, final String topic, final AsyncNotificationCallback callback) { + final Runnable r = new Runnable() { + @Override + public void run() { + try { + sendUpdateNotification(hub, topic); + callback.onSuccess(); + } catch (final Throwable t) { + callback.onFailure(t); } - }; + } + }; - if (this.executor != null) { - this.executor.execute(r); + if (executor != null) { + executor.execute(r); } else { new Thread(r).start(); } @@ -180,66 +173,70 @@ public class Publisher { /** * Asynchronously sends a notification for a feed located at "topic". The feed MUST contain rel="hub". + * * @param topic URL for the feed * @param feed The feed itself - * @param callback A callback invoked when the notification completes. + * @param callback A callback invoked when the notification completes. * @throws NotificationException Any failure */ - public void sendUpdateNotificationAsyncronously(final String topic, final SyndFeed feed, - final AsyncNotificationCallback callback) { - Runnable r = new Runnable() { - @Override - public void run() { - try { - sendUpdateNotification(topic, feed); - callback.onSuccess(); - } catch (Throwable t) { - callback.onFailure(t); - } + public void sendUpdateNotificationAsyncronously(final String topic, final SyndFeed feed, final AsyncNotificationCallback callback) { + final Runnable r = new Runnable() { + @Override + public void run() { + try { + sendUpdateNotification(topic, feed); + callback.onSuccess(); + } catch (final Throwable t) { + callback.onFailure(t); } - }; + } + }; - if (this.executor != null) { - this.executor.execute(r); + if (executor != null) { + executor.execute(r); } else { new Thread(r).start(); } } /** - * Asyncronously sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links. + * Asyncronously sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links. + * * @param feed The feed to notify - * @param callback A callback invoked when the notification completes. + * @param callback A callback invoked when the notification completes. * @throws NotificationException Any failure */ public void sendUpdateNotificationAsyncronously(final SyndFeed feed, final AsyncNotificationCallback callback) { - Runnable r = new Runnable() { - @Override - public void run() { - try { - sendUpdateNotification(feed); - callback.onSuccess(); - } catch (Throwable t) { - callback.onFailure(t); - } + final Runnable r = new Runnable() { + @Override + public void run() { + try { + sendUpdateNotification(feed); + callback.onSuccess(); + } catch (final Throwable t) { + callback.onFailure(t); } - }; + } + }; - if (this.executor != null) { - this.executor.execute(r); + if (executor != null) { + executor.execute(r); } else { new Thread(r).start(); } } + /** * A callback interface for asynchronous notifications. */ public static interface AsyncNotificationCallback { /** * Called when a notification fails + * * @param thrown Whatever was thrown during the failure */ public void onFailure(Throwable thrown); + /** * Invoked with the asyncronous notification completes successfully. */ diff --git a/src/main/java/org/rometools/certiorem/sub/Requester.java b/src/main/java/org/rometools/certiorem/sub/Requester.java index 72d9481..3bfce54 100644 --- a/src/main/java/org/rometools/certiorem/sub/Requester.java +++ b/src/main/java/org/rometools/certiorem/sub/Requester.java @@ -20,17 +20,15 @@ package org.rometools.certiorem.sub; import org.rometools.certiorem.sub.data.Subscription; - /** - * + * * @author robert.cooper */ public interface Requester { - public void sendSubscribeRequest(String hubUrl, Subscription subscription, String verifySync, long leaseSeconds, - String secret, String callbackUrl, RequestCallback callback); + public void sendSubscribeRequest(String hubUrl, Subscription subscription, String verifySync, long leaseSeconds, String secret, String callbackUrl, + RequestCallback callback); - public void sendUnsubscribeRequest(String hubUrl, Subscription subscription, String verifySync, String secret, - String callbackUrl, RequestCallback callback); + public void sendUnsubscribeRequest(String hubUrl, Subscription subscription, String verifySync, String secret, String callbackUrl, RequestCallback callback); public static interface RequestCallback { public void onFailure(Exception e); diff --git a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java index 32492d2..1f04342 100644 --- a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java +++ b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java @@ -18,104 +18,95 @@ package org.rometools.certiorem.sub; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndLink; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.SyndFeedInput; - -import org.rometools.certiorem.HttpStatusCodeException; -import org.rometools.certiorem.sub.Requester.RequestCallback; -import org.rometools.certiorem.sub.data.SubDAO; -import org.rometools.certiorem.sub.data.Subscription; - -import org.rometools.fetcher.impl.FeedFetcherCache; -import org.rometools.fetcher.impl.SyndFeedInfo; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; - import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; - -import java.util.List; import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; -import org.rometools.certiorem.sub.data.SubscriptionCallback; +import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.certiorem.sub.Requester.RequestCallback; +import org.rometools.certiorem.sub.data.SubDAO; +import org.rometools.certiorem.sub.data.Subscription; +import org.rometools.certiorem.sub.data.SubscriptionCallback; +import org.rometools.fetcher.impl.FeedFetcherCache; +import org.rometools.fetcher.impl.SyndFeedInfo; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndLink; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; /** - * + * * @author robert.cooper */ public class Subscriptions { - //TODO unsubscribe. + // TODO unsubscribe. private FeedFetcherCache cache; private Requester requester; private String callbackPrefix; private SubDAO dao; - public Subscriptions() { + public Subscriptions() { } - - public Subscriptions(final FeedFetcherCache cache, final Requester requester, final String callbackPrefix, - final SubDAO dao) { + + public Subscriptions(final FeedFetcherCache cache, final Requester requester, final String callbackPrefix, final SubDAO dao) { this.cache = cache; this.requester = requester; this.callbackPrefix = callbackPrefix; this.dao = dao; } - public void callback(String callbackPath, String feed) { + public void callback(final String callbackPath, final String feed) { try { this.callback(callbackPath, feed.getBytes("UTF-8")); - } catch (UnsupportedEncodingException ex) { - Logger.getLogger(Subscriptions.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final UnsupportedEncodingException ex) { + Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); throw new HttpStatusCodeException(400, "Unable to parse feed.", ex); } } - public void callback(String callbackPath, InputStream feed) { - SyndFeedInput input = new SyndFeedInput(); + public void callback(final String callbackPath, final InputStream feed) { + final SyndFeedInput input = new SyndFeedInput(); try { this.callback(callbackPath, input.build(new InputStreamReader(feed))); - } catch (IllegalArgumentException ex) { - Logger.getLogger(Subscriptions.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final IllegalArgumentException ex) { + Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); throw new HttpStatusCodeException(500, "Unable to parse feed.", ex); - } catch (FeedException ex) { - Logger.getLogger(Subscriptions.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final FeedException ex) { + Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); throw new HttpStatusCodeException(400, "Unable to parse feed.", ex); } } - public void callback(String callbackPath, byte[] feed) { + public void callback(final String callbackPath, final byte[] feed) { this.callback(callbackPath, new ByteArrayInputStream(feed)); } - public void callback(String callbackPath, SyndFeed feed) { + public void callback(final String callbackPath, final SyndFeed feed) { if (!callbackPath.startsWith(callbackPrefix)) { - throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath+" doesnt start with "+callbackPrefix)); + throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath + " doesnt start with " + callbackPrefix)); } - String id = callbackPath.substring(callbackPrefix.length()); + final String id = callbackPath.substring(callbackPrefix.length()); Logger.getLogger(Subscriptions.class.getName()).log(Level.FINE, "Got callback for {0}", id); - Subscription s = dao.findById(id); + final Subscription s = dao.findById(id); if (s == null) { throw new HttpStatusCodeException(404, "Not a valid callback.", null); } - this.validateLink(feed, s.getSourceUrl()); + validateLink(feed, s.getSourceUrl()); SyndFeedInfo info = null; URL url = null; @@ -123,9 +114,8 @@ public class Subscriptions { try { url = new URL(s.getSourceUrl()); info = cache.getFeedInfo(url); - } catch (MalformedURLException ex) { - Logger.getLogger(Subscriptions.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final MalformedURLException ex) { + Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); } if (info == null) { @@ -141,58 +131,53 @@ public class Subscriptions { s.getCallback().onNotify(s, info); } - public void unsubscribe(final Subscription subscription, String hubUrl, boolean sync, String secret, - final SubscriptionCallback callback) { + public void unsubscribe(final Subscription subscription, final String hubUrl, final boolean sync, final String secret, final SubscriptionCallback callback) { subscription.setUnsubscribed(true); - this.requester.sendUnsubscribeRequest(hubUrl, subscription, (sync ? "sync" : "async"), secret, - this.callbackPrefix + subscription.getId(), - new RequestCallback() { - @Override - public void onSuccess() { - callback.onUnsubscribe(subscription); - } + requester.sendUnsubscribeRequest(hubUrl, subscription, sync ? "sync" : "async", secret, callbackPrefix + subscription.getId(), new RequestCallback() { + @Override + public void onSuccess() { + callback.onUnsubscribe(subscription); + } - @Override - public void onFailure(Exception e) { - callback.onFailure(e); - } - }); + @Override + public void onFailure(final Exception e) { + callback.onFailure(e); + } + }); } - - public void subscribe(String hubUrl, String topic, boolean sync, long leaseSeconds, String secret, - final SubscriptionCallback callback) { - Subscription s = new Subscription(); + + public void subscribe(final String hubUrl, final String topic, final boolean sync, final long leaseSeconds, final String secret, + final SubscriptionCallback callback) { + final Subscription s = new Subscription(); s.setId(UUID.randomUUID().toString()); s.setVerifyToken(UUID.randomUUID().toString()); s.setSourceUrl(topic); s.setCallback(callback); if (leaseSeconds > 0) { - s.setExpirationTime(System.currentTimeMillis() + (leaseSeconds * 1000)); + s.setExpirationTime(System.currentTimeMillis() + leaseSeconds * 1000); } - final Subscription stored = this.dao.addSubscription(s); + final Subscription stored = dao.addSubscription(s); - this.requester.sendSubscribeRequest(hubUrl, stored, (sync ? "sync" : "async"), leaseSeconds, secret, - this.callbackPrefix + stored.getId(), - new RequestCallback() { - @Override - public void onSuccess() { - callback.onSubscribe(stored); - } + requester.sendSubscribeRequest(hubUrl, stored, sync ? "sync" : "async", leaseSeconds, secret, callbackPrefix + stored.getId(), new RequestCallback() { + @Override + public void onSuccess() { + callback.onSubscribe(stored); + } - @Override - public void onFailure(Exception e) { - callback.onFailure(e); - } - }); + @Override + public void onFailure(final Exception e) { + callback.onFailure(e); + } + }); } - public void subscribe(String topic, boolean sync, long leaseSeconds, String secret, - final SubscriptionCallback callback) throws IllegalArgumentException, IOException, FeedException { - SyndFeedInput input = new SyndFeedInput(); - SyndFeed feed = input.build(new InputStreamReader(new URL(topic).openStream())); - String hubUrl = this.findHubUrl(feed); + public void subscribe(final String topic, final boolean sync, final long leaseSeconds, final String secret, final SubscriptionCallback callback) + throws IllegalArgumentException, IOException, FeedException { + final SyndFeedInput input = new SyndFeedInput(); + final SyndFeed feed = input.build(new InputStreamReader(new URL(topic).openStream())); + final String hubUrl = findHubUrl(feed); if (hubUrl == null) { throw new FeedException("No hub link"); @@ -201,20 +186,19 @@ public class Subscriptions { this.subscribe(hubUrl, topic, sync, leaseSeconds, secret, callback); } - public String validate(String callbackPath, String topic, String mode, String challenge, String leaseSeconds, - String verifyToken) { + public String validate(final String callbackPath, final String topic, final String mode, final String challenge, final String leaseSeconds, + final String verifyToken) { if (!callbackPath.startsWith(callbackPrefix)) { - throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath+" doesnt start with "+callbackPrefix)); + throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath + " doesnt start with " + callbackPrefix)); } - String id = callbackPath.substring(callbackPrefix.length()); + final String id = callbackPath.substring(callbackPrefix.length()); Logger.getLogger(Subscriptions.class.getName()).log(Level.FINE, "Handling validation request for id {0}", id); - Subscription s = dao.findById(id); - if(s == null){ + final Subscription s = dao.findById(id); + if (s == null) { throw new HttpStatusCodeException(404, "Not a valid subscription id", null); } - if (!s.getVerifyToken() - .equals(verifyToken)) { + if (!s.getVerifyToken().equals(verifyToken)) { throw new HttpStatusCodeException(403, "Verification Token Mismatch.", null); } @@ -238,8 +222,8 @@ public class Subscriptions { return challenge; } - private String findHubUrl(SyndFeed feed) { - for (SyndLink l : (List) feed.getLinks()) { + private String findHubUrl(final SyndFeed feed) { + for (final SyndLink l : feed.getLinks()) { if ("hub".equals(l.getRel())) { return l.getHref(); } @@ -248,21 +232,20 @@ public class Subscriptions { return null; } - private void validateLink(SyndFeed feed, String source) { - for (SyndLink l : (List) feed.getLinks()) { + private void validateLink(final SyndFeed feed, final String source) { + for (final SyndLink l : feed.getLinks()) { if ("self".equalsIgnoreCase(l.getRel())) { try { - URI u = new URI(l.getHref()); - URI t = new URI(source); + final URI u = new URI(l.getHref()); + final URI t = new URI(source); if (!u.equals(t)) { throw new HttpStatusCodeException(400, "Feed self link does not match the subscribed URI.", null); } break; - } catch (URISyntaxException ex) { - Logger.getLogger(Subscriptions.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final URISyntaxException ex) { + Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); } } } @@ -271,28 +254,28 @@ public class Subscriptions { /** * @param cache the cache to set */ - public void setCache(FeedFetcherCache cache) { + public void setCache(final FeedFetcherCache cache) { this.cache = cache; } /** * @param requester the requester to set */ - public void setRequester(Requester requester) { + public void setRequester(final Requester requester) { this.requester = requester; } /** * @param callbackPrefix the callbackPrefix to set */ - public void setCallbackPrefix(String callbackPrefix) { + public void setCallbackPrefix(final String callbackPrefix) { this.callbackPrefix = callbackPrefix; } /** * @param dao the dao to set */ - public void setDao(SubDAO dao) { + public void setDao(final SubDAO dao) { this.dao = dao; } } diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java b/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java index 0eb12d0..dac96f5 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java +++ b/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java @@ -16,11 +16,10 @@ * limitations under the License. */ - package org.rometools.certiorem.sub.data; /** - * + * * @author robert.cooper */ public interface SubDAO { diff --git a/src/main/java/org/rometools/certiorem/sub/data/Subscription.java b/src/main/java/org/rometools/certiorem/sub/data/Subscription.java index 5aa1de2..c6f19c6 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/Subscription.java +++ b/src/main/java/org/rometools/certiorem/sub/data/Subscription.java @@ -20,9 +20,8 @@ package org.rometools.certiorem.sub.data; import java.io.Serializable; - /** - * + * * @author robert.cooper */ public class Subscription implements Serializable { @@ -36,110 +35,110 @@ public class Subscription implements Serializable { /** * Set the value of expirationTime - * + * * @param newexpirationTime new value of expirationTime */ - public void setExpirationTime(long newexpirationTime) { - this.expirationTime = newexpirationTime; + public void setExpirationTime(final long newexpirationTime) { + expirationTime = newexpirationTime; } /** * Get the value of expirationTime - * + * * @return the value of expirationTime */ public long getExpirationTime() { - return this.expirationTime; + return expirationTime; } /** * Set the value of id - * + * * @param newid new value of id */ - public void setId(String newid) { - this.id = newid; + public void setId(final String newid) { + id = newid; } /** * Get the value of id - * + * * @return the value of id */ public String getId() { - return this.id; + return id; } /** * Set the value of sourceUrl - * + * * @param newsourceUrl new value of sourceUrl */ - public void setSourceUrl(String newsourceUrl) { - this.sourceUrl = newsourceUrl; + public void setSourceUrl(final String newsourceUrl) { + sourceUrl = newsourceUrl; } /** * Get the value of sourceUrl - * + * * @return the value of sourceUrl */ public String getSourceUrl() { - return this.sourceUrl; + return sourceUrl; } /** * Set the value of unsubscribed - * + * * @param newunsubscribed new value of unsubscribed */ - public void setUnsubscribed(boolean newunsubscribed) { - this.unsubscribed = newunsubscribed; + public void setUnsubscribed(final boolean newunsubscribed) { + unsubscribed = newunsubscribed; } /** * Get the value of unsubscribed - * + * * @return the value of unsubscribed */ public boolean isUnsubscribed() { - return this.unsubscribed; + return unsubscribed; } /** * Set the value of validated - * + * * @param newvalidated new value of validated */ - public void setValidated(boolean newvalidated) { - this.validated = newvalidated; + public void setValidated(final boolean newvalidated) { + validated = newvalidated; } /** * Get the value of validated - * + * * @return the value of validated */ public boolean isValidated() { - return this.validated; + return validated; } /** * Set the value of verifyToken - * + * * @param newverifyToken new value of verifyToken */ - public void setVerifyToken(String newverifyToken) { - this.verifyToken = newverifyToken; + public void setVerifyToken(final String newverifyToken) { + verifyToken = newverifyToken; } /** * Get the value of verifyToken - * + * * @return the value of verifyToken */ public String getVerifyToken() { - return this.verifyToken; + return verifyToken; } /** @@ -152,7 +151,7 @@ public class Subscription implements Serializable { /** * @param callback the callback to set */ - public void setCallback(SubscriptionCallback callback) { + public void setCallback(final SubscriptionCallback callback) { this.callback = callback; } } diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java b/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java index 6c050a5..01018df 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java +++ b/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java @@ -8,7 +8,7 @@ package org.rometools.certiorem.sub.data; import org.rometools.fetcher.impl.SyndFeedInfo; /** - * + * * @author najmi */ public interface SubscriptionCallback { @@ -18,6 +18,6 @@ public interface SubscriptionCallback { void onFailure(Exception e); void onSubscribe(Subscription subscribed); - + void onUnsubscribe(Subscription subscribed); } diff --git a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java b/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java index 9cb0587..0e50fce 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java +++ b/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java @@ -27,25 +27,27 @@ import java.util.Date; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; + import org.rometools.certiorem.sub.data.SubDAO; import org.rometools.certiorem.sub.data.Subscription; /** - * + * * @author robert.cooper */ public class InMemorySubDAO implements SubDAO { - private ConcurrentHashMap subscriptions = new ConcurrentHashMap(); + private final ConcurrentHashMap subscriptions = new ConcurrentHashMap(); @Override - public Subscription findById(String id) { - Subscription s = subscriptions.get(id); - if(s == null){ + public Subscription findById(final String id) { + final Subscription s = subscriptions.get(id); + if (s == null) { return null; } - if(s.getExpirationTime() > 0 && s.getExpirationTime() <= System.currentTimeMillis()){ - Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Subscription {0} expired at {1}", new Object[]{s.getSourceUrl(), new Date(s.getExpirationTime())}); + if (s.getExpirationTime() > 0 && s.getExpirationTime() <= System.currentTimeMillis()) { + Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Subscription {0} expired at {1}", + new Object[] { s.getSourceUrl(), new Date(s.getExpirationTime()) }); subscriptions.remove(id); return null; @@ -54,20 +56,20 @@ public class InMemorySubDAO implements SubDAO { } @Override - public Subscription addSubscription(Subscription s) { + public Subscription addSubscription(final Subscription s) { subscriptions.put(s.getId(), s); - Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Stored subscription {0} {1}", new Object[]{s.getSourceUrl(), s.getId()}); + Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Stored subscription {0} {1}", new Object[] { s.getSourceUrl(), s.getId() }); return s; } @Override - public Subscription updateSubscription(Subscription s) { + public Subscription updateSubscription(final Subscription s) { subscriptions.put(s.getId(), s); return s; } @Override - public void removeSubscription(Subscription s) { + public void removeSubscription(final Subscription s) { subscriptions.remove(s.getId()); } diff --git a/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java b/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java index ff32ca5..532260f 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java +++ b/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java @@ -16,64 +16,51 @@ * limitations under the License. */ - package org.rometools.certiorem.sub.request; -import org.rometools.certiorem.sub.Requester; -import org.rometools.certiorem.sub.data.Subscription; - import java.io.IOException; - import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; +import org.rometools.certiorem.sub.Requester; +import org.rometools.certiorem.sub.data.Subscription; /** - * + * * @author robert.cooper */ public abstract class AbstractRequester implements Requester { - - protected boolean sendRequest(String hubUrl, String mode, Subscription subscription, String verifySync, - long leaseSeconds, String secret, String callbackUrl, RequestCallback callback) - throws IOException { - StringBuilder sb = new StringBuilder("hub.callback=").append(URLEncoder.encode(callbackUrl, "UTF-8")) - .append("&hub.topic=") - .append(URLEncoder.encode(subscription.getSourceUrl(), - "UTF-8")) - .append("&hub.verify=") - .append(URLEncoder.encode(verifySync, "UTF-8")) - .append("&hub.mode=") - .append(URLEncoder.encode(mode, "UTF-8")); + + protected boolean sendRequest(final String hubUrl, final String mode, final Subscription subscription, final String verifySync, final long leaseSeconds, + final String secret, final String callbackUrl, final RequestCallback callback) throws IOException { + final StringBuilder sb = new StringBuilder("hub.callback=").append(URLEncoder.encode(callbackUrl, "UTF-8")).append("&hub.topic=") + .append(URLEncoder.encode(subscription.getSourceUrl(), "UTF-8")).append("&hub.verify=").append(URLEncoder.encode(verifySync, "UTF-8")) + .append("&hub.mode=").append(URLEncoder.encode(mode, "UTF-8")); if (leaseSeconds > 0) { - sb.append("&hub.lease_seconds=") - .append(Long.toString(leaseSeconds)); + sb.append("&hub.lease_seconds=").append(Long.toString(leaseSeconds)); } if (secret != null) { - sb.append("&hub.secret=") - .append(URLEncoder.encode(secret, "UTF-8")); + sb.append("&hub.secret=").append(URLEncoder.encode(secret, "UTF-8")); } if (subscription.getVerifyToken() != null) { - sb.append("&hub.verify_token=") - .append(URLEncoder.encode(subscription.getVerifyToken(), "UTF-8")); + sb.append("&hub.verify_token=").append(URLEncoder.encode(subscription.getVerifyToken(), "UTF-8")); } - URL url = new URL(hubUrl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + final URL url = new URL(hubUrl); + final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setDoOutput(true); -// connection.setRequestProperty("Host", url.getHost()); + // connection.setRequestProperty("Host", url.getHost()); connection.setRequestProperty("User-Agent", "ROME-Certiorem"); connection.connect(); - connection.getOutputStream() - .write(sb.toString().getBytes("UTF-8")); + connection.getOutputStream().write(sb.toString().getBytes("UTF-8")); - int rc = connection.getResponseCode(); + final int rc = connection.getResponseCode(); connection.disconnect(); if (rc != 204) { diff --git a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java b/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java index c345410..305a12b 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java +++ b/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java @@ -18,57 +18,53 @@ package org.rometools.certiorem.sub.request; -import org.rometools.certiorem.sub.data.Subscription; - import java.io.IOException; - import java.util.logging.Level; import java.util.logging.Logger; +import org.rometools.certiorem.sub.data.Subscription; /** * A simple requester implementation that always makes requests as Async. + * * @author robert.cooper */ public class AsyncRequester extends AbstractRequester { @Override - public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, - final long leaseSeconds, final String secret, final String callbackUrl, final RequestCallback callback) { - Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending subscribe request to {0} for {1} to {2}", new Object[]{hubUrl, subscription.getSourceUrl(), callbackUrl}); - Runnable r = new Runnable() { - @Override - public void run() { - try { - sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, - callback); - } catch (Exception ex) { - Logger.getLogger(AsyncRequester.class.getName()) - .log(Level.SEVERE, null, ex); - callback.onFailure(ex); - } + public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds, + final String secret, final String callbackUrl, final RequestCallback callback) { + Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending subscribe request to {0} for {1} to {2}", + new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl }); + final Runnable r = new Runnable() { + @Override + public void run() { + try { + sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback); + } catch (final Exception ex) { + Logger.getLogger(AsyncRequester.class.getName()).log(Level.SEVERE, null, ex); + callback.onFailure(ex); } - }; - new Thread(r).start(); + } + }; + new Thread(r).start(); } @Override - public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, - final String secret, - final String callbackUrl, final RequestCallback callback) { - Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending unsubscribe request to {0} for {1} to {2}", new Object[]{hubUrl, subscription.getSourceUrl(), callbackUrl}); - Runnable r = new Runnable() { - @Override - public void run() { - try { - sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, - callback); - } catch (IOException ex) { - Logger.getLogger(AsyncRequester.class.getName()) - .log(Level.SEVERE, null, ex); - callback.onFailure(ex); - } + public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret, + final String callbackUrl, final RequestCallback callback) { + Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending unsubscribe request to {0} for {1} to {2}", + new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl }); + final Runnable r = new Runnable() { + @Override + public void run() { + try { + sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback); + } catch (final IOException ex) { + Logger.getLogger(AsyncRequester.class.getName()).log(Level.SEVERE, null, ex); + callback.onFailure(ex); } - }; - new Thread(r).start(); + } + }; + new Thread(r).start(); } } diff --git a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java b/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java index 2f25229..5cd6d17 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java +++ b/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java @@ -22,46 +22,42 @@ */ package org.rometools.certiorem.sub.request; -import org.rometools.certiorem.sub.data.Subscription; - import java.io.IOException; - import java.util.logging.Level; import java.util.logging.Logger; +import org.rometools.certiorem.sub.data.Subscription; /** * A simple requester implementation that always makes requests as Async. + * * @author Farrukh Najmi */ public class SyncRequester extends AbstractRequester { @Override - public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, - final long leaseSeconds, final String secret, final String callbackUrl, final RequestCallback callback) { - Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending subscribe request to {0} for {1} to {2}", new Object[]{hubUrl, subscription.getSourceUrl(), callbackUrl}); + public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds, + final String secret, final String callbackUrl, final RequestCallback callback) { + Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending subscribe request to {0} for {1} to {2}", + new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl }); try { - sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, - callback); + sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback); callback.onSuccess(); - } catch (Exception ex) { - Logger.getLogger(SyncRequester.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final Exception ex) { + Logger.getLogger(SyncRequester.class.getName()).log(Level.SEVERE, null, ex); callback.onFailure(ex); } } @Override - public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, - final String secret, - final String callbackUrl, final RequestCallback callback) { - Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending unsubscribe request to {0} for {1} to {2}", new Object[]{hubUrl, subscription.getSourceUrl(), callbackUrl}); + public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret, + final String callbackUrl, final RequestCallback callback) { + Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending unsubscribe request to {0} for {1} to {2}", + new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl }); try { - sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, - callback); + sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback); callback.onSuccess(); - } catch (IOException ex) { - Logger.getLogger(SyncRequester.class.getName()) - .log(Level.SEVERE, null, ex); + } catch (final IOException ex) { + Logger.getLogger(SyncRequester.class.getName()).log(Level.SEVERE, null, ex); callback.onFailure(ex); } } diff --git a/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java b/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java index 091bc6d..64d9f31 100644 --- a/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java +++ b/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java @@ -16,14 +16,9 @@ * limitations under the License. */ - package org.rometools.certiorem.web; -import org.rometools.certiorem.HttpStatusCodeException; -import org.rometools.certiorem.hub.Hub; - import java.io.IOException; - import java.util.Arrays; import javax.servlet.ServletException; @@ -31,9 +26,11 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.certiorem.hub.Hub; /** - * + * * @author robert.cooper */ public abstract class AbstractHubServlet extends HttpServlet { @@ -46,37 +43,34 @@ public abstract class AbstractHubServlet extends HttpServlet { } @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { + protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try { if ("publish".equals(req.getParameter(HUBMODE))) { hub.sendNotification(req.getServerName(), req.getParameter("hub.url")); } else { - String callback = req.getParameter("hub.callback"); - String topic = req.getParameter("hub.topic"); - String[] verifies = req.getParameterValues("hub.verify"); - String leaseString = req.getParameter("hub.lease_seconds"); - String secret = req.getParameter("hub.secret"); - String verifyToken = req.getParameter("hub.verify_token"); - String verifyMode = Arrays.asList(verifies) - .contains("async") ? "async" : "sync"; + final String callback = req.getParameter("hub.callback"); + final String topic = req.getParameter("hub.topic"); + final String[] verifies = req.getParameterValues("hub.verify"); + final String leaseString = req.getParameter("hub.lease_seconds"); + final String secret = req.getParameter("hub.secret"); + final String verifyToken = req.getParameter("hub.verify_token"); + final String verifyMode = Arrays.asList(verifies).contains("async") ? "async" : "sync"; Boolean result = null; if ("subscribe".equals(req.getParameter(HUBMODE))) { - long leaseSeconds = (leaseString != null) ? Long.parseLong(leaseString) : (-1); + final long leaseSeconds = leaseString != null ? Long.parseLong(leaseString) : -1; result = hub.subscribe(callback, topic, verifyMode, leaseSeconds, secret, verifyToken); } else if ("unsubscribe".equals(req.getParameter(HUBMODE))) { result = hub.unsubscribe(callback, topic, verifyMode, secret, verifyToken); } - if ((result != null) && !result) { + if (result != null && !result) { throw new HttpStatusCodeException(500, "Operation failed.", null); } } - } catch (HttpStatusCodeException sc) { + } catch (final HttpStatusCodeException sc) { resp.setStatus(sc.getStatus()); - resp.getWriter() - .println(sc.getMessage()); + resp.getWriter().println(sc.getMessage()); return; } diff --git a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java b/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java index 5c74657..9a3d42e 100644 --- a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java +++ b/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java @@ -16,45 +16,46 @@ * limitations under the License. */ - package org.rometools.certiorem.web; import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpUtils; + import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.sub.Subscriptions; /** - * + * * @author robert.cooper */ public class AbstractSubServlet extends HttpServlet { private final Subscriptions subscriptions; - - protected AbstractSubServlet(final Subscriptions subscriptions){ + + protected AbstractSubServlet(final Subscriptions subscriptions) { super(); this.subscriptions = subscriptions; - + } @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - String mode = req.getParameter("hub.mode"); - String topic = req.getParameter("hub.topic"); - String challenge = req.getParameter("hub.challenge"); - String leaseString = req.getParameter("hub.lease_seconds"); - String verifyToken = req.getParameter("hub.verify_token"); - try{ - String result = subscriptions.validate(HttpUtils.getRequestURL(req).toString(), topic, mode, challenge, leaseString, verifyToken); + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + final String mode = req.getParameter("hub.mode"); + final String topic = req.getParameter("hub.topic"); + final String challenge = req.getParameter("hub.challenge"); + final String leaseString = req.getParameter("hub.lease_seconds"); + final String verifyToken = req.getParameter("hub.verify_token"); + try { + final String result = subscriptions.validate(HttpUtils.getRequestURL(req).toString(), topic, mode, challenge, leaseString, verifyToken); resp.setStatus(200); resp.getWriter().print(result); return; - } catch(HttpStatusCodeException e){ + } catch (final HttpStatusCodeException e) { e.printStackTrace(); resp.setStatus(e.getStatus()); resp.getWriter().print(e.getMessage()); @@ -63,17 +64,15 @@ public class AbstractSubServlet extends HttpServlet { } @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - try{ - this.subscriptions.callback(HttpUtils.getRequestURL(req).toString(), req.getInputStream()); + protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + try { + subscriptions.callback(HttpUtils.getRequestURL(req).toString(), req.getInputStream()); return; - } catch(HttpStatusCodeException e){ + } catch (final HttpStatusCodeException e) { e.printStackTrace(); resp.setStatus(e.getStatus()); resp.getWriter().println(e.getMessage()); } } - - } diff --git a/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java b/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java index 447aed8..3e01b85 100644 --- a/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java +++ b/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java @@ -16,34 +16,33 @@ * limitations under the License. */ - package org.rometools.certiorem.hub; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ public class AlwaysVerifier implements Verifier { @Override - public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { callback.onVerify(true); } @Override - public boolean verifySubcribeSyncronously(Subscriber subscriber) { + public boolean verifySubcribeSyncronously(final Subscriber subscriber) { return true; } @Override - public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { callback.onVerify(true); } @Override - public boolean verifyUnsubcribeSyncronously(Subscriber subscriber) { + public boolean verifyUnsubcribeSyncronously(final Subscriber subscriber) { return true; } diff --git a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java index 172d9b1..f337505 100644 --- a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java +++ b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java @@ -18,25 +18,25 @@ package org.rometools.certiorem.hub; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.util.logging.Logger; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.rometools.certiorem.HttpStatusCodeException; +import org.rometools.certiorem.hub.data.HubDAO; +import org.rometools.certiorem.hub.data.ram.InMemoryHubDAO; import org.rometools.fetcher.FeedFetcher; import org.rometools.fetcher.impl.HashMapFeedInfoCache; import org.rometools.fetcher.impl.HttpURLFeedFetcher; -import org.junit.After; -import org.junit.AfterClass; -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import org.rometools.certiorem.hub.data.HubDAO; -import org.rometools.certiorem.hub.data.ram.InMemoryHubDAO; - /** - * + * * @author robert.cooper */ public class ControllerTest { @@ -66,14 +66,14 @@ public class ControllerTest { public void testSubscribe() { Logger.getLogger(ControllerTest.class.getName()).info("subscribe"); - String callback = "http://localhost/doNothing"; - String topic = "http://feeds.feedburner.com/screaming-penguin"; - long lease_seconds = -1; - String secret = null; - String verify_token = "MyVoiceIsMyPassport"; - HubDAO dao = new InMemoryHubDAO(); - Notifier notifier = null; - FeedFetcher fetcher = new HttpURLFeedFetcher(HashMapFeedInfoCache.getInstance()); + final String callback = "http://localhost/doNothing"; + final String topic = "http://feeds.feedburner.com/screaming-penguin"; + final long lease_seconds = -1; + final String secret = null; + final String verify_token = "MyVoiceIsMyPassport"; + final HubDAO dao = new InMemoryHubDAO(); + final Notifier notifier = null; + final FeedFetcher fetcher = new HttpURLFeedFetcher(HashMapFeedInfoCache.getInstance()); Hub instance = new Hub(dao, new AlwaysVerifier(), notifier, fetcher); Boolean result = instance.subscribe(callback, topic, "sync", lease_seconds, secret, verify_token); @@ -90,7 +90,7 @@ public class ControllerTest { try { instance.subscribe(null, topic, "async", lease_seconds, secret, verify_token); fail(); - } catch (HttpStatusCodeException e) { + } catch (final HttpStatusCodeException e) { assertEquals(400, e.getStatus()); Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); } @@ -98,7 +98,7 @@ public class ControllerTest { try { instance.subscribe(callback, null, "async", lease_seconds, secret, verify_token); fail(); - } catch (HttpStatusCodeException e) { + } catch (final HttpStatusCodeException e) { assertEquals(400, e.getStatus()); Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); } @@ -106,7 +106,7 @@ public class ControllerTest { try { instance.subscribe(callback, topic, "foo", lease_seconds, secret, verify_token); fail(); - } catch (HttpStatusCodeException e) { + } catch (final HttpStatusCodeException e) { assertEquals(400, e.getStatus()); Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); } @@ -117,7 +117,7 @@ public class ControllerTest { try { result = instance.subscribe(callback, topic, "sync", lease_seconds, secret, verify_token); fail(); - } catch (HttpStatusCodeException e) { + } catch (final HttpStatusCodeException e) { assertEquals(500, e.getStatus()); } } diff --git a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java index a7786e1..4f35551 100644 --- a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java +++ b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java @@ -5,29 +5,32 @@ package org.rometools.certiorem.hub; import java.io.IOException; -import com.sun.syndication.feed.synd.SyndEntry; -import java.util.List; -import junit.framework.Assert; -import org.rometools.fetcher.impl.HashMapFeedInfoCache; -import org.rometools.fetcher.impl.HttpURLFeedFetcher; import java.net.URL; -import com.sun.syndication.feed.synd.SyndFeed; +import java.util.List; + +import junit.framework.Assert; + import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.rometools.fetcher.impl.HashMapFeedInfoCache; +import org.rometools.fetcher.impl.HttpURLFeedFetcher; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; /** - * + * * @author najmi */ public class DeltaSyndFeedInfoTest { - + DeltaFeedInfoCache feedInfoCache; HttpURLFeedFetcher feedFetcher; SyndFeed feed; - + public DeltaSyndFeedInfoTest() { } @@ -38,18 +41,16 @@ public class DeltaSyndFeedInfoTest { @AfterClass public static void tearDownClass() throws Exception { } - - + @Before public void setUp() { feedInfoCache = new DeltaFeedInfoCache(new HashMapFeedInfoCache()); feedFetcher = new HttpURLFeedFetcher(feedInfoCache); } - + @After - public void tearDown() { + public void tearDown() { } - /** * Test of getSyndFeed method, of class DeltaSyndFeedInfo. @@ -57,21 +58,21 @@ public class DeltaSyndFeedInfoTest { @Test public void testGetSyndFeed() throws Exception { System.out.println("getSyndFeed"); - + feed = feedFetcher.retrieveFeed(getFeedUrl()); List entries = feed.getEntries(); Assert.assertTrue(!entries.isEmpty()); - //Fetch again and this time the entries should be empty as none have changed. + // Fetch again and this time the entries should be empty as none have changed. feed = feedFetcher.retrieveFeed(getFeedUrl()); entries = feed.getEntries(); - Assert.assertTrue(entries.isEmpty()); + Assert.assertTrue(entries.isEmpty()); } private URL getFeedUrl() throws IOException { - URL feedUrl = new URL("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss"); -// URL feedUrl = new URL("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml"); - + final URL feedUrl = new URL("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss"); + // URL feedUrl = new URL("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml"); + return feedUrl; - } + } } diff --git a/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java b/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java index 9dfa920..87153b3 100644 --- a/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java +++ b/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java @@ -16,34 +16,33 @@ * limitations under the License. */ - package org.rometools.certiorem.hub; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ -public class ExceptionVerifier implements Verifier{ +public class ExceptionVerifier implements Verifier { @Override - public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public boolean verifySubcribeSyncronously(Subscriber subscriber) { + public boolean verifySubcribeSyncronously(final Subscriber subscriber) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public boolean verifyUnsubcribeSyncronously(Subscriber subscriber) { + public boolean verifyUnsubcribeSyncronously(final Subscriber subscriber) { throw new UnsupportedOperationException("Not supported yet."); } diff --git a/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java b/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java index 86cd96d..b514293 100644 --- a/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java +++ b/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java @@ -16,34 +16,33 @@ * limitations under the License. */ - package org.rometools.certiorem.hub; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ -public class NeverVerifier implements Verifier{ +public class NeverVerifier implements Verifier { @Override - public void verifySubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + public void verifySubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { callback.onVerify(false); } @Override - public boolean verifySubcribeSyncronously(Subscriber subscriber) { + public boolean verifySubcribeSyncronously(final Subscriber subscriber) { return false; } @Override - public void verifyUnsubscribeAsyncronously(Subscriber subscriber, VerificationCallback callback) { + public void verifyUnsubscribeAsyncronously(final Subscriber subscriber, final VerificationCallback callback) { callback.onVerify(false); } @Override - public boolean verifyUnsubcribeSyncronously(Subscriber subscriber) { + public boolean verifyUnsubcribeSyncronously(final Subscriber subscriber) { return false; } diff --git a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java index ff39791..af8f1c7 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java +++ b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java @@ -21,10 +21,11 @@ package org.rometools.certiorem.hub.data; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; + import org.junit.Test; /** - * + * * @author robert.cooper */ public abstract class AbstractDAOTest { @@ -33,40 +34,40 @@ public abstract class AbstractDAOTest { @Test public void testSubscribe() { - HubDAO instance = get(); + final HubDAO instance = get(); Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testSubscribe", instance.getClass().getName()); - Subscriber subscriber = new Subscriber(); + final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); subscriber.setLeaseSeconds(-1); subscriber.setVerify("VerifyMe"); - Subscriber result = instance.addSubscriber(subscriber); + final Subscriber result = instance.addSubscriber(subscriber); assert result.equals(subscriber) : "Subscriber not equal."; - List subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); + final List subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); assert subscribers.contains(result) : "Subscriber not in result."; } @Test public void testLeaseExpire() throws InterruptedException { - HubDAO instance = get(); + final HubDAO instance = get(); Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testLeaseExpire", instance.getClass().getName()); - Subscriber subscriber = new Subscriber(); + final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); subscriber.setLeaseSeconds(1); subscriber.setVerify("VerifyMe"); - Subscriber result = instance.addSubscriber(subscriber); + final Subscriber result = instance.addSubscriber(subscriber); assert subscriber.equals(result) : "Subscriber not equal."; - //quick test for store. + // quick test for store. List subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); assert subscribers.contains(result) : "Subscriber not in result."; - //sleep past expiration + // sleep past expiration Thread.sleep(1100); subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); assert !subscribers.contains(result) : "Subscriber should have expired"; @@ -74,15 +75,15 @@ public abstract class AbstractDAOTest { @Test public void testUnsubscribe() throws InterruptedException { - HubDAO instance = get(); + final HubDAO instance = get(); Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testUnsubscribe", instance.getClass().getName()); - Subscriber subscriber = new Subscriber(); + final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); subscriber.setLeaseSeconds(1); subscriber.setVerify("VerifyMe"); - Subscriber result = instance.addSubscriber(subscriber); + final Subscriber result = instance.addSubscriber(subscriber); // TODO } diff --git a/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java index 90db87f..218fcbe 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java +++ b/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java @@ -16,18 +16,17 @@ * limitations under the License. */ - package org.rometools.certiorem.hub.data.ram; import org.rometools.certiorem.hub.data.AbstractDAOTest; import org.rometools.certiorem.hub.data.HubDAO; /** - * + * * @author robert.cooper */ -public class InMemoryDAOTest extends AbstractDAOTest{ - private InMemoryHubDAO dao = new InMemoryHubDAO(); +public class InMemoryDAOTest extends AbstractDAOTest { + private final InMemoryHubDAO dao = new InMemoryHubDAO(); public InMemoryDAOTest() { } @@ -37,8 +36,4 @@ public class InMemoryDAOTest extends AbstractDAOTest{ return dao; } - - - - } \ 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 From 2f93235e69daee6bde4c4ac53e2dc0d730482c4f Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Oct 2013 15:30:24 +0200 Subject: [PATCH 04/23] Removed warnings Cleanup up test --- .../certiorem/hub/DeltaSyndFeedInfoTest.java | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java index 4f35551..f1526f1 100644 --- a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java +++ b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java @@ -4,16 +4,13 @@ */ package org.rometools.certiorem.hub; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.net.URL; import java.util.List; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.rometools.fetcher.impl.HashMapFeedInfoCache; import org.rometools.fetcher.impl.HttpURLFeedFetcher; @@ -27,20 +24,9 @@ import com.sun.syndication.feed.synd.SyndFeed; */ public class DeltaSyndFeedInfoTest { - DeltaFeedInfoCache feedInfoCache; - HttpURLFeedFetcher feedFetcher; - SyndFeed feed; - - public DeltaSyndFeedInfoTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - } - - @AfterClass - public static void tearDownClass() throws Exception { - } + private DeltaFeedInfoCache feedInfoCache; + private HttpURLFeedFetcher feedFetcher; + private SyndFeed feed; @Before public void setUp() { @@ -48,31 +34,26 @@ public class DeltaSyndFeedInfoTest { feedFetcher = new HttpURLFeedFetcher(feedInfoCache); } - @After - public void tearDown() { - } - /** * Test of getSyndFeed method, of class DeltaSyndFeedInfo. */ @Test public void testGetSyndFeed() throws Exception { - System.out.println("getSyndFeed"); feed = feedFetcher.retrieveFeed(getFeedUrl()); List entries = feed.getEntries(); - Assert.assertTrue(!entries.isEmpty()); + assertTrue(!entries.isEmpty()); // Fetch again and this time the entries should be empty as none have changed. feed = feedFetcher.retrieveFeed(getFeedUrl()); entries = feed.getEntries(); - Assert.assertTrue(entries.isEmpty()); + assertTrue(entries.isEmpty()); } private URL getFeedUrl() throws IOException { final URL feedUrl = new URL("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss"); // URL feedUrl = new URL("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml"); - return feedUrl; } + } From b4c1248ab5b876c78f4a477db6baaf5da24301ff Mon Sep 17 00:00:00 2001 From: Martin Kurz Date: Sat, 12 Oct 2013 15:47:03 +0200 Subject: [PATCH 05/23] removed incubator infos from site, site config adapted for standalone certiorem project (and github fork config added), site generation adapted for maven 3 including reports --- pom.xml | 55 +++++++++++++++++++++++++++++++++++--- src/site/apt/Certiorem.apt | 47 -------------------------------- src/site/apt/index.apt | 44 +++++++++++++++++++++++++----- src/site/site.xml | 23 +++++++++++----- 4 files changed, 106 insertions(+), 63 deletions(-) delete mode 100644 src/site/apt/Certiorem.apt diff --git a/pom.xml b/pom.xml index ddb952a..6168ef4 100644 --- a/pom.xml +++ b/pom.xml @@ -13,9 +13,9 @@ A PubSubHubub implementation for Java based on ROME - scm:svn:https://rometools.jira.com/svn/INCUBATOR/trunk/pubsubhubub/certiorem/ - scm:svn:https://rometools.jira.com/svn/INCUBATOR/trunk/pubsubhubub/certiorem/ - https://rometools.jira.com/svn/INCUBATOR/trunk/pubsubhubub/certiorem/ + scm:git:git@github.com:rometools/rome-certiorem.git + scm:git:git@github.com:rometools/rome-certiorem.git + https://github.com/rometools/rome-certiorem/ @@ -99,6 +99,25 @@ + + org.apache.maven.plugins + maven-site-plugin + 3.3 + + 9000 + ${basedir}/target/site/tempdir + + + + org.apache.maven.plugins + maven-scm-publish-plugin + 1.0-beta-2 + + gh-pages + scm:git:git@github.com:rometools/rome-certiorem.git + ${project.build.directory}/site + + @@ -142,4 +161,34 @@ + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + + javadoc + test-javadoc + + + + aggregate + false + + aggregate + + + + + + + diff --git a/src/site/apt/Certiorem.apt b/src/site/apt/Certiorem.apt deleted file mode 100644 index d240e48..0000000 --- a/src/site/apt/Certiorem.apt +++ /dev/null @@ -1,47 +0,0 @@ - ----- - certiorem - ----- - kebernet - ----- - 2011-03-19 10:30:35.292 - ----- - -Certiorem - - Certiorem is an implementation of the {{{http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub\-core\-0.3.html}PubSubHubub }}protocol for ROME. - - It is dependent on ROME and ROME\-Fetcher for the base implementations, and will provide standard plugins for Propono to allow for publish eventing, where applicable. - -*Primary Components - -*Hub Implementation and Scaffolding (Done) - - The first part of Certiorem is a basic set of scaffolding classes that can be used to create a PSH notification hub. Initially, this will include a non\-guaranteed delivery hub, with standard implementations suitable for deployment on most JavaEE application servers or Google App Engine. It is intended that there should be at least one simple, drop in WAR file, utilizing JavaEE classes that can work in a default configuration for various standard web containers. Subsequently,  each of the classes in the PSH implementation up through the primary Controller class use constructor\-time composition/configuration so that the user/developer can easily construct a custom configuration of the Hub. - -**Client Implementation Integrated with ROME\-Fetcher (Done) - - For web\-based applications that use ROME\-Fetcher, an extended push\-notified store wrapper that will update based on callbacks from a Hub of change notifications. This will include a highly configurable callback servlet to write into the Fetcher cache as changes are made. Additionally, the system should support (semi\-)real time notifications of changes in the form of a listener that exectutes in a TBD thread state relative to the callback servlet. This should be packaged as a simple JAR with no more deps than fetcher that defines the callback servlet, and automagically does subscribes where link\=rel appropriate. - -**Notification Implementation for Propono based and JAX\-RS based Servers (In Progress) - - This should be a simple API call to notify a Hub of changes to topics. Again, this should provide real\-time notifications either synchronously or asynchronously. Importantly for Asynchronous notifications, they should block subsequent change notifications pending a notification to the Hub. - - References:  - - {{{https://github.com/nlothian/RTUpdates/blob/master/src/com/nicklothian/pubsubhub/PubSubHubSubscriptionServlet.java}https://github.com/nlothian/RTUpdates/blob/master/src/com/nicklothian/pubsubhub/PubSubHubSubscriptionServlet.java}} - - {{{http://grack.com/blog/2009/09/09/parsing\-the\-pubsubhubbub\-notifications/}http://grack.com/blog/2009/09/09/parsing\-the\-pubsubhubbub\-notifications/}} - -Notes on the Code - - It is still mostly a rough sketch, but the big outlines are there: - - There are three main packages: pub, sub and hub. - - The pub package is basically just a single utility class for pushing notifications to a hub. - - The hub package contains the Hub class. This is a general business controller that is intended to allow you to build a servlet around it with a very, very thin veneer, but you could also use it to drive an XMPP or JMS version too. It is basically built by composition of a number of classes, for which there are some default implementations: A Verifier, which makes the callback to verify new subscriptions, the HubDAO which stores the current subscriptions and subscriber statistics, and a Notifier which actually sends notifications to the subscribers. There are a couple of implementations of each of these (though the JPA HubDAO is still in process). Mostly the implementations for the Verifier and Notifier support threadpooling or no\-threads (for App Engine use). - - I have just started sketching out the sub package, but it basically has a "Subscriptions" class that will take in notifications (using the same "thin veneer" pattern that the Hub class uses). It is also constructed with some impls: A SubscriptionDAO that stores you current subscription information, a FeedFetcherCache that holds the received data, and a Requester that makes the subscription requests to hubs. - - I am hoping to have a basic end to end example working sometime in the next week or so, but if anyone wants to look over what is there, feel free. diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt index c6ce1c1..d240e48 100644 --- a/src/site/apt/index.apt +++ b/src/site/apt/index.apt @@ -1,15 +1,47 @@ ----- - Home + certiorem ----- kebernet ----- - 2011-02-28 21:38:15.537 + 2011-03-19 10:30:35.292 ----- -ROME Incubator +Certiorem - This is the home of the Incubator space. + Certiorem is an implementation of the {{{http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub\-core\-0.3.html}PubSubHubub }}protocol for ROME. - To help you on your way, we've inserted some of our favourite macros on this home page. As you start creating pages, blogging and commenting you'll see the macros below fill up with all the activity in your space. + It is dependent on ROME and ROME\-Fetcher for the base implementations, and will provide standard plugins for Propono to allow for publish eventing, where applicable. - {{{./Certiorem.html}certiorem (incubator)}} The Certiorem project – A PubSubHubub implementation for ROME +*Primary Components + +*Hub Implementation and Scaffolding (Done) + + The first part of Certiorem is a basic set of scaffolding classes that can be used to create a PSH notification hub. Initially, this will include a non\-guaranteed delivery hub, with standard implementations suitable for deployment on most JavaEE application servers or Google App Engine. It is intended that there should be at least one simple, drop in WAR file, utilizing JavaEE classes that can work in a default configuration for various standard web containers. Subsequently,  each of the classes in the PSH implementation up through the primary Controller class use constructor\-time composition/configuration so that the user/developer can easily construct a custom configuration of the Hub. + +**Client Implementation Integrated with ROME\-Fetcher (Done) + + For web\-based applications that use ROME\-Fetcher, an extended push\-notified store wrapper that will update based on callbacks from a Hub of change notifications. This will include a highly configurable callback servlet to write into the Fetcher cache as changes are made. Additionally, the system should support (semi\-)real time notifications of changes in the form of a listener that exectutes in a TBD thread state relative to the callback servlet. This should be packaged as a simple JAR with no more deps than fetcher that defines the callback servlet, and automagically does subscribes where link\=rel appropriate. + +**Notification Implementation for Propono based and JAX\-RS based Servers (In Progress) + + This should be a simple API call to notify a Hub of changes to topics. Again, this should provide real\-time notifications either synchronously or asynchronously. Importantly for Asynchronous notifications, they should block subsequent change notifications pending a notification to the Hub. + + References:  + + {{{https://github.com/nlothian/RTUpdates/blob/master/src/com/nicklothian/pubsubhub/PubSubHubSubscriptionServlet.java}https://github.com/nlothian/RTUpdates/blob/master/src/com/nicklothian/pubsubhub/PubSubHubSubscriptionServlet.java}} + + {{{http://grack.com/blog/2009/09/09/parsing\-the\-pubsubhubbub\-notifications/}http://grack.com/blog/2009/09/09/parsing\-the\-pubsubhubbub\-notifications/}} + +Notes on the Code + + It is still mostly a rough sketch, but the big outlines are there: + + There are three main packages: pub, sub and hub. + + The pub package is basically just a single utility class for pushing notifications to a hub. + + The hub package contains the Hub class. This is a general business controller that is intended to allow you to build a servlet around it with a very, very thin veneer, but you could also use it to drive an XMPP or JMS version too. It is basically built by composition of a number of classes, for which there are some default implementations: A Verifier, which makes the callback to verify new subscriptions, the HubDAO which stores the current subscriptions and subscriber statistics, and a Notifier which actually sends notifications to the subscribers. There are a couple of implementations of each of these (though the JPA HubDAO is still in process). Mostly the implementations for the Verifier and Notifier support threadpooling or no\-threads (for App Engine use). + + I have just started sketching out the sub package, but it basically has a "Subscriptions" class that will take in notifications (using the same "thin veneer" pattern that the Hub class uses). It is also constructed with some impls: A SubscriptionDAO that stores you current subscription information, a FeedFetcherCache that holds the received data, and a Requester that makes the subscription requests to hubs. + + I am hoping to have a basic end to end example working sometime in the next week or so, but if anyone wants to look over what is there, feel free. diff --git a/src/site/site.xml b/src/site/site.xml index c6a5c88..61433df 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -2,14 +2,24 @@ + name="ROME Certiorem"> org.apache.maven.skins maven-fluido-skin 1.3.0 - + + + + + rometools/rome-certiorem + right + gray + + + + ROME images/romelogo.png @@ -18,14 +28,13 @@ - + - + - - - + + From d799a2b177cea2c6abb41fc740d9a1cfd4f57d52 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 11:07:38 +0200 Subject: [PATCH 06/23] Preparing release 1.5.0 Cleaned up POM --- pom.xml | 298 +++++++++++++++++++++++--------------------------------- 1 file changed, 120 insertions(+), 178 deletions(-) diff --git a/pom.xml b/pom.xml index 6168ef4..44a9acd 100644 --- a/pom.xml +++ b/pom.xml @@ -1,194 +1,136 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - 4.0.0 + 4.0.0 - com.rometools - rome-certiorem - 1.0.0-SNAPSHOT + + org.sonatype.oss + oss-parent + 9 + - rome-certiorem + com.rometools + rome-certiorem + 1.5.0-SNAPSHOT + jar - A PubSubHubub implementation for Java based on ROME + rome-certiorem - - scm:git:git@github.com:rometools/rome-certiorem.git - scm:git:git@github.com:rometools/rome-certiorem.git - https://github.com/rometools/rome-certiorem/ - + A PubSubHubub implementation for Java based on ROME - - - Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.txt - - + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + - - - kebernet - Robert Cooper - kebernet@gmail.comM - http://www.kebernet.net - - - fnajmi - Farrukh Najmi - http://wellfleetsoftware.com - - + + scm:git:git@github.com:rometools/rome-certiorem.git + scm:git:git@github.com:rometools/rome-certiorem.git + https://github.com/rometools/rome-certiorem/ + - - UTF-8 - UTF-8 - + + + Robert Cooper + kebernet@gmail.comM + http://www.kebernet.net + + + Farrukh Najmi + http://wellfleetsoftware.com + + - - - central.staging - http://oss.sonatype.org/service/local/staging/deploy/maven2 - - - sonatype.snapshots - https://oss.sonatype.org/content/repositories/snapshots - - + + UTF-8 + UTF-8 + - - - sonatype.snapshots - https://oss.sonatype.org/content/repositories/snapshots - - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-site-plugin + 3.3 + + 9000 + ${basedir}/target/site/tempdir + + + + org.apache.maven.plugins + maven-scm-publish-plugin + 1.0 + + gh-pages + ${project.scm.developerConnection} + ${project.build.directory}/site + + + + - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-site-plugin - 3.3 - - 9000 - ${basedir}/target/site/tempdir - - - - org.apache.maven.plugins - maven-scm-publish-plugin - 1.0-beta-2 - - gh-pages - scm:git:git@github.com:rometools/rome-certiorem.git - ${project.build.directory}/site - - - - + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + - - - com.rometools - rome-fetcher - 2.0.0-SNAPSHOT - - - commons-httpclient - commons-httpclient - - - commons-logging - commons-logging-api - - - commons-logging - commons-logging - - - - - javax.servlet - servlet-api - 2.5 - provided - - - javax.persistence - persistence-api - 1.0 - provided - - - junit - junit - 4.11 - test - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.7 - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - - javadoc - test-javadoc - - - - aggregate - false - - aggregate - - - - - - + + + com.rometools + rome-fetcher + 1.5.0-SNAPSHOT + + + commons-httpclient + commons-httpclient + + + commons-logging + commons-logging-api + + + commons-logging + commons-logging + + + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.persistence + persistence-api + 1.0 + provided + + + junit + junit + 4.11 + test + + From fbad9f22ee9740e30dc107461ab4d4541bcd0ce4 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 13:37:34 +0200 Subject: [PATCH 07/23] Migration to rome-parent --- cleanup.xml | 56 ---------- formatter.xml | 291 -------------------------------------------------- pom.xml | 46 +------- 3 files changed, 3 insertions(+), 390 deletions(-) delete mode 100644 cleanup.xml delete mode 100644 formatter.xml diff --git a/cleanup.xml b/cleanup.xml deleted file mode 100644 index 40f9b7a..0000000 --- a/cleanup.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/formatter.xml b/formatter.xml deleted file mode 100644 index e7ba7aa..0000000 --- a/formatter.xml +++ /dev/null @@ -1,291 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 44a9acd..ce9d992 100644 --- a/pom.xml +++ b/pom.xml @@ -5,28 +5,18 @@ 4.0.0 - org.sonatype.oss - oss-parent - 9 + com.rometools + rome-parent + 1.5.0-SNAPSHOT - com.rometools rome-certiorem - 1.5.0-SNAPSHOT jar rome-certiorem A PubSubHubub implementation for Java based on ROME - - - 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.git scm:git:git@github.com:rometools/rome-certiorem.git @@ -45,26 +35,11 @@ - - UTF-8 - UTF-8 - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - - org.apache.maven.plugins maven-site-plugin - 3.3 9000 ${basedir}/target/site/tempdir @@ -73,7 +48,6 @@ org.apache.maven.plugins maven-scm-publish-plugin - 1.0 gh-pages ${project.scm.developerConnection} @@ -83,21 +57,10 @@ - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.7 - - - - com.rometools rome-fetcher - 1.5.0-SNAPSHOT commons-httpclient @@ -116,19 +79,16 @@ javax.servlet servlet-api - 2.5 provided javax.persistence persistence-api - 1.0 provided junit junit - 4.11 test From d100aca9bbdf7d98c438a4ac635e797c9710a444 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 14:19:00 +0200 Subject: [PATCH 08/23] Removed unnecessary excludes --- pom.xml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index ce9d992..429ee41 100644 --- a/pom.xml +++ b/pom.xml @@ -63,16 +63,8 @@ rome-fetcher - commons-httpclient commons-httpclient - - - commons-logging - commons-logging-api - - - commons-logging - commons-logging + commons-httpclient From 372e2581cef998ad61bd08c49c2f889fb3d34ad1 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 15:02:38 +0200 Subject: [PATCH 09/23] Formatted and cleaned up code Fixed Java warnings --- .../certiorem/HttpStatusCodeException.java | 4 +- .../certiorem/hub/DeltaFeedInfoCache.java | 5 +- .../certiorem/hub/DeltaSyndFeedInfo.java | 38 ++++++++----- .../java/org/rometools/certiorem/hub/Hub.java | 57 ++++++++++++------- .../org/rometools/certiorem/hub/Notifier.java | 14 +++-- .../org/rometools/certiorem/hub/Verifier.java | 15 ++--- .../rometools/certiorem/hub/data/HubDAO.java | 2 +- .../certiorem/hub/data/Subscriber.java | 34 ++++++----- .../hub/data/SubscriptionSummary.java | 18 +++--- .../certiorem/hub/data/jpa/JPADAO.java | 6 +- .../certiorem/hub/data/jpa/JPASubscriber.java | 18 +++--- .../hub/data/ram/InMemoryHubDAO.java | 4 +- .../hub/notify/standard/AbstractNotifier.java | 25 ++++---- .../hub/notify/standard/Notification.java | 2 +- .../notify/standard/ThreadPoolNotifier.java | 14 +++-- .../notify/standard/UnthreadedNotifier.java | 15 ++--- .../hub/verify/standard/AbstractVerifier.java | 8 ++- .../verify/standard/ThreadPoolVerifier.java | 2 +- .../standard/ThreadpoolVerifierAdvanced.java | 2 +- .../verify/standard/UnthreadedVerifier.java | 2 +- .../certiorem/pub/NotificationException.java | 7 ++- .../rometools/certiorem/pub/Publisher.java | 34 ++++++----- .../rometools/certiorem/sub/Requester.java | 2 +- .../certiorem/sub/Subscriptions.java | 2 +- .../rometools/certiorem/sub/data/SubDAO.java | 2 +- .../certiorem/sub/data/Subscription.java | 30 +++++----- .../sub/data/SubscriptionCallback.java | 2 +- .../sub/data/ram/InMemorySubDAO.java | 2 +- .../sub/request/AbstractRequester.java | 2 +- .../certiorem/sub/request/AsyncRequester.java | 2 +- .../certiorem/sub/request/SyncRequester.java | 2 +- .../certiorem/web/AbstractHubServlet.java | 6 +- .../certiorem/web/AbstractSubServlet.java | 6 +- .../certiorem/hub/AlwaysVerifier.java | 2 +- .../certiorem/hub/ControllerTest.java | 2 +- .../certiorem/hub/DeltaSyndFeedInfoTest.java | 8 ++- .../certiorem/hub/ExceptionVerifier.java | 2 +- .../certiorem/hub/NeverVerifier.java | 2 +- .../certiorem/hub/data/AbstractDAOTest.java | 10 ++-- .../hub/data/ram/InMemoryDAOTest.java | 2 +- 40 files changed, 244 insertions(+), 168 deletions(-) diff --git a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java b/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java index d1ff1b0..da7cf16 100644 --- a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java +++ b/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java @@ -19,11 +19,13 @@ package org.rometools.certiorem; /** - * + * * @author robert.cooper */ public class HttpStatusCodeException extends RuntimeException { + private static final long serialVersionUID = 1L; + private final int status; public HttpStatusCodeException(final int status, final String message, final Throwable cause) { diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java index edf0c02..7b9a727 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java +++ b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java @@ -10,9 +10,10 @@ import org.rometools.fetcher.impl.FeedFetcherCache; import org.rometools.fetcher.impl.SyndFeedInfo; /** - * Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure that any SyndFeedInfo used within it are replaced with a DeltaSyndFeedInfo + * Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure + * that any SyndFeedInfo used within it are replaced with a DeltaSyndFeedInfo * which is capable of tracking changes to entries in the underlying feed. - * + * * @author najmi */ public class DeltaFeedInfoCache implements FeedFetcherCache { diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java index ed9284e..9a1836d 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java +++ b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java @@ -18,18 +18,21 @@ import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; /** - * Extends SyndFeedInfo to also track etags for individual entries. This may be used with DeltaFeedInfoCache to only return feed with a subset of entries that - * have changed since last fetch. - * + * Extends SyndFeedInfo to also track etags for individual entries. This may be + * used with DeltaFeedInfoCache to only return feed with a subset of entries + * that have changed since last fetch. + * * @author najmi */ public class DeltaSyndFeedInfo extends SyndFeedInfo { + + /** + * + */ + private static final long serialVersionUID = 1L; Map entryTagsMap = new HashMap(); Map changedMap = new HashMap(); - private DeltaSyndFeedInfo() { - } - public DeltaSyndFeedInfo(final SyndFeedInfo backingFeedInfo) { setETag(backingFeedInfo.getETag()); setId(backingFeedInfo.getId()); @@ -38,8 +41,9 @@ public class DeltaSyndFeedInfo extends SyndFeedInfo { } /** - * Gets a filtered version of the SyndFeed that only has entries that were changed in the last setSyndFeed() call. - * + * Gets a filtered version of the SyndFeed that only has entries that were + * changed in the last setSyndFeed() call. + * * @return */ @Override @@ -65,8 +69,9 @@ public class DeltaSyndFeedInfo extends SyndFeedInfo { } /** - * Overrides super class method to update changedMap and entryTagsMap for tracking changed entries. - * + * Overrides super class method to update changedMap and entryTagsMap for + * tracking changed entries. + * * @param feed */ @Override @@ -89,9 +94,12 @@ public class DeltaSyndFeedInfo extends SyndFeedInfo { private String computeEntryTag(final SyndEntry entry) { - // Following hash algorithm suggested by Robert Cooper needs to be evaluated in future. - // int hash = ( entry.getUri() != null ? entry.getUri().hashCode() : entry.getLink().hashCode() ) ^ - // (entry.getUpdatedDate() != null ? entry.getUpdatedDate().hashCode() : entry.getPublishedDate().hashCode()) ^ + // Following hash algorithm suggested by Robert Cooper needs to be + // evaluated in future. + // int hash = ( entry.getUri() != null ? entry.getUri().hashCode() : + // entry.getLink().hashCode() ) ^ + // (entry.getUpdatedDate() != null ? entry.getUpdatedDate().hashCode() : + // entry.getPublishedDate().hashCode()) ^ // entry.getTitle().hashCode() ^ // entry.getDescription().hashCode(); @@ -102,7 +110,9 @@ public class DeltaSyndFeedInfo extends SyndFeedInfo { if (publishedDate != null) { updateDate = publishedDate; } else { - // For misbehaving feeds that do not set updateDate or publishedDate we use current tiem which pretty mucg assures that it will be viewed as + // For misbehaving feeds that do not set updateDate or + // publishedDate we use current tiem which pretty mucg assures + // that it will be viewed as // changed even when it is not updateDate = new Date(); } diff --git a/src/main/java/org/rometools/certiorem/hub/Hub.java b/src/main/java/org/rometools/certiorem/hub/Hub.java index da5b446..ac4665f 100644 --- a/src/main/java/org/rometools/certiorem/hub/Hub.java +++ b/src/main/java/org/rometools/certiorem/hub/Hub.java @@ -39,9 +39,10 @@ import org.rometools.fetcher.FeedFetcher; import com.sun.syndication.feed.synd.SyndFeed; /** - * The basic business logic controller for the Hub implementation. It is intended to be usable under a very thin servlet wrapper, or other, non-HTTP + * The basic business logic controller for the Hub implementation. It is + * intended to be usable under a very thin servlet wrapper, or other, non-HTTP * notification methods you might want to use. - * + * * @author robert.cooper */ public class Hub { @@ -62,7 +63,7 @@ public class Hub { /** * Constructs a new Hub instance - * + * * @param dao The persistence HubDAO to use * @param verifier The verification strategy to use. */ @@ -72,18 +73,21 @@ public class Hub { this.notifier = notifier; this.fetcher = fetcher; validSchemes = STANDARD_SCHEMES; - validPorts = Collections.EMPTY_SET; - validTopics = Collections.EMPTY_SET; + validPorts = Collections.emptySet(); + validTopics = Collections.emptySet(); } /** * Constructs a new Hub instance. - * + * * @param dao The persistence HubDAO to use * @param verifier The verification strategy to use - * @param validSchemes A list of valid URI schemes for callbacks (default: http, https) - * @param validPorts A list of valid port numbers for callbacks (default: any) - * @param validTopics A set of valid topic URIs which can be subscribed to (default: any) + * @param validSchemes A list of valid URI schemes for callbacks (default: + * http, https) + * @param validPorts A list of valid port numbers for callbacks (default: + * any) + * @param validTopics A set of valid topic URIs which can be subscribed to + * (default: any) */ public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher, final Set validSchemes, final Set validPorts, final Set validTopics) { @@ -96,18 +100,29 @@ public class Hub { this.validSchemes = readOnlySchemes == null ? STANDARD_SCHEMES : readOnlySchemes; final Set readOnlyPorts = Collections.unmodifiableSet(validPorts); - this.validPorts = readOnlyPorts == null ? Collections.EMPTY_SET : readOnlyPorts; + if (readOnlyPorts == null) { + this.validPorts = Collections.emptySet(); + } else { + this.validPorts = readOnlyPorts; + } final Set readOnlyTopics = Collections.unmodifiableSet(validTopics); - this.validTopics = readOnlyTopics == null ? Collections.EMPTY_SET : readOnlyTopics; + if (validTopics == null) { + this.validTopics = Collections.emptySet(); + } else { + this.validTopics = readOnlyTopics; + } + } /** * Sends a notification to the subscribers - * - * @param requestHost the host name the hub is running on. (Used for the user agent) + * + * @param requestHost the host name the hub is running on. (Used for the + * user agent) * @param topic the URL of the topic that was updated. - * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the request. + * @throws HttpStatusCodeException a wrapper exception with a recommended + * status code for the request. */ public void sendNotification(final String requestHost, final String topic) { assert validTopics.isEmpty() || validTopics.contains(topic) : "That topic is not supported by this hub. " + topic; @@ -120,7 +135,7 @@ public class Hub { return; } - final List summaries = (List) dao.summariesForTopic(topic); + final List summaries = dao.summariesForTopic(topic); int total = 0; final StringBuilder hosts = new StringBuilder(); @@ -135,7 +150,7 @@ public class Hub { .append(" subscribers)").append(hosts); final SyndFeed feed = fetcher.retrieveFeed(userAgent.toString(), new URL(topic)); Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Got feed for {0} Sending to {1} subscribers.", new Object[] { topic, subscribers.size() }); - notifier.notifySubscribers((List) subscribers, feed, new SubscriptionSummaryCallback() { + notifier.notifySubscribers(subscribers, feed, new SubscriptionSummaryCallback() { @Override public void onSummaryInfo(final SubscriptionSummary summary) { dao.handleSummary(topic, summary); @@ -149,16 +164,18 @@ public class Hub { /** * Subscribes to a topic. - * + * * @param callback Callback URI * @param topic Topic URI * @param verify Verification Type * @param lease_seconds Duration of the lease * @param secret Secret value * @param verify_token verify_token; - * @return Boolean.TRUE if the subscription succeeded synchronously, Boolean.FALSE if the subscription failed synchronously, or null if the request is - * asynchronous. - * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the request. + * @return Boolean.TRUE if the subscription succeeded synchronously, + * Boolean.FALSE if the subscription failed synchronously, or null + * if the request is asynchronous. + * @throws HttpStatusCodeException a wrapper exception with a recommended + * status code for the request. */ public Boolean subscribe(final String callback, final String topic, final String verify, final long lease_seconds, final String secret, final String verify_token) { diff --git a/src/main/java/org/rometools/certiorem/hub/Notifier.java b/src/main/java/org/rometools/certiorem/hub/Notifier.java index dfc01fb..576b778 100644 --- a/src/main/java/org/rometools/certiorem/hub/Notifier.java +++ b/src/main/java/org/rometools/certiorem/hub/Notifier.java @@ -26,25 +26,27 @@ import org.rometools.certiorem.hub.data.SubscriptionSummary; import com.sun.syndication.feed.synd.SyndFeed; /** - * + * * @author robert.cooper */ public interface Notifier { /** - * Instructs the notifier to begin sending notifications to the list of subscribers - * + * Instructs the notifier to begin sending notifications to the list of + * subscribers + * * @param subscribers Subscribers to notify * @param value The SyndFeed to send them - * @param callback A callback that is invoked each time a subscriber is notified. + * @param callback A callback that is invoked each time a subscriber is + * notified. */ - public void notifySubscribers(List subscribers, SyndFeed value, SubscriptionSummaryCallback callback); + public void notifySubscribers(List subscribers, SyndFeed value, SubscriptionSummaryCallback callback); /** * A callback that is invoked each time a subscriber is notified. */ public static interface SubscriptionSummaryCallback { /** - * + * * @param summary A summary of the data received from the subscriber */ public void onSummaryInfo(SubscriptionSummary summary); diff --git a/src/main/java/org/rometools/certiorem/hub/Verifier.java b/src/main/java/org/rometools/certiorem/hub/Verifier.java index fe79e78..4a6c58f 100644 --- a/src/main/java/org/rometools/certiorem/hub/Verifier.java +++ b/src/main/java/org/rometools/certiorem/hub/Verifier.java @@ -22,7 +22,7 @@ import org.rometools.certiorem.hub.data.Subscriber; /** * A strategy interface for verification of subscriptions. - * + * * @author robert.cooper */ public interface Verifier { @@ -38,7 +38,7 @@ public interface Verifier { /** * Verifies a subscriber (possibly) asyncronously - * + * * @param subscriber the Subscriber to verify * @param callback a callback with the result of the verification. */ @@ -46,7 +46,7 @@ public interface Verifier { /** * Verifies a subscriber syncronously - * + * * @param subscriber The subscriber data * @return boolean result; */ @@ -54,7 +54,7 @@ public interface Verifier { /** * Verifies am unsubscribe (possibly) asyncronously - * + * * @param subscriber The subscriber data * @param callback result */ @@ -62,18 +62,19 @@ public interface Verifier { /** * Verifies an unsubscribe syncronously - * + * * @param subscriber The subscriber data * @return boolean result; */ public boolean verifyUnsubcribeSyncronously(Subscriber subscriber); /** - * An interface for capturing the result of a verification (subscribe or unsubscribe) + * An interface for capturing the result of a verification (subscribe or + * unsubscribe) */ public static interface VerificationCallback { /** - * + * * @param verified success state of the verification */ public void onVerify(boolean verified); diff --git a/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java b/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java index bd23698..249693b 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java +++ b/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java @@ -21,7 +21,7 @@ package org.rometools.certiorem.hub.data; import java.util.List; /** - * + * * @author robert.cooper */ public interface HubDAO { diff --git a/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java b/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java index ed56456..c8bbe8f 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java +++ b/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java @@ -21,10 +21,14 @@ package org.rometools.certiorem.hub.data; import java.io.Serializable; /** - * + * * @author robert.cooper */ public class Subscriber implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; public static final String VERIFY_SYNC = "sync"; public static final String VERIFY_ASYNC = "async"; private String callback; @@ -37,7 +41,7 @@ public class Subscriber implements Serializable { /** * Set the value of callback - * + * * @param newcallback new value of callback */ public void setCallback(final String newcallback) { @@ -46,7 +50,7 @@ public class Subscriber implements Serializable { /** * Get the value of callback - * + * * @return the value of callback */ public String getCallback() { @@ -55,7 +59,7 @@ public class Subscriber implements Serializable { /** * Set the value of creationTime - * + * * @param newcreationTime new value of creationTime */ public void setCreationTime(final long newcreationTime) { @@ -64,7 +68,7 @@ public class Subscriber implements Serializable { /** * Get the value of creationTime - * + * * @return the value of creationTime */ public long getCreationTime() { @@ -73,7 +77,7 @@ public class Subscriber implements Serializable { /** * Set the value of leaseSeconds - * + * * @param newleaseSeconds new value of leaseSeconds */ public void setLeaseSeconds(final long newleaseSeconds) { @@ -82,7 +86,7 @@ public class Subscriber implements Serializable { /** * Get the value of leaseSeconds - * + * * @return the value of leaseSeconds */ public long getLeaseSeconds() { @@ -91,7 +95,7 @@ public class Subscriber implements Serializable { /** * Set the value of secret - * + * * @param newsecret new value of secret */ public void setSecret(final String newsecret) { @@ -100,7 +104,7 @@ public class Subscriber implements Serializable { /** * Get the value of secret - * + * * @return the value of secret */ public String getSecret() { @@ -109,7 +113,7 @@ public class Subscriber implements Serializable { /** * Set the value of topic - * + * * @param newtopic new value of topic */ public void setTopic(final String newtopic) { @@ -118,7 +122,7 @@ public class Subscriber implements Serializable { /** * Get the value of topic - * + * * @return the value of topic */ public String getTopic() { @@ -127,7 +131,7 @@ public class Subscriber implements Serializable { /** * Set the value of verify - * + * * @param newverify new value of verify */ public void setVerify(final String newverify) { @@ -136,7 +140,7 @@ public class Subscriber implements Serializable { /** * Get the value of verify - * + * * @return the value of verify */ public String getVerify() { @@ -145,7 +149,7 @@ public class Subscriber implements Serializable { /** * Set the value of vertifyToken - * + * * @param newvertifyToken new value of vertifyToken */ public void setVertifyToken(final String newvertifyToken) { @@ -154,7 +158,7 @@ public class Subscriber implements Serializable { /** * Get the value of vertifyToken - * + * * @return the value of vertifyToken */ public String getVertifyToken() { diff --git a/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java b/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java index 90dd65d..8e7d3d0 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java +++ b/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java @@ -21,17 +21,21 @@ package org.rometools.certiorem.hub.data; import java.io.Serializable; /** - * + * * @author robert.cooper */ public class SubscriptionSummary implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; private String host; private boolean lastPublishSuccessful = true; private int subscribers = 0; /** * Set the value of host - * + * * @param newhost new value of host */ public void setHost(final String newhost) { @@ -40,7 +44,7 @@ public class SubscriptionSummary implements Serializable { /** * Get the value of host - * + * * @return the value of host */ public String getHost() { @@ -49,7 +53,7 @@ public class SubscriptionSummary implements Serializable { /** * Set the value of lastPublishSuccessful - * + * * @param newlastPublishSuccessful new value of lastPublishSuccessful */ public void setLastPublishSuccessful(final boolean newlastPublishSuccessful) { @@ -58,7 +62,7 @@ public class SubscriptionSummary implements Serializable { /** * Get the value of lastPublishSuccessful - * + * * @return the value of lastPublishSuccessful */ public boolean isLastPublishSuccessful() { @@ -67,7 +71,7 @@ public class SubscriptionSummary implements Serializable { /** * Set the value of subscribers - * + * * @param newsubscribers new value of subscribers */ public void setSubscribers(final int newsubscribers) { @@ -76,7 +80,7 @@ public class SubscriptionSummary implements Serializable { /** * Get the value of subscribers - * + * * @return the value of subscribers */ public int getSubscribers() { diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java index b8d6c50..01d1f4b 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java +++ b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java @@ -33,7 +33,7 @@ import org.rometools.certiorem.hub.data.Subscriber; import org.rometools.certiorem.hub.data.SubscriptionSummary; /** - * + * * @author robert.cooper */ public class JPADAO implements HubDAO { @@ -57,7 +57,9 @@ public class JPADAO implements HubDAO { query.setParameter("topic", topic); try { - for (final JPASubscriber subscriber : (List) query.getResultList()) { + @SuppressWarnings("unchecked") + final List subscribers = query.getResultList(); + for (final JPASubscriber subscriber : subscribers) { if (subscriber.getLeaseSeconds() == -1) { result.add(subscriber); continue; diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java index 6b8621a..fe80d94 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java +++ b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java @@ -31,19 +31,23 @@ import javax.persistence.TemporalType; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ @Entity @NamedQueries({ @NamedQuery(name = "Subcriber.forTopic", query = "SELECT o FROM JPASubscriber o WHERE o.topic = :topic AND o.expired = false ORDER BY o.subscribedAt") }) public class JPASubscriber extends Subscriber implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; private Date subscribedAt = new Date(); private String id; private boolean expired = false; /** * Set the value of expired - * + * * @param newexpired new value of expired */ public void setExpired(final boolean newexpired) { @@ -52,7 +56,7 @@ public class JPASubscriber extends Subscriber implements Serializable { /** * Get the value of expired - * + * * @return the value of expired */ public boolean isExpired() { @@ -61,7 +65,7 @@ public class JPASubscriber extends Subscriber implements Serializable { /** * Set the value of id - * + * * @param newid new value of id */ public void setId(final String newid) { @@ -70,7 +74,7 @@ public class JPASubscriber extends Subscriber implements Serializable { /** * Get the value of id - * + * * @return the value of id */ @Id @@ -80,7 +84,7 @@ public class JPASubscriber extends Subscriber implements Serializable { /** * Set the value of subscribedAt - * + * * @param newsubscribedAt new value of subscribedAt */ public void setSubscribedAt(final Date newsubscribedAt) { @@ -89,7 +93,7 @@ public class JPASubscriber extends Subscriber implements Serializable { /** * Get the value of subscribedAt - * + * * @return the value of subscribedAt */ @Temporal(TemporalType.TIMESTAMP) diff --git a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java b/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java index 44497db..72a8075 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java +++ b/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java @@ -30,7 +30,7 @@ import org.rometools.certiorem.hub.data.SubscriptionSummary; /** * A Simple In-Memory HubDAO for subscribers. - * + * * @author robert.cooper */ public class InMemoryHubDAO implements HubDAO { @@ -89,7 +89,7 @@ public class InMemoryHubDAO implements HubDAO { return result; } else { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java index 7cf9cc0..10d1f8a 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java @@ -38,22 +38,24 @@ import com.sun.syndication.io.FeedException; import com.sun.syndication.io.SyndFeedOutput; /** - * + * * @author robert.cooper */ public abstract class AbstractNotifier implements Notifier { /** - * This method will serialize the synd feed and build Notifications for the implementation class to handle. - * + * This method will serialize the synd feed and build Notifications for the + * implementation class to handle. + * * @see enqueueNotification - * + * * @param subscribers List of subscribers to notify * @param value The SyndFeed object to send - * @param callback A callback that will be invoked each time a subscriber is notified. - * + * @param callback A callback that will be invoked each time a subscriber is + * notified. + * */ @Override - public void notifySubscribers(final List subscribers, final SyndFeed value, final SubscriptionSummaryCallback callback) { + public void notifySubscribers(final List subscribers, final SyndFeed value, final SubscriptionSummaryCallback callback) { String mimeType = null; if (value.getFeedType().startsWith("rss")) { @@ -92,15 +94,16 @@ public abstract class AbstractNotifier implements Notifier { /** * Implementation method that queues/sends a notification - * + * * @param not notification to send. */ protected abstract void enqueueNotification(Notification not); /** - * POSTs the payload to the subscriber's callback and returns a SubscriptionSummary with subscriber counts (where possible) and the success state of the - * notification. - * + * POSTs the payload to the subscriber's callback and returns a + * SubscriptionSummary with subscriber counts (where possible) and the + * success state of the notification. + * * @param subscriber subscriber data. * @param mimeType MIME type for the request * @param payload payload of the feed to send diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java index 053e091..f0c62e6 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java @@ -22,7 +22,7 @@ import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ public class Notification { diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java index d305f5a..42db9e9 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java @@ -28,8 +28,9 @@ import java.util.concurrent.TimeUnit; import org.rometools.certiorem.hub.data.SubscriptionSummary; /** - * A notifier implementation that uses a thread pool to deliver notifications to subscribers - * + * A notifier implementation that uses a thread pool to deliver notifications to + * subscribers + * * @author robert.cooper */ public class ThreadPoolNotifier extends AbstractNotifier { @@ -51,9 +52,10 @@ public class ThreadPoolNotifier extends AbstractNotifier { } /** - * Enqueues a notification to run. If the notification fails, it will be retried every two minutes until 5 attempts are completed. Notifications to the same - * callback should be delivered successfully in order. - * + * Enqueues a notification to run. If the notification fails, it will be + * retried every two minutes until 5 attempts are completed. Notifications + * to the same callback should be delivered successfully in order. + * * @param not */ @Override @@ -82,7 +84,7 @@ public class ThreadPoolNotifier extends AbstractNotifier { /** * Schedules a notification to retry in two minutes. - * + * * @param not Notification to retry */ protected void retry(final Notification not) { diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java index 303bf9d..f591b43 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java @@ -18,30 +18,27 @@ package org.rometools.certiorem.hub.notify.standard; -import java.util.concurrent.ConcurrentSkipListSet; - import org.rometools.certiorem.hub.data.SubscriptionSummary; /** * A notifier that does not use threads. All calls are blocking and synchronous. - * + * * @author robert.cooper */ public class UnthreadedNotifier extends AbstractNotifier { - private final ConcurrentSkipListSet retries = new ConcurrentSkipListSet(); /** - * A blocking call that performs a notification. If there are pending retries that are older than two minutes old, they will be retried before the method - * returns. - * + * A blocking call that performs a notification. If there are pending + * retries that are older than two minutes old, they will be retried before + * the method returns. + * * @param not */ @Override protected void enqueueNotification(final Notification not) { not.lastRun = System.currentTimeMillis(); - final SubscriptionSummary summary = postNotification(not.subscriber, not.mimeType, not.payload); - not.callback.onSummaryInfo(summary); } + } diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java index 528505f..53d775c 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java @@ -34,8 +34,9 @@ import org.rometools.certiorem.hub.Verifier; import org.rometools.certiorem.hub.data.Subscriber; /** - * An abstract verifier based on the java.net HTTP classes. This implements only synchronous operations, and expects a child class to do Async ops. - * + * An abstract verifier based on the java.net HTTP classes. This implements only + * synchronous operations, and expects a child class to do Async ops. + * * @author robert.cooper */ public abstract class AbstractVerifier implements Verifier { @@ -68,7 +69,8 @@ public abstract class AbstractVerifier implements Verifier { final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); // connection.setRequestProperty("Host", url.getHost()); - // connection.setRequestProperty("Port", Integer.toString(url.getPort())); + // connection.setRequestProperty("Port", + // Integer.toString(url.getPort())); connection.setRequestProperty("User-Agent", "ROME-Certiorem"); connection.connect(); final int rc = connection.getResponseCode(); diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java index 7bc7452..bb806ea 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java @@ -26,7 +26,7 @@ import org.rometools.certiorem.hub.data.Subscriber; /** * Uses a ThreadPoolExecutor to do async verifications. - * + * * @author robert.cooper */ public class ThreadPoolVerifier extends AbstractVerifier { diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java index 4a206fe..19d9b5f 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java @@ -21,7 +21,7 @@ package org.rometools.certiorem.hub.verify.standard; import java.util.concurrent.ThreadPoolExecutor; /** - * + * * @author robert.cooper */ public class ThreadpoolVerifierAdvanced extends ThreadPoolVerifier { diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java index 69b1f19..060965c 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java @@ -22,7 +22,7 @@ import org.rometools.certiorem.hub.data.Subscriber; /** * A verifier that does not use threads. Suitable for Google App Engine. - * + * * @author robert.cooper */ public class UnthreadedVerifier extends AbstractVerifier { diff --git a/src/main/java/org/rometools/certiorem/pub/NotificationException.java b/src/main/java/org/rometools/certiorem/pub/NotificationException.java index 9138694..2e46354 100644 --- a/src/main/java/org/rometools/certiorem/pub/NotificationException.java +++ b/src/main/java/org/rometools/certiorem/pub/NotificationException.java @@ -19,11 +19,16 @@ package org.rometools.certiorem.pub; /** - * + * * @author robert.cooper */ public class NotificationException extends Exception { + /** + * + */ + private static final long serialVersionUID = 1L; + public NotificationException(final String message) { super(message); } diff --git a/src/main/java/org/rometools/certiorem/pub/Publisher.java b/src/main/java/org/rometools/certiorem/pub/Publisher.java index 5ac17b6..0f6d4f2 100644 --- a/src/main/java/org/rometools/certiorem/pub/Publisher.java +++ b/src/main/java/org/rometools/certiorem/pub/Publisher.java @@ -33,20 +33,22 @@ import com.sun.syndication.feed.synd.SyndLink; /** * A class for sending update notifications to a hub. - * + * * @author robert.cooper */ public class Publisher { private ThreadPoolExecutor executor; /** - * Constructs a new publisher. This publisher will spawn a new thread for each async send. + * Constructs a new publisher. This publisher will spawn a new thread for + * each async send. */ public Publisher() { } /** - * Constructs a new publisher with an optional ThreadPoolExector for sending updates. + * Constructs a new publisher with an optional ThreadPoolExector for sending + * updates. */ public Publisher(final ThreadPoolExecutor executor) { this.executor = executor; @@ -54,7 +56,7 @@ public class Publisher { /** * Sends the HUB url a notification of a change in topic - * + * * @param hub URL of the hub to notify. * @param topic The Topic that has changed * @throws NotificationException Any failure @@ -91,8 +93,9 @@ public class Publisher { } /** - * Sends a notification for a feed located at "topic". The feed MUST contain rel="hub". - * + * Sends a notification for a feed located at "topic". The feed MUST contain + * rel="hub". + * * @param topic URL for the feed * @param feed The feed itself * @throws NotificationException Any failure @@ -109,8 +112,9 @@ public class Publisher { } /** - * Sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links. - * + * Sends a notification for a feed. The feed MUST contain rel="hub" and + * rel="self" links. + * * @param feed The feed to notify * @throws NotificationException Any failure */ @@ -145,7 +149,7 @@ public class Publisher { /** * Sends the HUB url a notification of a change in topic asynchronously - * + * * @param hub URL of the hub to notify. * @param topic The Topic that has changed * @param callback A callback invoked when the notification completes. @@ -172,8 +176,9 @@ public class Publisher { } /** - * Asynchronously sends a notification for a feed located at "topic". The feed MUST contain rel="hub". - * + * Asynchronously sends a notification for a feed located at "topic". The + * feed MUST contain rel="hub". + * * @param topic URL for the feed * @param feed The feed itself * @param callback A callback invoked when the notification completes. @@ -200,8 +205,9 @@ public class Publisher { } /** - * Asyncronously sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links. - * + * Asyncronously sends a notification for a feed. The feed MUST contain + * rel="hub" and rel="self" links. + * * @param feed The feed to notify * @param callback A callback invoked when the notification completes. * @throws NotificationException Any failure @@ -232,7 +238,7 @@ public class Publisher { public static interface AsyncNotificationCallback { /** * Called when a notification fails - * + * * @param thrown Whatever was thrown during the failure */ public void onFailure(Throwable thrown); diff --git a/src/main/java/org/rometools/certiorem/sub/Requester.java b/src/main/java/org/rometools/certiorem/sub/Requester.java index 3bfce54..ce027c0 100644 --- a/src/main/java/org/rometools/certiorem/sub/Requester.java +++ b/src/main/java/org/rometools/certiorem/sub/Requester.java @@ -21,7 +21,7 @@ package org.rometools.certiorem.sub; import org.rometools.certiorem.sub.data.Subscription; /** - * + * * @author robert.cooper */ public interface Requester { diff --git a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java index 1f04342..87269b1 100644 --- a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java +++ b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java @@ -45,7 +45,7 @@ import com.sun.syndication.io.FeedException; import com.sun.syndication.io.SyndFeedInput; /** - * + * * @author robert.cooper */ public class Subscriptions { diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java b/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java index dac96f5..00692e1 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java +++ b/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java @@ -19,7 +19,7 @@ package org.rometools.certiorem.sub.data; /** - * + * * @author robert.cooper */ public interface SubDAO { diff --git a/src/main/java/org/rometools/certiorem/sub/data/Subscription.java b/src/main/java/org/rometools/certiorem/sub/data/Subscription.java index c6f19c6..8978c7a 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/Subscription.java +++ b/src/main/java/org/rometools/certiorem/sub/data/Subscription.java @@ -21,10 +21,14 @@ package org.rometools.certiorem.sub.data; import java.io.Serializable; /** - * + * * @author robert.cooper */ public class Subscription implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; private String id; private String sourceUrl; private String verifyToken; @@ -35,7 +39,7 @@ public class Subscription implements Serializable { /** * Set the value of expirationTime - * + * * @param newexpirationTime new value of expirationTime */ public void setExpirationTime(final long newexpirationTime) { @@ -44,7 +48,7 @@ public class Subscription implements Serializable { /** * Get the value of expirationTime - * + * * @return the value of expirationTime */ public long getExpirationTime() { @@ -53,7 +57,7 @@ public class Subscription implements Serializable { /** * Set the value of id - * + * * @param newid new value of id */ public void setId(final String newid) { @@ -62,7 +66,7 @@ public class Subscription implements Serializable { /** * Get the value of id - * + * * @return the value of id */ public String getId() { @@ -71,7 +75,7 @@ public class Subscription implements Serializable { /** * Set the value of sourceUrl - * + * * @param newsourceUrl new value of sourceUrl */ public void setSourceUrl(final String newsourceUrl) { @@ -80,7 +84,7 @@ public class Subscription implements Serializable { /** * Get the value of sourceUrl - * + * * @return the value of sourceUrl */ public String getSourceUrl() { @@ -89,7 +93,7 @@ public class Subscription implements Serializable { /** * Set the value of unsubscribed - * + * * @param newunsubscribed new value of unsubscribed */ public void setUnsubscribed(final boolean newunsubscribed) { @@ -98,7 +102,7 @@ public class Subscription implements Serializable { /** * Get the value of unsubscribed - * + * * @return the value of unsubscribed */ public boolean isUnsubscribed() { @@ -107,7 +111,7 @@ public class Subscription implements Serializable { /** * Set the value of validated - * + * * @param newvalidated new value of validated */ public void setValidated(final boolean newvalidated) { @@ -116,7 +120,7 @@ public class Subscription implements Serializable { /** * Get the value of validated - * + * * @return the value of validated */ public boolean isValidated() { @@ -125,7 +129,7 @@ public class Subscription implements Serializable { /** * Set the value of verifyToken - * + * * @param newverifyToken new value of verifyToken */ public void setVerifyToken(final String newverifyToken) { @@ -134,7 +138,7 @@ public class Subscription implements Serializable { /** * Get the value of verifyToken - * + * * @return the value of verifyToken */ public String getVerifyToken() { diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java b/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java index 01018df..6a82aff 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java +++ b/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java @@ -8,7 +8,7 @@ package org.rometools.certiorem.sub.data; import org.rometools.fetcher.impl.SyndFeedInfo; /** - * + * * @author najmi */ public interface SubscriptionCallback { diff --git a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java b/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java index 0e50fce..0d32815 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java +++ b/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java @@ -32,7 +32,7 @@ import org.rometools.certiorem.sub.data.SubDAO; import org.rometools.certiorem.sub.data.Subscription; /** - * + * * @author robert.cooper */ public class InMemorySubDAO implements SubDAO { diff --git a/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java b/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java index 532260f..b6abf20 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java +++ b/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java @@ -27,7 +27,7 @@ import org.rometools.certiorem.sub.Requester; import org.rometools.certiorem.sub.data.Subscription; /** - * + * * @author robert.cooper */ public abstract class AbstractRequester implements Requester { diff --git a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java b/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java index 305a12b..64b5efc 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java +++ b/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java @@ -26,7 +26,7 @@ import org.rometools.certiorem.sub.data.Subscription; /** * A simple requester implementation that always makes requests as Async. - * + * * @author robert.cooper */ public class AsyncRequester extends AbstractRequester { diff --git a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java b/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java index 5cd6d17..553d2b1 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java +++ b/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java @@ -30,7 +30,7 @@ import org.rometools.certiorem.sub.data.Subscription; /** * A simple requester implementation that always makes requests as Async. - * + * * @author Farrukh Najmi */ public class SyncRequester extends AbstractRequester { diff --git a/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java b/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java index 64d9f31..0a4ff7c 100644 --- a/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java +++ b/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java @@ -30,10 +30,14 @@ import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.hub.Hub; /** - * + * * @author robert.cooper */ public abstract class AbstractHubServlet extends HttpServlet { + /** + * + */ + private static final long serialVersionUID = 1L; public static final String HUBMODE = "hub.mode"; private final Hub hub; diff --git a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java b/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java index 9a3d42e..3790667 100644 --- a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java +++ b/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java @@ -30,11 +30,15 @@ import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.sub.Subscriptions; /** - * + * * @author robert.cooper */ public class AbstractSubServlet extends HttpServlet { + /** + * + */ + private static final long serialVersionUID = 1L; private final Subscriptions subscriptions; protected AbstractSubServlet(final Subscriptions subscriptions) { diff --git a/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java b/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java index 3e01b85..5d198e8 100644 --- a/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java +++ b/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java @@ -21,7 +21,7 @@ package org.rometools.certiorem.hub; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ public class AlwaysVerifier implements Verifier { diff --git a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java index f337505..5729fe2 100644 --- a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java +++ b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java @@ -36,7 +36,7 @@ import org.rometools.fetcher.impl.HashMapFeedInfoCache; import org.rometools.fetcher.impl.HttpURLFeedFetcher; /** - * + * * @author robert.cooper */ public class ControllerTest { diff --git a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java index f1526f1..da9c401 100644 --- a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java +++ b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java @@ -19,7 +19,7 @@ import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; /** - * + * * @author najmi */ public class DeltaSyndFeedInfoTest { @@ -44,7 +44,8 @@ public class DeltaSyndFeedInfoTest { List entries = feed.getEntries(); assertTrue(!entries.isEmpty()); - // Fetch again and this time the entries should be empty as none have changed. + // Fetch again and this time the entries should be empty as none have + // changed. feed = feedFetcher.retrieveFeed(getFeedUrl()); entries = feed.getEntries(); assertTrue(entries.isEmpty()); @@ -52,7 +53,8 @@ public class DeltaSyndFeedInfoTest { private URL getFeedUrl() throws IOException { final URL feedUrl = new URL("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss"); - // URL feedUrl = new URL("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml"); + // URL feedUrl = new + // URL("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml"); return feedUrl; } diff --git a/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java b/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java index 87153b3..7e7ae45 100644 --- a/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java +++ b/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java @@ -21,7 +21,7 @@ package org.rometools.certiorem.hub; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ public class ExceptionVerifier implements Verifier { diff --git a/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java b/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java index b514293..e4733bf 100644 --- a/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java +++ b/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java @@ -21,7 +21,7 @@ package org.rometools.certiorem.hub; import org.rometools.certiorem.hub.data.Subscriber; /** - * + * * @author robert.cooper */ public class NeverVerifier implements Verifier { diff --git a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java index af8f1c7..bd0fbd2 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java +++ b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java @@ -25,7 +25,7 @@ import java.util.logging.Logger; import org.junit.Test; /** - * + * * @author robert.cooper */ public abstract class AbstractDAOTest { @@ -46,7 +46,7 @@ public abstract class AbstractDAOTest { assert result.equals(subscriber) : "Subscriber not equal."; - final List subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); + final List subscribers = instance.subscribersForTopic(subscriber.getTopic()); assert subscribers.contains(result) : "Subscriber not in result."; } @@ -65,11 +65,11 @@ public abstract class AbstractDAOTest { assert subscriber.equals(result) : "Subscriber not equal."; // quick test for store. - List subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); + List subscribers = instance.subscribersForTopic(subscriber.getTopic()); assert subscribers.contains(result) : "Subscriber not in result."; // sleep past expiration Thread.sleep(1100); - subscribers = (List) instance.subscribersForTopic(subscriber.getTopic()); + subscribers = instance.subscribersForTopic(subscriber.getTopic()); assert !subscribers.contains(result) : "Subscriber should have expired"; } @@ -83,8 +83,8 @@ public abstract class AbstractDAOTest { subscriber.setLeaseSeconds(1); subscriber.setVerify("VerifyMe"); - final Subscriber result = instance.addSubscriber(subscriber); // TODO + // final Subscriber result = instance.addSubscriber(subscriber); } } diff --git a/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java index 218fcbe..be5f0a7 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java +++ b/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java @@ -22,7 +22,7 @@ import org.rometools.certiorem.hub.data.AbstractDAOTest; import org.rometools.certiorem.hub.data.HubDAO; /** - * + * * @author robert.cooper */ public class InMemoryDAOTest extends AbstractDAOTest { From bf527ec7aa5ca798d7c364a77347717525c1c016 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 21:17:20 +0200 Subject: [PATCH 10/23] Refactored some code Replaced deprecated code --- .../certiorem/sub/Subscriptions.java | 19 +++++++++++-------- .../certiorem/web/AbstractSubServlet.java | 19 +++++++------------ .../certiorem/hub/data/AbstractDAOTest.java | 8 +++++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java index 87269b1..50646ac 100644 --- a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java +++ b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java @@ -49,6 +49,9 @@ import com.sun.syndication.io.SyndFeedInput; * @author robert.cooper */ public class Subscriptions { + + private static final Logger LOGGER = Logger.getLogger(Subscriptions.class.getName()); + // TODO unsubscribe. private FeedFetcherCache cache; private Requester requester; @@ -69,7 +72,7 @@ public class Subscriptions { try { this.callback(callbackPath, feed.getBytes("UTF-8")); } catch (final UnsupportedEncodingException ex) { - Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, null, ex); throw new HttpStatusCodeException(400, "Unable to parse feed.", ex); } } @@ -80,10 +83,10 @@ public class Subscriptions { try { this.callback(callbackPath, input.build(new InputStreamReader(feed))); } catch (final IllegalArgumentException ex) { - Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, null, ex); throw new HttpStatusCodeException(500, "Unable to parse feed.", ex); } catch (final FeedException ex) { - Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, null, ex); throw new HttpStatusCodeException(400, "Unable to parse feed.", ex); } } @@ -99,7 +102,7 @@ public class Subscriptions { } final String id = callbackPath.substring(callbackPrefix.length()); - Logger.getLogger(Subscriptions.class.getName()).log(Level.FINE, "Got callback for {0}", id); + LOGGER.log(Level.FINE, "Got callback for {0}", id); final Subscription s = dao.findById(id); if (s == null) { @@ -115,7 +118,7 @@ public class Subscriptions { url = new URL(s.getSourceUrl()); info = cache.getFeedInfo(url); } catch (final MalformedURLException ex) { - Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, null, ex); } if (info == null) { @@ -193,7 +196,7 @@ public class Subscriptions { } final String id = callbackPath.substring(callbackPrefix.length()); - Logger.getLogger(Subscriptions.class.getName()).log(Level.FINE, "Handling validation request for id {0}", id); + LOGGER.log(Level.FINE, "Handling validation request for id {0}", id); final Subscription s = dao.findById(id); if (s == null) { throw new HttpStatusCodeException(404, "Not a valid subscription id", null); @@ -218,7 +221,7 @@ public class Subscriptions { } else { throw new HttpStatusCodeException(400, "Unsupported mode " + mode, null); } - Logger.getLogger(Subscriptions.class.getName()).log(Level.FINE, "Validated. Returning {0}", challenge); + LOGGER.log(Level.FINE, "Validated. Returning {0}", challenge); return challenge; } @@ -245,7 +248,7 @@ public class Subscriptions { break; } catch (final URISyntaxException ex) { - Logger.getLogger(Subscriptions.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, null, ex); } } } diff --git a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java b/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java index 3790667..6094731 100644 --- a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java +++ b/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java @@ -21,10 +21,10 @@ package org.rometools.certiorem.web; import java.io.IOException; import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpUtils; import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.sub.Subscriptions; @@ -33,18 +33,14 @@ import org.rometools.certiorem.sub.Subscriptions; * * @author robert.cooper */ -public class AbstractSubServlet extends HttpServlet { +public abstract class AbstractSubServlet extends HttpServlet { - /** - * - */ private static final long serialVersionUID = 1L; + private final Subscriptions subscriptions; protected AbstractSubServlet(final Subscriptions subscriptions) { - super(); this.subscriptions = subscriptions; - } @Override @@ -55,23 +51,22 @@ public class AbstractSubServlet extends HttpServlet { final String leaseString = req.getParameter("hub.lease_seconds"); final String verifyToken = req.getParameter("hub.verify_token"); try { - final String result = subscriptions.validate(HttpUtils.getRequestURL(req).toString(), topic, mode, challenge, leaseString, verifyToken); + final String result = subscriptions.validate(req.getRequestURL().toString(), topic, mode, challenge, leaseString, verifyToken); resp.setStatus(200); resp.getWriter().print(result); - return; } catch (final HttpStatusCodeException e) { e.printStackTrace(); resp.setStatus(e.getStatus()); resp.getWriter().print(e.getMessage()); } - } @Override protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try { - subscriptions.callback(HttpUtils.getRequestURL(req).toString(), req.getInputStream()); - return; + final String requestUrl = req.getRequestURL().toString(); + final ServletInputStream inputStream = req.getInputStream(); + subscriptions.callback(requestUrl, inputStream); } catch (final HttpStatusCodeException e) { e.printStackTrace(); resp.setStatus(e.getStatus()); diff --git a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java index bd0fbd2..77836b3 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java +++ b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java @@ -30,12 +30,14 @@ import org.junit.Test; */ public abstract class AbstractDAOTest { + private static final Logger LOGGER = Logger.getLogger(AbstractDAOTest.class.getName()); + protected abstract HubDAO get(); @Test public void testSubscribe() { final HubDAO instance = get(); - Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testSubscribe", instance.getClass().getName()); + LOGGER.log(Level.INFO, "{0} testSubscribe", instance.getClass().getName()); final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); @@ -54,7 +56,7 @@ public abstract class AbstractDAOTest { @Test public void testLeaseExpire() throws InterruptedException { final HubDAO instance = get(); - Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testLeaseExpire", instance.getClass().getName()); + LOGGER.log(Level.INFO, "{0} testLeaseExpire", instance.getClass().getName()); final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); @@ -76,7 +78,7 @@ public abstract class AbstractDAOTest { @Test public void testUnsubscribe() throws InterruptedException { final HubDAO instance = get(); - Logger.getLogger(AbstractDAOTest.class.getName()).log(Level.INFO, "{0} testUnsubscribe", instance.getClass().getName()); + LOGGER.log(Level.INFO, "{0} testUnsubscribe", instance.getClass().getName()); final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); From 00c4101063b79564c63b246bc0fa026a7950fadc Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 14 Apr 2014 19:10:23 +0200 Subject: [PATCH 11/23] Migrated logging to SLF4J --- pom.xml | 9 ++++ .../java/org/rometools/certiorem/hub/Hub.java | 53 +++++++++---------- .../hub/notify/standard/AbstractNotifier.java | 35 ++++++------ .../hub/verify/standard/AbstractVerifier.java | 18 ++++--- .../rometools/certiorem/pub/Publisher.java | 32 +++++------ .../certiorem/sub/Subscriptions.java | 22 ++++---- .../sub/data/ram/InMemorySubDAO.java | 11 ++-- .../certiorem/sub/request/AsyncRequester.java | 17 +++--- .../certiorem/sub/request/SyncRequester.java | 17 +++--- .../certiorem/hub/ControllerTest.java | 16 +++--- .../certiorem/hub/data/AbstractDAOTest.java | 12 ++--- src/test/resources/logback-test.xml | 13 +++++ 12 files changed, 141 insertions(+), 114 deletions(-) create mode 100644 src/test/resources/logback-test.xml diff --git a/pom.xml b/pom.xml index 429ee41..7bebdae 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,15 @@ persistence-api provided + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + test + junit junit diff --git a/src/main/java/org/rometools/certiorem/hub/Hub.java b/src/main/java/org/rometools/certiorem/hub/Hub.java index ac4665f..dbe6397 100644 --- a/src/main/java/org/rometools/certiorem/hub/Hub.java +++ b/src/main/java/org/rometools/certiorem/hub/Hub.java @@ -25,8 +25,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; @@ -35,17 +33,21 @@ import org.rometools.certiorem.hub.data.HubDAO; import org.rometools.certiorem.hub.data.Subscriber; import org.rometools.certiorem.hub.data.SubscriptionSummary; import org.rometools.fetcher.FeedFetcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.synd.SyndFeed; /** - * The basic business logic controller for the Hub implementation. It is - * intended to be usable under a very thin servlet wrapper, or other, non-HTTP - * notification methods you might want to use. + * The basic business logic controller for the Hub implementation. It is intended to be usable under + * a very thin servlet wrapper, or other, non-HTTP notification methods you might want to use. * * @author robert.cooper */ public class Hub { + + private static final Logger LOG = LoggerFactory.getLogger(Hub.class); + private static final HashSet STANDARD_SCHEMES = new HashSet(); static { @@ -82,12 +84,9 @@ public class Hub { * * @param dao The persistence HubDAO to use * @param verifier The verification strategy to use - * @param validSchemes A list of valid URI schemes for callbacks (default: - * http, https) - * @param validPorts A list of valid port numbers for callbacks (default: - * any) - * @param validTopics A set of valid topic URIs which can be subscribed to - * (default: any) + * @param validSchemes A list of valid URI schemes for callbacks (default: http, https) + * @param validPorts A list of valid port numbers for callbacks (default: any) + * @param validTopics A set of valid topic URIs which can be subscribed to (default: any) */ public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher, final Set validSchemes, final Set validPorts, final Set validTopics) { @@ -118,20 +117,19 @@ public class Hub { /** * Sends a notification to the subscribers * - * @param requestHost the host name the hub is running on. (Used for the - * user agent) + * @param requestHost the host name the hub is running on. (Used for the user agent) * @param topic the URL of the topic that was updated. - * @throws HttpStatusCodeException a wrapper exception with a recommended - * status code for the request. + * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the + * request. */ public void sendNotification(final String requestHost, final String topic) { assert validTopics.isEmpty() || validTopics.contains(topic) : "That topic is not supported by this hub. " + topic; - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Sending notification for {0}", topic); + LOG.debug("Sending notification for {}", topic); try { final List subscribers = dao.subscribersForTopic(topic); if (subscribers.isEmpty()) { - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "No subscribers to notify for {0}", topic); + LOG.debug("No subscribers to notify for {}", topic); return; } @@ -149,7 +147,7 @@ public class Hub { final StringBuilder userAgent = new StringBuilder("ROME-Certiorem (+http://").append(requestHost).append("; ").append(total) .append(" subscribers)").append(hosts); final SyndFeed feed = fetcher.retrieveFeed(userAgent.toString(), new URL(topic)); - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Got feed for {0} Sending to {1} subscribers.", new Object[] { topic, subscribers.size() }); + LOG.debug("Got feed for {} Sending to {} subscribers.", topic, subscribers.size()); notifier.notifySubscribers(subscribers, feed, new SubscriptionSummaryCallback() { @Override public void onSummaryInfo(final SubscriptionSummary summary) { @@ -157,7 +155,7 @@ public class Hub { } }); } catch (final Exception ex) { - Logger.getLogger(Hub.class.getName()).log(Level.SEVERE, "Exception getting " + topic, ex); + LOG.debug("Exception getting " + topic, ex); throw new HttpStatusCodeException(500, ex.getMessage(), ex); } } @@ -171,15 +169,14 @@ public class Hub { * @param lease_seconds Duration of the lease * @param secret Secret value * @param verify_token verify_token; - * @return Boolean.TRUE if the subscription succeeded synchronously, - * Boolean.FALSE if the subscription failed synchronously, or null - * if the request is asynchronous. - * @throws HttpStatusCodeException a wrapper exception with a recommended - * status code for the request. + * @return Boolean.TRUE if the subscription succeeded synchronously, Boolean.FALSE if the + * subscription failed synchronously, or null if the request is asynchronous. + * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the + * request. */ public Boolean subscribe(final String callback, final String topic, final String verify, final long lease_seconds, final String secret, final String verify_token) { - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "{0} wants to subscribe to {1}", new Object[] { callback, topic }); + LOG.debug("{} wants to subscribe to {}", callback, topic); try { try { assert callback != null : "Callback URL is required."; @@ -206,8 +203,7 @@ public class Hub { @Override public void onVerify(final boolean verified) { if (verified) { - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Verified {0} subscribed to {1}", - new Object[] { subscriber.getCallback(), subscriber.getTopic() }); + LOG.debug("Verified {} subscribed to {}", subscriber.getCallback(), subscriber.getTopic()); dao.addSubscriber(subscriber); } } @@ -248,8 +244,7 @@ public class Hub { @Override public void onVerify(final boolean verified) { - Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Unsubscribe for {0} at {1} verified {2}", - new Object[] { subscriber.getTopic(), subscriber.getCallback(), verified }); + LOG.debug("Unsubscribe for {} at {} verified {}", subscriber.getTopic(), subscriber.getCallback(), verified); if (verified) { dao.removeSubscriber(topic, callback); } diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java index 10d1f8a..2edd51b 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java @@ -26,12 +26,12 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import org.rometools.certiorem.hub.Notifier; import org.rometools.certiorem.hub.data.Subscriber; import org.rometools.certiorem.hub.data.SubscriptionSummary; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.FeedException; @@ -42,20 +42,23 @@ import com.sun.syndication.io.SyndFeedOutput; * @author robert.cooper */ public abstract class AbstractNotifier implements Notifier { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractNotifier.class); + /** - * This method will serialize the synd feed and build Notifications for the - * implementation class to handle. + * This method will serialize the synd feed and build Notifications for the implementation class + * to handle. * * @see enqueueNotification * * @param subscribers List of subscribers to notify * @param value The SyndFeed object to send - * @param callback A callback that will be invoked each time a subscriber is - * notified. + * @param callback A callback that will be invoked each time a subscriber is notified. * */ @Override public void notifySubscribers(final List subscribers, final SyndFeed value, final SubscriptionSummaryCallback callback) { + String mimeType = null; if (value.getFeedType().startsWith("rss")) { @@ -71,10 +74,10 @@ public abstract class AbstractNotifier implements Notifier { output.output(value, new OutputStreamWriter(baos)); baos.close(); } catch (final IOException ex) { - Logger.getLogger(AbstractNotifier.class.getName()).log(Level.SEVERE, null, ex); + LOG.error("Unable to output the feed", ex); throw new RuntimeException("Unable to output the feed.", ex); } catch (final FeedException ex) { - Logger.getLogger(AbstractNotifier.class.getName()).log(Level.SEVERE, null, ex); + LOG.error("Unable to output the feed", ex); throw new RuntimeException("Unable to output the feed.", ex); } @@ -100,9 +103,8 @@ public abstract class AbstractNotifier implements Notifier { protected abstract void enqueueNotification(Notification not); /** - * POSTs the payload to the subscriber's callback and returns a - * SubscriptionSummary with subscriber counts (where possible) and the - * success state of the notification. + * POSTs the payload to the subscriber's callback and returns a SubscriptionSummary with + * subscriber counts (where possible) and the success state of the notification. * * @param subscriber subscriber data. * @param mimeType MIME type for the request @@ -114,7 +116,7 @@ public abstract class AbstractNotifier implements Notifier { try { final URL target = new URL(subscriber.getCallback()); - Logger.getLogger(AbstractNotifier.class.getName()).log(Level.INFO, "Posting notification to subscriber {0}", subscriber.getCallback()); + LOG.info("Posting notification to subscriber {}", subscriber.getCallback()); result.setHost(target.getHost()); final HttpURLConnection connection = (HttpURLConnection) target.openConnection(); @@ -132,9 +134,8 @@ public abstract class AbstractNotifier implements Notifier { connection.disconnect(); if (responseCode != 200) { - Logger.getLogger(AbstractNotifier.class.getName()).log(Level.WARNING, "Got code " + responseCode + " from " + target); + LOG.warn("Got code {} from {}", responseCode, target); result.setLastPublishSuccessful(false); - return result; } @@ -142,17 +143,17 @@ public abstract class AbstractNotifier implements Notifier { try { result.setSubscribers(Integer.parseInt(subscribers)); } catch (final NumberFormatException nfe) { - Logger.getLogger(AbstractNotifier.class.getName()).log(Level.WARNING, "Invalid subscriber value " + subscribers + " " + target, nfe); + LOG.warn("Invalid subscriber value " + subscribers + " " + target, nfe); result.setSubscribers(-1); } } else { result.setSubscribers(-1); } } catch (final MalformedURLException ex) { - Logger.getLogger(AbstractNotifier.class.getName()).log(Level.WARNING, null, ex); + LOG.warn(null, ex); result.setLastPublishSuccessful(false); } catch (final IOException ex) { - Logger.getLogger(AbstractNotifier.class.getName()).log(Level.SEVERE, null, ex); + LOG.error(null, ex); result.setLastPublishSuccessful(false); } diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java index 53d775c..c12b601 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java @@ -27,19 +27,22 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; import org.rometools.certiorem.hub.Verifier; import org.rometools.certiorem.hub.data.Subscriber; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * An abstract verifier based on the java.net HTTP classes. This implements only - * synchronous operations, and expects a child class to do Async ops. + * An abstract verifier based on the java.net HTTP classes. This implements only synchronous + * operations, and expects a child class to do Async ops. * * @author robert.cooper */ public abstract class AbstractVerifier implements Verifier { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractVerifier.class); + @Override public boolean verifySubcribeSyncronously(final Subscriber subscriber) { return doOp(Verifier.MODE_SUBSCRIBE, subscriber); @@ -55,7 +58,7 @@ public abstract class AbstractVerifier implements Verifier { final String challenge = UUID.randomUUID().toString(); final StringBuilder queryString = new StringBuilder(); queryString.append("hub.mode=").append(mode).append("&hub.topic=").append(URLEncoder.encode(subscriber.getTopic(), "UTF-8")) - .append("&hub.challenge=").append(challenge); + .append("&hub.challenge=").append(challenge); if (subscriber.getLeaseSeconds() != -1) { queryString.append("&hub.lease_seconds=").append(subscriber.getLeaseSeconds()); @@ -85,11 +88,10 @@ public abstract class AbstractVerifier implements Verifier { return true; } } catch (final UnsupportedEncodingException ex) { - Logger.getLogger(AbstractVerifier.class.getName()).log(Level.SEVERE, null, ex); + LOG.error("Unsupported encoding", ex); throw new RuntimeException("Should not happen. UTF-8 threw unsupported encoding", ex); } catch (final IOException ex) { - Logger.getLogger(AbstractVerifier.class.getName()).log(Level.SEVERE, null, ex); - + LOG.error("An IOException occured", ex); return false; } } diff --git a/src/main/java/org/rometools/certiorem/pub/Publisher.java b/src/main/java/org/rometools/certiorem/pub/Publisher.java index 0f6d4f2..922766e 100644 --- a/src/main/java/org/rometools/certiorem/pub/Publisher.java +++ b/src/main/java/org/rometools/certiorem/pub/Publisher.java @@ -25,8 +25,9 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.concurrent.ThreadPoolExecutor; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndLink; @@ -37,18 +38,19 @@ import com.sun.syndication.feed.synd.SyndLink; * @author robert.cooper */ public class Publisher { + + private static final Logger LOG = LoggerFactory.getLogger(Publisher.class); + private ThreadPoolExecutor executor; /** - * Constructs a new publisher. This publisher will spawn a new thread for - * each async send. + * Constructs a new publisher. This publisher will spawn a new thread for each async send. */ public Publisher() { } /** - * Constructs a new publisher with an optional ThreadPoolExector for sending - * updates. + * Constructs a new publisher with an optional ThreadPoolExector for sending updates. */ public Publisher(final ThreadPoolExecutor executor) { this.executor = executor; @@ -84,17 +86,16 @@ public class Publisher { } } catch (final UnsupportedEncodingException ex) { - Logger.getLogger(Publisher.class.getName()).log(Level.SEVERE, null, ex); + LOG.error("Could not encode URL", ex); throw new NotificationException("Could not encode URL", ex); } catch (final IOException ex) { - Logger.getLogger(Publisher.class.getName()).log(Level.SEVERE, null, ex); + LOG.error("Communication error", ex); throw new NotificationException("Unable to communicate with " + hub, ex); } } /** - * Sends a notification for a feed located at "topic". The feed MUST contain - * rel="hub". + * Sends a notification for a feed located at "topic". The feed MUST contain rel="hub". * * @param topic URL for the feed * @param feed The feed itself @@ -112,8 +113,7 @@ public class Publisher { } /** - * Sends a notification for a feed. The feed MUST contain rel="hub" and - * rel="self" links. + * Sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links. * * @param feed The feed to notify * @throws NotificationException Any failure @@ -176,8 +176,8 @@ public class Publisher { } /** - * Asynchronously sends a notification for a feed located at "topic". The - * feed MUST contain rel="hub". + * Asynchronously sends a notification for a feed located at "topic". The feed MUST contain + * rel="hub". * * @param topic URL for the feed * @param feed The feed itself @@ -205,8 +205,8 @@ public class Publisher { } /** - * Asyncronously sends a notification for a feed. The feed MUST contain - * rel="hub" and rel="self" links. + * Asyncronously sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" + * links. * * @param feed The feed to notify * @param callback A callback invoked when the notification completes. diff --git a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java index 50646ac..5156b03 100644 --- a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java +++ b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java @@ -28,8 +28,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.sub.Requester.RequestCallback; @@ -38,6 +36,8 @@ import org.rometools.certiorem.sub.data.Subscription; import org.rometools.certiorem.sub.data.SubscriptionCallback; import org.rometools.fetcher.impl.FeedFetcherCache; import org.rometools.fetcher.impl.SyndFeedInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndLink; @@ -50,7 +50,7 @@ import com.sun.syndication.io.SyndFeedInput; */ public class Subscriptions { - private static final Logger LOGGER = Logger.getLogger(Subscriptions.class.getName()); + private static final Logger LOG = LoggerFactory.getLogger(Subscriptions.class); // TODO unsubscribe. private FeedFetcherCache cache; @@ -72,7 +72,7 @@ public class Subscriptions { try { this.callback(callbackPath, feed.getBytes("UTF-8")); } catch (final UnsupportedEncodingException ex) { - LOGGER.log(Level.SEVERE, null, ex); + LOG.error("Unable to parse feed", ex); throw new HttpStatusCodeException(400, "Unable to parse feed.", ex); } } @@ -83,10 +83,10 @@ public class Subscriptions { try { this.callback(callbackPath, input.build(new InputStreamReader(feed))); } catch (final IllegalArgumentException ex) { - LOGGER.log(Level.SEVERE, null, ex); + LOG.error("Unable to parse feed", ex); throw new HttpStatusCodeException(500, "Unable to parse feed.", ex); } catch (final FeedException ex) { - LOGGER.log(Level.SEVERE, null, ex); + LOG.error("Unable to parse feed", ex); throw new HttpStatusCodeException(400, "Unable to parse feed.", ex); } } @@ -102,7 +102,7 @@ public class Subscriptions { } final String id = callbackPath.substring(callbackPrefix.length()); - LOGGER.log(Level.FINE, "Got callback for {0}", id); + LOG.debug("Got callback for {}", id); final Subscription s = dao.findById(id); if (s == null) { @@ -118,7 +118,7 @@ public class Subscriptions { url = new URL(s.getSourceUrl()); info = cache.getFeedInfo(url); } catch (final MalformedURLException ex) { - LOGGER.log(Level.SEVERE, null, ex); + LOG.error("Malformed URL", ex); } if (info == null) { @@ -196,7 +196,7 @@ public class Subscriptions { } final String id = callbackPath.substring(callbackPrefix.length()); - LOGGER.log(Level.FINE, "Handling validation request for id {0}", id); + LOG.debug("Handling validation request for id {}", id); final Subscription s = dao.findById(id); if (s == null) { throw new HttpStatusCodeException(404, "Not a valid subscription id", null); @@ -221,7 +221,7 @@ public class Subscriptions { } else { throw new HttpStatusCodeException(400, "Unsupported mode " + mode, null); } - LOGGER.log(Level.FINE, "Validated. Returning {0}", challenge); + LOG.debug("Validated. Returning {}", challenge); return challenge; } @@ -248,7 +248,7 @@ public class Subscriptions { break; } catch (final URISyntaxException ex) { - LOGGER.log(Level.SEVERE, null, ex); + LOG.error(null, ex); } } } diff --git a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java b/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java index 0d32815..56bbd62 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java +++ b/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java @@ -25,11 +25,11 @@ package org.rometools.certiorem.sub.data.ram; import java.util.Date; import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; import org.rometools.certiorem.sub.data.SubDAO; import org.rometools.certiorem.sub.data.Subscription; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @@ -37,6 +37,8 @@ import org.rometools.certiorem.sub.data.Subscription; */ public class InMemorySubDAO implements SubDAO { + private static final Logger LOG = LoggerFactory.getLogger(InMemorySubDAO.class); + private final ConcurrentHashMap subscriptions = new ConcurrentHashMap(); @Override @@ -46,8 +48,7 @@ public class InMemorySubDAO implements SubDAO { return null; } if (s.getExpirationTime() > 0 && s.getExpirationTime() <= System.currentTimeMillis()) { - Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Subscription {0} expired at {1}", - new Object[] { s.getSourceUrl(), new Date(s.getExpirationTime()) }); + LOG.debug("Subscription {} expired at {}", s.getSourceUrl(), new Date(s.getExpirationTime())); subscriptions.remove(id); return null; @@ -58,7 +59,7 @@ public class InMemorySubDAO implements SubDAO { @Override public Subscription addSubscription(final Subscription s) { subscriptions.put(s.getId(), s); - Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Stored subscription {0} {1}", new Object[] { s.getSourceUrl(), s.getId() }); + LOG.debug("Stored subscription {} {}", s.getSourceUrl(), s.getId()); return s; } diff --git a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java b/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java index 64b5efc..62a2a82 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java +++ b/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java @@ -19,10 +19,10 @@ package org.rometools.certiorem.sub.request; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; import org.rometools.certiorem.sub.data.Subscription; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A simple requester implementation that always makes requests as Async. @@ -30,18 +30,20 @@ import org.rometools.certiorem.sub.data.Subscription; * @author robert.cooper */ public class AsyncRequester extends AbstractRequester { + + private static final Logger LOG = LoggerFactory.getLogger(AsyncRequester.class); + @Override public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds, final String secret, final String callbackUrl, final RequestCallback callback) { - Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending subscribe request to {0} for {1} to {2}", - new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl }); + LOG.debug("Sending subscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl); final Runnable r = new Runnable() { @Override public void run() { try { sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback); } catch (final Exception ex) { - Logger.getLogger(AsyncRequester.class.getName()).log(Level.SEVERE, null, ex); + LOG.error(null, ex); callback.onFailure(ex); } } @@ -52,15 +54,14 @@ public class AsyncRequester extends AbstractRequester { @Override public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret, final String callbackUrl, final RequestCallback callback) { - Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending unsubscribe request to {0} for {1} to {2}", - new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl }); + LOG.debug("Sending unsubscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl); final Runnable r = new Runnable() { @Override public void run() { try { sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback); } catch (final IOException ex) { - Logger.getLogger(AsyncRequester.class.getName()).log(Level.SEVERE, null, ex); + LOG.error(null, ex); callback.onFailure(ex); } } diff --git a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java b/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java index 553d2b1..7896991 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java +++ b/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java @@ -23,10 +23,10 @@ package org.rometools.certiorem.sub.request; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; import org.rometools.certiorem.sub.data.Subscription; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A simple requester implementation that always makes requests as Async. @@ -34,16 +34,18 @@ import org.rometools.certiorem.sub.data.Subscription; * @author Farrukh Najmi */ public class SyncRequester extends AbstractRequester { + + private static final Logger LOG = LoggerFactory.getLogger(SyncRequester.class); + @Override public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds, final String secret, final String callbackUrl, final RequestCallback callback) { - Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending subscribe request to {0} for {1} to {2}", - new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl }); + LOG.info("Sending subscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl); try { sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback); callback.onSuccess(); } catch (final Exception ex) { - Logger.getLogger(SyncRequester.class.getName()).log(Level.SEVERE, null, ex); + LOG.error(null, ex); callback.onFailure(ex); } } @@ -51,13 +53,12 @@ public class SyncRequester extends AbstractRequester { @Override public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret, final String callbackUrl, final RequestCallback callback) { - Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending unsubscribe request to {0} for {1} to {2}", - new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl }); + LOG.info("Sending unsubscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl); try { sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback); callback.onSuccess(); } catch (final IOException ex) { - Logger.getLogger(SyncRequester.class.getName()).log(Level.SEVERE, null, ex); + LOG.error(null, ex); callback.onFailure(ex); } } diff --git a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java index 5729fe2..ed1327a 100644 --- a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java +++ b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java @@ -21,8 +21,6 @@ package org.rometools.certiorem.hub; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import java.util.logging.Logger; - import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -34,12 +32,17 @@ import org.rometools.certiorem.hub.data.ram.InMemoryHubDAO; import org.rometools.fetcher.FeedFetcher; import org.rometools.fetcher.impl.HashMapFeedInfoCache; import org.rometools.fetcher.impl.HttpURLFeedFetcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * * @author robert.cooper */ public class ControllerTest { + + private static final Logger LOG = LoggerFactory.getLogger(ControllerTest.class); + public ControllerTest() { } @@ -64,7 +67,8 @@ public class ControllerTest { */ @Test public void testSubscribe() { - Logger.getLogger(ControllerTest.class.getName()).info("subscribe"); + + LOG.info("subscribe"); final String callback = "http://localhost/doNothing"; final String topic = "http://feeds.feedburner.com/screaming-penguin"; @@ -92,7 +96,7 @@ public class ControllerTest { fail(); } catch (final HttpStatusCodeException e) { assertEquals(400, e.getStatus()); - Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); + LOG.info(e.getMessage()); } try { @@ -100,7 +104,7 @@ public class ControllerTest { fail(); } catch (final HttpStatusCodeException e) { assertEquals(400, e.getStatus()); - Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); + LOG.info(e.getMessage()); } try { @@ -108,7 +112,7 @@ public class ControllerTest { fail(); } catch (final HttpStatusCodeException e) { assertEquals(400, e.getStatus()); - Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); + LOG.info(e.getMessage()); } // test general exception diff --git a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java index 77836b3..4867195 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java +++ b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java @@ -19,10 +19,10 @@ package org.rometools.certiorem.hub.data; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @@ -30,14 +30,14 @@ import org.junit.Test; */ public abstract class AbstractDAOTest { - private static final Logger LOGGER = Logger.getLogger(AbstractDAOTest.class.getName()); + private static final Logger LOG = LoggerFactory.getLogger(AbstractDAOTest.class); protected abstract HubDAO get(); @Test public void testSubscribe() { final HubDAO instance = get(); - LOGGER.log(Level.INFO, "{0} testSubscribe", instance.getClass().getName()); + LOG.info("{} testSubscribe", instance.getClass().getName()); final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); @@ -56,7 +56,7 @@ public abstract class AbstractDAOTest { @Test public void testLeaseExpire() throws InterruptedException { final HubDAO instance = get(); - LOGGER.log(Level.INFO, "{0} testLeaseExpire", instance.getClass().getName()); + LOG.info("{} testLeaseExpire", instance.getClass().getName()); final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); @@ -78,7 +78,7 @@ public abstract class AbstractDAOTest { @Test public void testUnsubscribe() throws InterruptedException { final HubDAO instance = get(); - LOGGER.log(Level.INFO, "{0} testUnsubscribe", instance.getClass().getName()); + LOG.info("{} testUnsubscribe", instance.getClass().getName()); final Subscriber subscriber = new Subscriber(); subscriber.setCallback("http://localhost:9797/noop"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 0000000..44dea42 --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n + + + + + + + + \ No newline at end of file From fdd5783d8e339ec14076f3e52b1139a62afa763c Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 14 Apr 2014 20:14:31 +0200 Subject: [PATCH 12/23] Added FIXME comments to wrong used assert statements --- src/main/java/org/rometools/certiorem/hub/Hub.java | 2 ++ .../org/rometools/certiorem/hub/data/jpa/JPADAO.java | 1 + .../certiorem/hub/data/ram/InMemoryHubDAO.java | 1 + .../certiorem/hub/data/AbstractDAOTest.java | 12 +++++++----- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/rometools/certiorem/hub/Hub.java b/src/main/java/org/rometools/certiorem/hub/Hub.java index dbe6397..c6996b5 100644 --- a/src/main/java/org/rometools/certiorem/hub/Hub.java +++ b/src/main/java/org/rometools/certiorem/hub/Hub.java @@ -123,6 +123,7 @@ public class Hub { * request. */ public void sendNotification(final String requestHost, final String topic) { + // FIXME assert should not be used for validation because it can be disabled assert validTopics.isEmpty() || validTopics.contains(topic) : "That topic is not supported by this hub. " + topic; LOG.debug("Sending notification for {}", topic); try { @@ -179,6 +180,7 @@ public class Hub { LOG.debug("{} wants to subscribe to {}", callback, topic); try { try { + // FIXME assert should not be used for validation because it can be disabled assert callback != null : "Callback URL is required."; assert topic != null : "Topic URL is required."; diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java index 01d1f4b..ceb2f67 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java +++ b/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java @@ -95,6 +95,7 @@ public class JPADAO implements HubDAO { @Override public Subscriber addSubscriber(final Subscriber subscriber) { + // FIXME assert should not be used for validation because it can be disabled assert subscriber != null : "Attempt to store a null subscriber"; final EntityManager em = factory.createEntityManager(); final EntityTransaction tx = em.getTransaction(); diff --git a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java b/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java index 72a8075..cdcce85 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java +++ b/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java @@ -39,6 +39,7 @@ public class InMemoryHubDAO implements HubDAO { @Override public Subscriber addSubscriber(final Subscriber subscriber) { + // FIXME assert should not be used for validation because it can be disabled assert subscriber != null : "Attempt to store a null subscriber"; List subList = subscribers.get(subscriber.getTopic()); diff --git a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java index 4867195..191f5cb 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java +++ b/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java @@ -20,6 +20,7 @@ package org.rometools.certiorem.hub.data; import java.util.List; +import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,11 +47,12 @@ public abstract class AbstractDAOTest { final Subscriber result = instance.addSubscriber(subscriber); - assert result.equals(subscriber) : "Subscriber not equal."; + Assert.assertTrue("Subscriber not equal", result.equals(subscriber)); final List subscribers = instance.subscribersForTopic(subscriber.getTopic()); - assert subscribers.contains(result) : "Subscriber not in result."; + Assert.assertTrue("Subscriber not in result", subscribers.contains(result)); + } @Test @@ -65,14 +67,14 @@ public abstract class AbstractDAOTest { final Subscriber result = instance.addSubscriber(subscriber); - assert subscriber.equals(result) : "Subscriber not equal."; + Assert.assertEquals("Subscriber not equal", subscriber, result); // quick test for store. List subscribers = instance.subscribersForTopic(subscriber.getTopic()); - assert subscribers.contains(result) : "Subscriber not in result."; + Assert.assertTrue("Subscriber not in result", subscribers.contains(result)); // sleep past expiration Thread.sleep(1100); subscribers = instance.subscribersForTopic(subscriber.getTopic()); - assert !subscribers.contains(result) : "Subscriber should have expired"; + Assert.assertFalse("Subscriber should have expired", subscribers.contains(result)); } @Test From 3d284937908e2d2ee28890eda0d92dff7d083c16 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 28 Apr 2014 17:49:26 +0200 Subject: [PATCH 13/23] Added snapshot repository --- pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pom.xml b/pom.xml index 7bebdae..0dafbbd 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,19 @@ + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + From afdba4ee51a59dd66a9b94fdb2889d904848520b Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 28 Apr 2014 17:49:44 +0200 Subject: [PATCH 14/23] Fixed imports --- .../org/rometools/certiorem/hub/DeltaFeedInfoCache.java | 4 ++-- .../org/rometools/certiorem/hub/DeltaSyndFeedInfo.java | 3 +-- src/main/java/org/rometools/certiorem/hub/Hub.java | 2 +- .../java/org/rometools/certiorem/sub/Subscriptions.java | 4 ++-- .../rometools/certiorem/sub/data/SubscriptionCallback.java | 2 +- .../java/org/rometools/certiorem/hub/ControllerTest.java | 7 ++++--- .../org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java index 7b9a727..c58496c 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java +++ b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java @@ -6,8 +6,8 @@ package org.rometools.certiorem.hub; import java.net.URL; -import org.rometools.fetcher.impl.FeedFetcherCache; -import org.rometools.fetcher.impl.SyndFeedInfo; +import com.rometools.fetcher.impl.FeedFetcherCache; +import com.rometools.fetcher.impl.SyndFeedInfo; /** * Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java index 9a1836d..f84234e 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java +++ b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java @@ -12,8 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.rometools.fetcher.impl.SyndFeedInfo; - +import com.rometools.fetcher.impl.SyndFeedInfo; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; diff --git a/src/main/java/org/rometools/certiorem/hub/Hub.java b/src/main/java/org/rometools/certiorem/hub/Hub.java index c6996b5..b949a5a 100644 --- a/src/main/java/org/rometools/certiorem/hub/Hub.java +++ b/src/main/java/org/rometools/certiorem/hub/Hub.java @@ -32,10 +32,10 @@ import org.rometools.certiorem.hub.Verifier.VerificationCallback; import org.rometools.certiorem.hub.data.HubDAO; import org.rometools.certiorem.hub.data.Subscriber; import org.rometools.certiorem.hub.data.SubscriptionSummary; -import org.rometools.fetcher.FeedFetcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.fetcher.FeedFetcher; import com.sun.syndication.feed.synd.SyndFeed; /** diff --git a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java index 5156b03..051addb 100644 --- a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java +++ b/src/main/java/org/rometools/certiorem/sub/Subscriptions.java @@ -34,11 +34,11 @@ import org.rometools.certiorem.sub.Requester.RequestCallback; import org.rometools.certiorem.sub.data.SubDAO; import org.rometools.certiorem.sub.data.Subscription; import org.rometools.certiorem.sub.data.SubscriptionCallback; -import org.rometools.fetcher.impl.FeedFetcherCache; -import org.rometools.fetcher.impl.SyndFeedInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.fetcher.impl.FeedFetcherCache; +import com.rometools.fetcher.impl.SyndFeedInfo; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndLink; import com.sun.syndication.io.FeedException; diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java b/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java index 6a82aff..044edac 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java +++ b/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java @@ -5,7 +5,7 @@ package org.rometools.certiorem.sub.data; -import org.rometools.fetcher.impl.SyndFeedInfo; +import com.rometools.fetcher.impl.SyndFeedInfo; /** * diff --git a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java index ed1327a..d7dcb6d 100644 --- a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java +++ b/src/test/java/org/rometools/certiorem/hub/ControllerTest.java @@ -29,12 +29,13 @@ import org.junit.Test; import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.hub.data.HubDAO; import org.rometools.certiorem.hub.data.ram.InMemoryHubDAO; -import org.rometools.fetcher.FeedFetcher; -import org.rometools.fetcher.impl.HashMapFeedInfoCache; -import org.rometools.fetcher.impl.HttpURLFeedFetcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.fetcher.FeedFetcher; +import com.rometools.fetcher.impl.HashMapFeedInfoCache; +import com.rometools.fetcher.impl.HttpURLFeedFetcher; + /** * * @author robert.cooper diff --git a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java index da9c401..54c2306 100644 --- a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java +++ b/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java @@ -12,9 +12,9 @@ import java.util.List; import org.junit.Before; import org.junit.Test; -import org.rometools.fetcher.impl.HashMapFeedInfoCache; -import org.rometools.fetcher.impl.HttpURLFeedFetcher; +import com.rometools.fetcher.impl.HashMapFeedInfoCache; +import com.rometools.fetcher.impl.HttpURLFeedFetcher; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; From 14561d43cc725f98f33c786023a5d22f134ef3ec Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 13 May 2014 19:28:16 +0200 Subject: [PATCH 15/23] Formatted and cleaned up sources --- .../certiorem/HttpStatusCodeException.java | 2 +- .../certiorem/hub/DeltaFeedInfoCache.java | 6 +++--- .../rometools/certiorem/hub/DeltaSyndFeedInfo.java | 14 +++++++------- .../java/org/rometools/certiorem/hub/Notifier.java | 6 ++---- .../java/org/rometools/certiorem/hub/Verifier.java | 3 +-- .../hub/notify/standard/ThreadPoolNotifier.java | 9 ++++----- .../hub/notify/standard/UnthreadedNotifier.java | 5 ++--- .../hub/verify/standard/AbstractVerifier.java | 2 +- 8 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java b/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java index da7cf16..a6a7bd4 100644 --- a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java +++ b/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java @@ -25,7 +25,7 @@ package org.rometools.certiorem; public class HttpStatusCodeException extends RuntimeException { private static final long serialVersionUID = 1L; - + private final int status; public HttpStatusCodeException(final int status, final String message, final Throwable cause) { diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java index c58496c..bfe34ea 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java +++ b/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java @@ -10,9 +10,9 @@ import com.rometools.fetcher.impl.FeedFetcherCache; import com.rometools.fetcher.impl.SyndFeedInfo; /** - * Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure - * that any SyndFeedInfo used within it are replaced with a DeltaSyndFeedInfo - * which is capable of tracking changes to entries in the underlying feed. + * Wrapper FeedFetcherCache that wraps a backing FeedFetcherCache and makes sure that any + * SyndFeedInfo used within it are replaced with a DeltaSyndFeedInfo which is capable of tracking + * changes to entries in the underlying feed. * * @author najmi */ diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java index f84234e..d077dc2 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java +++ b/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java @@ -17,9 +17,9 @@ import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; /** - * Extends SyndFeedInfo to also track etags for individual entries. This may be - * used with DeltaFeedInfoCache to only return feed with a subset of entries - * that have changed since last fetch. + * Extends SyndFeedInfo to also track etags for individual entries. This may be used with + * DeltaFeedInfoCache to only return feed with a subset of entries that have changed since last + * fetch. * * @author najmi */ @@ -40,8 +40,8 @@ public class DeltaSyndFeedInfo extends SyndFeedInfo { } /** - * Gets a filtered version of the SyndFeed that only has entries that were - * changed in the last setSyndFeed() call. + * Gets a filtered version of the SyndFeed that only has entries that were changed in the last + * setSyndFeed() call. * * @return */ @@ -68,8 +68,8 @@ public class DeltaSyndFeedInfo extends SyndFeedInfo { } /** - * Overrides super class method to update changedMap and entryTagsMap for - * tracking changed entries. + * Overrides super class method to update changedMap and entryTagsMap for tracking changed + * entries. * * @param feed */ diff --git a/src/main/java/org/rometools/certiorem/hub/Notifier.java b/src/main/java/org/rometools/certiorem/hub/Notifier.java index 576b778..89373fa 100644 --- a/src/main/java/org/rometools/certiorem/hub/Notifier.java +++ b/src/main/java/org/rometools/certiorem/hub/Notifier.java @@ -31,13 +31,11 @@ import com.sun.syndication.feed.synd.SyndFeed; */ public interface Notifier { /** - * Instructs the notifier to begin sending notifications to the list of - * subscribers + * Instructs the notifier to begin sending notifications to the list of subscribers * * @param subscribers Subscribers to notify * @param value The SyndFeed to send them - * @param callback A callback that is invoked each time a subscriber is - * notified. + * @param callback A callback that is invoked each time a subscriber is notified. */ public void notifySubscribers(List subscribers, SyndFeed value, SubscriptionSummaryCallback callback); diff --git a/src/main/java/org/rometools/certiorem/hub/Verifier.java b/src/main/java/org/rometools/certiorem/hub/Verifier.java index 4a6c58f..5b6457e 100644 --- a/src/main/java/org/rometools/certiorem/hub/Verifier.java +++ b/src/main/java/org/rometools/certiorem/hub/Verifier.java @@ -69,8 +69,7 @@ public interface Verifier { public boolean verifyUnsubcribeSyncronously(Subscriber subscriber); /** - * An interface for capturing the result of a verification (subscribe or - * unsubscribe) + * An interface for capturing the result of a verification (subscribe or unsubscribe) */ public static interface VerificationCallback { /** diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java index 42db9e9..0aa8f06 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java @@ -28,8 +28,7 @@ import java.util.concurrent.TimeUnit; import org.rometools.certiorem.hub.data.SubscriptionSummary; /** - * A notifier implementation that uses a thread pool to deliver notifications to - * subscribers + * A notifier implementation that uses a thread pool to deliver notifications to subscribers * * @author robert.cooper */ @@ -52,9 +51,9 @@ public class ThreadPoolNotifier extends AbstractNotifier { } /** - * Enqueues a notification to run. If the notification fails, it will be - * retried every two minutes until 5 attempts are completed. Notifications - * to the same callback should be delivered successfully in order. + * Enqueues a notification to run. If the notification fails, it will be retried every two + * minutes until 5 attempts are completed. Notifications to the same callback should be + * delivered successfully in order. * * @param not */ diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java b/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java index f591b43..d04fec8 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java +++ b/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java @@ -28,9 +28,8 @@ import org.rometools.certiorem.hub.data.SubscriptionSummary; public class UnthreadedNotifier extends AbstractNotifier { /** - * A blocking call that performs a notification. If there are pending - * retries that are older than two minutes old, they will be retried before - * the method returns. + * A blocking call that performs a notification. If there are pending retries that are older + * than two minutes old, they will be retried before the method returns. * * @param not */ diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java index c12b601..4f0eac9 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java +++ b/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java @@ -58,7 +58,7 @@ public abstract class AbstractVerifier implements Verifier { final String challenge = UUID.randomUUID().toString(); final StringBuilder queryString = new StringBuilder(); queryString.append("hub.mode=").append(mode).append("&hub.topic=").append(URLEncoder.encode(subscriber.getTopic(), "UTF-8")) - .append("&hub.challenge=").append(challenge); + .append("&hub.challenge=").append(challenge); if (subscriber.getLeaseSeconds() != -1) { queryString.append("&hub.lease_seconds=").append(subscriber.getLeaseSeconds()); From 0588cfd66d0b2747c9cc79017be846e0e6cc79d9 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 30 May 2014 16:31:08 +0200 Subject: [PATCH 16/23] Renamed and harmonized packages --- .../certiorem/HttpStatusCodeException.java | 2 +- .../certiorem/hub/DeltaFeedInfoCache.java | 2 +- .../certiorem/hub/DeltaSyndFeedInfo.java | 6 +++--- .../rometools/certiorem/hub/Hub.java | 16 +++++++-------- .../rometools/certiorem/hub/Notifier.java | 9 ++++----- .../rometools/certiorem/hub/Verifier.java | 4 ++-- .../rometools/certiorem/hub/data/HubDAO.java | 2 +- .../certiorem/hub/data/Subscriber.java | 2 +- .../hub/data/SubscriptionSummary.java | 2 +- .../certiorem/hub/data/jpa/JPADAO.java | 8 ++++---- .../certiorem/hub/data/jpa/JPASubscriber.java | 4 ++-- .../certiorem/hub/data/jpa/package.html | 0 .../rometools/certiorem/hub/data/package.html | 0 .../hub/data/ram/InMemoryHubDAO.java | 8 ++++---- .../certiorem/hub/data/ram/package.html | 0 .../hub/notify/standard/AbstractNotifier.java | 14 ++++++------- .../hub/notify/standard/Notification.java | 6 +++--- .../notify/standard/ThreadPoolNotifier.java | 4 ++-- .../notify/standard/UnthreadedNotifier.java | 4 ++-- .../hub/notify/standard/package.html | 0 .../rometools/certiorem/hub/package.html | 0 .../hub/verify/standard/AbstractVerifier.java | 7 ++++--- .../verify/standard/ThreadPoolVerifier.java | 4 ++-- .../standard/ThreadpoolVerifierAdvanced.java | 2 +- .../verify/standard/UnthreadedVerifier.java | 4 ++-- .../hub/verify/standard/package.html | 0 .../rometools/certiorem/package.html | 0 .../certiorem/pub/NotificationException.java | 2 +- .../rometools/certiorem/pub/Publisher.java | 6 +++--- .../rometools/certiorem/pub/package.html | 0 .../rometools/certiorem/sub/Requester.java | 4 ++-- .../certiorem/sub/Subscriptions.java | 20 +++++++++---------- .../rometools/certiorem/sub/data/SubDAO.java | 2 +- .../certiorem/sub/data/Subscription.java | 2 +- .../sub/data/SubscriptionCallback.java | 2 +- .../rometools/certiorem/sub/data/package.html | 0 .../sub/data/ram/InMemorySubDAO.java | 7 ++++--- .../certiorem/sub/data/ram/package.html | 0 .../rometools/certiorem/sub/package.html | 0 .../sub/request/AbstractRequester.java | 6 +++--- .../certiorem/sub/request/AsyncRequester.java | 5 +++-- .../certiorem/sub/request/SyncRequester.java | 5 +++-- .../certiorem/sub/request/package.html | 0 .../certiorem/web/AbstractHubServlet.java | 6 +++--- .../certiorem/web/AbstractSubServlet.java | 6 +++--- .../rometools/certiorem/web/package.html | 0 .../certiorem/hub/AlwaysVerifier.java | 5 +++-- .../certiorem/hub/ControllerTest.java | 10 ++++++---- .../certiorem/hub/DeltaSyndFeedInfoTest.java | 7 ++++--- .../certiorem/hub/ExceptionVerifier.java | 5 +++-- .../certiorem/hub/NeverVerifier.java | 5 +++-- .../certiorem/hub/data/AbstractDAOTest.java | 5 ++++- .../hub/data/ram/InMemoryDAOTest.java | 7 ++++--- 53 files changed, 120 insertions(+), 107 deletions(-) rename src/main/java/{org => com}/rometools/certiorem/HttpStatusCodeException.java (96%) rename src/main/java/{org => com}/rometools/certiorem/hub/DeltaFeedInfoCache.java (97%) rename src/main/java/{org => com}/rometools/certiorem/hub/DeltaSyndFeedInfo.java (97%) rename src/main/java/{org => com}/rometools/certiorem/hub/Hub.java (96%) rename src/main/java/{org => com}/rometools/certiorem/hub/Notifier.java (88%) rename src/main/java/{org => com}/rometools/certiorem/hub/Verifier.java (96%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/HubDAO.java (96%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/Subscriber.java (99%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/SubscriptionSummary.java (98%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/jpa/JPADAO.java (95%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/jpa/JPASubscriber.java (96%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/jpa/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java (95%) rename src/main/java/{org => com}/rometools/certiorem/hub/data/ram/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/hub/notify/standard/AbstractNotifier.java (93%) rename src/main/java/{org => com}/rometools/certiorem/hub/notify/standard/Notification.java (83%) rename src/main/java/{org => com}/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java (97%) rename src/main/java/{org => com}/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java (91%) rename src/main/java/{org => com}/rometools/certiorem/hub/notify/standard/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/hub/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/hub/verify/standard/AbstractVerifier.java (96%) rename src/main/java/{org => com}/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java (95%) rename src/main/java/{org => com}/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java (94%) rename src/main/java/{org => com}/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java (91%) rename src/main/java/{org => com}/rometools/certiorem/hub/verify/standard/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/pub/NotificationException.java (96%) rename src/main/java/{org => com}/rometools/certiorem/pub/Publisher.java (98%) rename src/main/java/{org => com}/rometools/certiorem/pub/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/sub/Requester.java (92%) rename src/main/java/{org => com}/rometools/certiorem/sub/Subscriptions.java (94%) rename src/main/java/{org => com}/rometools/certiorem/sub/data/SubDAO.java (95%) rename src/main/java/{org => com}/rometools/certiorem/sub/data/Subscription.java (98%) rename src/main/java/{org => com}/rometools/certiorem/sub/data/SubscriptionCallback.java (90%) rename src/main/java/{org => com}/rometools/certiorem/sub/data/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/sub/data/ram/InMemorySubDAO.java (93%) rename src/main/java/{org => com}/rometools/certiorem/sub/data/ram/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/sub/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/sub/request/AbstractRequester.java (94%) rename src/main/java/{org => com}/rometools/certiorem/sub/request/AsyncRequester.java (96%) rename src/main/java/{org => com}/rometools/certiorem/sub/request/SyncRequester.java (95%) rename src/main/java/{org => com}/rometools/certiorem/sub/request/package.html (100%) rename src/main/java/{org => com}/rometools/certiorem/web/AbstractHubServlet.java (95%) rename src/main/java/{org => com}/rometools/certiorem/web/AbstractSubServlet.java (94%) rename src/main/java/{org => com}/rometools/certiorem/web/package.html (100%) rename src/test/java/{org => com}/rometools/certiorem/hub/AlwaysVerifier.java (90%) rename src/test/java/{org => com}/rometools/certiorem/hub/ControllerTest.java (93%) rename src/test/java/{org => com}/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java (89%) rename src/test/java/{org => com}/rometools/certiorem/hub/ExceptionVerifier.java (91%) rename src/test/java/{org => com}/rometools/certiorem/hub/NeverVerifier.java (90%) rename src/test/java/{org => com}/rometools/certiorem/hub/data/AbstractDAOTest.java (95%) rename src/test/java/{org => com}/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java (80%) diff --git a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java b/src/main/java/com/rometools/certiorem/HttpStatusCodeException.java similarity index 96% rename from src/main/java/org/rometools/certiorem/HttpStatusCodeException.java rename to src/main/java/com/rometools/certiorem/HttpStatusCodeException.java index a6a7bd4..013ce71 100644 --- a/src/main/java/org/rometools/certiorem/HttpStatusCodeException.java +++ b/src/main/java/com/rometools/certiorem/HttpStatusCodeException.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem; +package com.rometools.certiorem; /** * diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java b/src/main/java/com/rometools/certiorem/hub/DeltaFeedInfoCache.java similarity index 97% rename from src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java rename to src/main/java/com/rometools/certiorem/hub/DeltaFeedInfoCache.java index bfe34ea..d197fd1 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaFeedInfoCache.java +++ b/src/main/java/com/rometools/certiorem/hub/DeltaFeedInfoCache.java @@ -2,7 +2,7 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; import java.net.URL; diff --git a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java b/src/main/java/com/rometools/certiorem/hub/DeltaSyndFeedInfo.java similarity index 97% rename from src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java rename to src/main/java/com/rometools/certiorem/hub/DeltaSyndFeedInfo.java index d077dc2..9f14f47 100644 --- a/src/main/java/org/rometools/certiorem/hub/DeltaSyndFeedInfo.java +++ b/src/main/java/com/rometools/certiorem/hub/DeltaSyndFeedInfo.java @@ -2,7 +2,7 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; import java.math.BigInteger; import java.security.MessageDigest; @@ -13,8 +13,8 @@ import java.util.List; import java.util.Map; import com.rometools.fetcher.impl.SyndFeedInfo; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndEntry; +import com.rometools.rome.feed.synd.SyndFeed; /** * Extends SyndFeedInfo to also track etags for individual entries. This may be used with diff --git a/src/main/java/org/rometools/certiorem/hub/Hub.java b/src/main/java/com/rometools/certiorem/hub/Hub.java similarity index 96% rename from src/main/java/org/rometools/certiorem/hub/Hub.java rename to src/main/java/com/rometools/certiorem/hub/Hub.java index b949a5a..81feb4f 100644 --- a/src/main/java/org/rometools/certiorem/hub/Hub.java +++ b/src/main/java/com/rometools/certiorem/hub/Hub.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; import java.net.URI; import java.net.URISyntaxException; @@ -26,17 +26,17 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.rometools.certiorem.HttpStatusCodeException; -import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; -import org.rometools.certiorem.hub.Verifier.VerificationCallback; -import org.rometools.certiorem.hub.data.HubDAO; -import org.rometools.certiorem.hub.data.Subscriber; -import org.rometools.certiorem.hub.data.SubscriptionSummary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.certiorem.HttpStatusCodeException; +import com.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; +import com.rometools.certiorem.hub.Verifier.VerificationCallback; +import com.rometools.certiorem.hub.data.HubDAO; +import com.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.SubscriptionSummary; import com.rometools.fetcher.FeedFetcher; -import com.sun.syndication.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndFeed; /** * The basic business logic controller for the Hub implementation. It is intended to be usable under diff --git a/src/main/java/org/rometools/certiorem/hub/Notifier.java b/src/main/java/com/rometools/certiorem/hub/Notifier.java similarity index 88% rename from src/main/java/org/rometools/certiorem/hub/Notifier.java rename to src/main/java/com/rometools/certiorem/hub/Notifier.java index 89373fa..b7f7ae3 100644 --- a/src/main/java/org/rometools/certiorem/hub/Notifier.java +++ b/src/main/java/com/rometools/certiorem/hub/Notifier.java @@ -16,14 +16,13 @@ * limitations under the License. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; import java.util.List; -import org.rometools.certiorem.hub.data.Subscriber; -import org.rometools.certiorem.hub.data.SubscriptionSummary; - -import com.sun.syndication.feed.synd.SyndFeed; +import com.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.SubscriptionSummary; +import com.rometools.rome.feed.synd.SyndFeed; /** * diff --git a/src/main/java/org/rometools/certiorem/hub/Verifier.java b/src/main/java/com/rometools/certiorem/hub/Verifier.java similarity index 96% rename from src/main/java/org/rometools/certiorem/hub/Verifier.java rename to src/main/java/com/rometools/certiorem/hub/Verifier.java index 5b6457e..b50a3f1 100644 --- a/src/main/java/org/rometools/certiorem/hub/Verifier.java +++ b/src/main/java/com/rometools/certiorem/hub/Verifier.java @@ -16,9 +16,9 @@ * limitations under the License. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; -import org.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.Subscriber; /** * A strategy interface for verification of subscriptions. diff --git a/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java b/src/main/java/com/rometools/certiorem/hub/data/HubDAO.java similarity index 96% rename from src/main/java/org/rometools/certiorem/hub/data/HubDAO.java rename to src/main/java/com/rometools/certiorem/hub/data/HubDAO.java index 249693b..b942746 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/HubDAO.java +++ b/src/main/java/com/rometools/certiorem/hub/data/HubDAO.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.data; +package com.rometools.certiorem.hub.data; import java.util.List; diff --git a/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java b/src/main/java/com/rometools/certiorem/hub/data/Subscriber.java similarity index 99% rename from src/main/java/org/rometools/certiorem/hub/data/Subscriber.java rename to src/main/java/com/rometools/certiorem/hub/data/Subscriber.java index c8bbe8f..01b2b42 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/Subscriber.java +++ b/src/main/java/com/rometools/certiorem/hub/data/Subscriber.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.data; +package com.rometools.certiorem.hub.data; import java.io.Serializable; diff --git a/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java b/src/main/java/com/rometools/certiorem/hub/data/SubscriptionSummary.java similarity index 98% rename from src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java rename to src/main/java/com/rometools/certiorem/hub/data/SubscriptionSummary.java index 8e7d3d0..42e63fa 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/SubscriptionSummary.java +++ b/src/main/java/com/rometools/certiorem/hub/data/SubscriptionSummary.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.data; +package com.rometools.certiorem.hub.data; import java.io.Serializable; diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java b/src/main/java/com/rometools/certiorem/hub/data/jpa/JPADAO.java similarity index 95% rename from src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java rename to src/main/java/com/rometools/certiorem/hub/data/jpa/JPADAO.java index ceb2f67..4c084a3 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPADAO.java +++ b/src/main/java/com/rometools/certiorem/hub/data/jpa/JPADAO.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.data.jpa; +package com.rometools.certiorem.hub.data.jpa; import java.util.LinkedList; import java.util.List; @@ -28,9 +28,9 @@ import javax.persistence.EntityTransaction; import javax.persistence.NoResultException; import javax.persistence.Query; -import org.rometools.certiorem.hub.data.HubDAO; -import org.rometools.certiorem.hub.data.Subscriber; -import org.rometools.certiorem.hub.data.SubscriptionSummary; +import com.rometools.certiorem.hub.data.HubDAO; +import com.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.SubscriptionSummary; /** * diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java b/src/main/java/com/rometools/certiorem/hub/data/jpa/JPASubscriber.java similarity index 96% rename from src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java rename to src/main/java/com/rometools/certiorem/hub/data/jpa/JPASubscriber.java index fe80d94..7620bf4 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/jpa/JPASubscriber.java +++ b/src/main/java/com/rometools/certiorem/hub/data/jpa/JPASubscriber.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.data.jpa; +package com.rometools.certiorem.hub.data.jpa; import java.io.Serializable; import java.util.Date; @@ -28,7 +28,7 @@ import javax.persistence.NamedQuery; import javax.persistence.Temporal; import javax.persistence.TemporalType; -import org.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.Subscriber; /** * diff --git a/src/main/java/org/rometools/certiorem/hub/data/jpa/package.html b/src/main/java/com/rometools/certiorem/hub/data/jpa/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/hub/data/jpa/package.html rename to src/main/java/com/rometools/certiorem/hub/data/jpa/package.html diff --git a/src/main/java/org/rometools/certiorem/hub/data/package.html b/src/main/java/com/rometools/certiorem/hub/data/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/hub/data/package.html rename to src/main/java/com/rometools/certiorem/hub/data/package.html diff --git a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java b/src/main/java/com/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java similarity index 95% rename from src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java rename to src/main/java/com/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java index cdcce85..b9ed4a3 100644 --- a/src/main/java/org/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java +++ b/src/main/java/com/rometools/certiorem/hub/data/ram/InMemoryHubDAO.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.data.ram; +package com.rometools.certiorem.hub.data.ram; import java.util.Collections; import java.util.LinkedList; @@ -24,9 +24,9 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import org.rometools.certiorem.hub.data.HubDAO; -import org.rometools.certiorem.hub.data.Subscriber; -import org.rometools.certiorem.hub.data.SubscriptionSummary; +import com.rometools.certiorem.hub.data.HubDAO; +import com.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.SubscriptionSummary; /** * A Simple In-Memory HubDAO for subscribers. diff --git a/src/main/java/org/rometools/certiorem/hub/data/ram/package.html b/src/main/java/com/rometools/certiorem/hub/data/ram/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/hub/data/ram/package.html rename to src/main/java/com/rometools/certiorem/hub/data/ram/package.html diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java b/src/main/java/com/rometools/certiorem/hub/notify/standard/AbstractNotifier.java similarity index 93% rename from src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java rename to src/main/java/com/rometools/certiorem/hub/notify/standard/AbstractNotifier.java index 2edd51b..4195ef1 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/AbstractNotifier.java +++ b/src/main/java/com/rometools/certiorem/hub/notify/standard/AbstractNotifier.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.notify.standard; +package com.rometools.certiorem.hub.notify.standard; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -27,15 +27,15 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.List; -import org.rometools.certiorem.hub.Notifier; -import org.rometools.certiorem.hub.data.Subscriber; -import org.rometools.certiorem.hub.data.SubscriptionSummary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.SyndFeedOutput; +import com.rometools.certiorem.hub.Notifier; +import com.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.SubscriptionSummary; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.SyndFeedOutput; /** * diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java b/src/main/java/com/rometools/certiorem/hub/notify/standard/Notification.java similarity index 83% rename from src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java rename to src/main/java/com/rometools/certiorem/hub/notify/standard/Notification.java index f0c62e6..d3ffdff 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/Notification.java +++ b/src/main/java/com/rometools/certiorem/hub/notify/standard/Notification.java @@ -16,10 +16,10 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.notify.standard; +package com.rometools.certiorem.hub.notify.standard; -import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; -import org.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; +import com.rometools.certiorem.hub.data.Subscriber; /** * diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java b/src/main/java/com/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java similarity index 97% rename from src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java rename to src/main/java/com/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java index 0aa8f06..12e30e1 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java +++ b/src/main/java/com/rometools/certiorem/hub/notify/standard/ThreadPoolNotifier.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.notify.standard; +package com.rometools.certiorem.hub.notify.standard; import java.util.Timer; import java.util.TimerTask; @@ -25,7 +25,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import org.rometools.certiorem.hub.data.SubscriptionSummary; +import com.rometools.certiorem.hub.data.SubscriptionSummary; /** * A notifier implementation that uses a thread pool to deliver notifications to subscribers diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java b/src/main/java/com/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java similarity index 91% rename from src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java rename to src/main/java/com/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java index d04fec8..b1228eb 100644 --- a/src/main/java/org/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java +++ b/src/main/java/com/rometools/certiorem/hub/notify/standard/UnthreadedNotifier.java @@ -16,9 +16,9 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.notify.standard; +package com.rometools.certiorem.hub.notify.standard; -import org.rometools.certiorem.hub.data.SubscriptionSummary; +import com.rometools.certiorem.hub.data.SubscriptionSummary; /** * A notifier that does not use threads. All calls are blocking and synchronous. diff --git a/src/main/java/org/rometools/certiorem/hub/notify/standard/package.html b/src/main/java/com/rometools/certiorem/hub/notify/standard/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/hub/notify/standard/package.html rename to src/main/java/com/rometools/certiorem/hub/notify/standard/package.html diff --git a/src/main/java/org/rometools/certiorem/hub/package.html b/src/main/java/com/rometools/certiorem/hub/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/hub/package.html rename to src/main/java/com/rometools/certiorem/hub/package.html diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java b/src/main/java/com/rometools/certiorem/hub/verify/standard/AbstractVerifier.java similarity index 96% rename from src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java rename to src/main/java/com/rometools/certiorem/hub/verify/standard/AbstractVerifier.java index 4f0eac9..7a8398c 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/AbstractVerifier.java +++ b/src/main/java/com/rometools/certiorem/hub/verify/standard/AbstractVerifier.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.verify.standard; +package com.rometools.certiorem.hub.verify.standard; import java.io.BufferedReader; import java.io.IOException; @@ -28,11 +28,12 @@ import java.net.URL; import java.net.URLEncoder; import java.util.UUID; -import org.rometools.certiorem.hub.Verifier; -import org.rometools.certiorem.hub.data.Subscriber; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.certiorem.hub.Verifier; +import com.rometools.certiorem.hub.data.Subscriber; + /** * An abstract verifier based on the java.net HTTP classes. This implements only synchronous * operations, and expects a child class to do Async ops. diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java b/src/main/java/com/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java similarity index 95% rename from src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java rename to src/main/java/com/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java index bb806ea..1c5f599 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java +++ b/src/main/java/com/rometools/certiorem/hub/verify/standard/ThreadPoolVerifier.java @@ -16,13 +16,13 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.verify.standard; +package com.rometools.certiorem.hub.verify.standard; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import org.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.Subscriber; /** * Uses a ThreadPoolExecutor to do async verifications. diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java b/src/main/java/com/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java similarity index 94% rename from src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java rename to src/main/java/com/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java index 19d9b5f..8751b27 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java +++ b/src/main/java/com/rometools/certiorem/hub/verify/standard/ThreadpoolVerifierAdvanced.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.verify.standard; +package com.rometools.certiorem.hub.verify.standard; import java.util.concurrent.ThreadPoolExecutor; diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java b/src/main/java/com/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java similarity index 91% rename from src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java rename to src/main/java/com/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java index 060965c..8f2fac9 100644 --- a/src/main/java/org/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java +++ b/src/main/java/com/rometools/certiorem/hub/verify/standard/UnthreadedVerifier.java @@ -16,9 +16,9 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.verify.standard; +package com.rometools.certiorem.hub.verify.standard; -import org.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.data.Subscriber; /** * A verifier that does not use threads. Suitable for Google App Engine. diff --git a/src/main/java/org/rometools/certiorem/hub/verify/standard/package.html b/src/main/java/com/rometools/certiorem/hub/verify/standard/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/hub/verify/standard/package.html rename to src/main/java/com/rometools/certiorem/hub/verify/standard/package.html diff --git a/src/main/java/org/rometools/certiorem/package.html b/src/main/java/com/rometools/certiorem/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/package.html rename to src/main/java/com/rometools/certiorem/package.html diff --git a/src/main/java/org/rometools/certiorem/pub/NotificationException.java b/src/main/java/com/rometools/certiorem/pub/NotificationException.java similarity index 96% rename from src/main/java/org/rometools/certiorem/pub/NotificationException.java rename to src/main/java/com/rometools/certiorem/pub/NotificationException.java index 2e46354..91c5c58 100644 --- a/src/main/java/org/rometools/certiorem/pub/NotificationException.java +++ b/src/main/java/com/rometools/certiorem/pub/NotificationException.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.pub; +package com.rometools.certiorem.pub; /** * diff --git a/src/main/java/org/rometools/certiorem/pub/Publisher.java b/src/main/java/com/rometools/certiorem/pub/Publisher.java similarity index 98% rename from src/main/java/org/rometools/certiorem/pub/Publisher.java rename to src/main/java/com/rometools/certiorem/pub/Publisher.java index 922766e..6857d55 100644 --- a/src/main/java/org/rometools/certiorem/pub/Publisher.java +++ b/src/main/java/com/rometools/certiorem/pub/Publisher.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.pub; +package com.rometools.certiorem.pub; import java.io.IOException; import java.io.OutputStream; @@ -29,8 +29,8 @@ import java.util.concurrent.ThreadPoolExecutor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndLink; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndLink; /** * A class for sending update notifications to a hub. diff --git a/src/main/java/org/rometools/certiorem/pub/package.html b/src/main/java/com/rometools/certiorem/pub/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/pub/package.html rename to src/main/java/com/rometools/certiorem/pub/package.html diff --git a/src/main/java/org/rometools/certiorem/sub/Requester.java b/src/main/java/com/rometools/certiorem/sub/Requester.java similarity index 92% rename from src/main/java/org/rometools/certiorem/sub/Requester.java rename to src/main/java/com/rometools/certiorem/sub/Requester.java index ce027c0..016f37d 100644 --- a/src/main/java/org/rometools/certiorem/sub/Requester.java +++ b/src/main/java/com/rometools/certiorem/sub/Requester.java @@ -16,9 +16,9 @@ * limitations under the License. */ -package org.rometools.certiorem.sub; +package com.rometools.certiorem.sub; -import org.rometools.certiorem.sub.data.Subscription; +import com.rometools.certiorem.sub.data.Subscription; /** * diff --git a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java b/src/main/java/com/rometools/certiorem/sub/Subscriptions.java similarity index 94% rename from src/main/java/org/rometools/certiorem/sub/Subscriptions.java rename to src/main/java/com/rometools/certiorem/sub/Subscriptions.java index 051addb..5989389 100644 --- a/src/main/java/org/rometools/certiorem/sub/Subscriptions.java +++ b/src/main/java/com/rometools/certiorem/sub/Subscriptions.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.sub; +package com.rometools.certiorem.sub; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -29,20 +29,20 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.UUID; -import org.rometools.certiorem.HttpStatusCodeException; -import org.rometools.certiorem.sub.Requester.RequestCallback; -import org.rometools.certiorem.sub.data.SubDAO; -import org.rometools.certiorem.sub.data.Subscription; -import org.rometools.certiorem.sub.data.SubscriptionCallback; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.certiorem.HttpStatusCodeException; +import com.rometools.certiorem.sub.Requester.RequestCallback; +import com.rometools.certiorem.sub.data.SubDAO; +import com.rometools.certiorem.sub.data.Subscription; +import com.rometools.certiorem.sub.data.SubscriptionCallback; import com.rometools.fetcher.impl.FeedFetcherCache; import com.rometools.fetcher.impl.SyndFeedInfo; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndLink; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.SyndFeedInput; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndLink; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.SyndFeedInput; /** * diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java b/src/main/java/com/rometools/certiorem/sub/data/SubDAO.java similarity index 95% rename from src/main/java/org/rometools/certiorem/sub/data/SubDAO.java rename to src/main/java/com/rometools/certiorem/sub/data/SubDAO.java index 00692e1..cef1930 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/SubDAO.java +++ b/src/main/java/com/rometools/certiorem/sub/data/SubDAO.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.sub.data; +package com.rometools.certiorem.sub.data; /** * diff --git a/src/main/java/org/rometools/certiorem/sub/data/Subscription.java b/src/main/java/com/rometools/certiorem/sub/data/Subscription.java similarity index 98% rename from src/main/java/org/rometools/certiorem/sub/data/Subscription.java rename to src/main/java/com/rometools/certiorem/sub/data/Subscription.java index 8978c7a..8344df0 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/Subscription.java +++ b/src/main/java/com/rometools/certiorem/sub/data/Subscription.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.sub.data; +package com.rometools.certiorem.sub.data; import java.io.Serializable; diff --git a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java b/src/main/java/com/rometools/certiorem/sub/data/SubscriptionCallback.java similarity index 90% rename from src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java rename to src/main/java/com/rometools/certiorem/sub/data/SubscriptionCallback.java index 044edac..ce9e560 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/SubscriptionCallback.java +++ b/src/main/java/com/rometools/certiorem/sub/data/SubscriptionCallback.java @@ -3,7 +3,7 @@ * and open the template in the editor. */ -package org.rometools.certiorem.sub.data; +package com.rometools.certiorem.sub.data; import com.rometools.fetcher.impl.SyndFeedInfo; diff --git a/src/main/java/org/rometools/certiorem/sub/data/package.html b/src/main/java/com/rometools/certiorem/sub/data/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/sub/data/package.html rename to src/main/java/com/rometools/certiorem/sub/data/package.html diff --git a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java b/src/main/java/com/rometools/certiorem/sub/data/ram/InMemorySubDAO.java similarity index 93% rename from src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java rename to src/main/java/com/rometools/certiorem/sub/data/ram/InMemorySubDAO.java index 56bbd62..d631d6c 100644 --- a/src/main/java/org/rometools/certiorem/sub/data/ram/InMemorySubDAO.java +++ b/src/main/java/com/rometools/certiorem/sub/data/ram/InMemorySubDAO.java @@ -21,16 +21,17 @@ * and open the template in the editor. */ -package org.rometools.certiorem.sub.data.ram; +package com.rometools.certiorem.sub.data.ram; import java.util.Date; import java.util.concurrent.ConcurrentHashMap; -import org.rometools.certiorem.sub.data.SubDAO; -import org.rometools.certiorem.sub.data.Subscription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.certiorem.sub.data.SubDAO; +import com.rometools.certiorem.sub.data.Subscription; + /** * * @author robert.cooper diff --git a/src/main/java/org/rometools/certiorem/sub/data/ram/package.html b/src/main/java/com/rometools/certiorem/sub/data/ram/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/sub/data/ram/package.html rename to src/main/java/com/rometools/certiorem/sub/data/ram/package.html diff --git a/src/main/java/org/rometools/certiorem/sub/package.html b/src/main/java/com/rometools/certiorem/sub/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/sub/package.html rename to src/main/java/com/rometools/certiorem/sub/package.html diff --git a/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java b/src/main/java/com/rometools/certiorem/sub/request/AbstractRequester.java similarity index 94% rename from src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java rename to src/main/java/com/rometools/certiorem/sub/request/AbstractRequester.java index b6abf20..ec663df 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/AbstractRequester.java +++ b/src/main/java/com/rometools/certiorem/sub/request/AbstractRequester.java @@ -16,15 +16,15 @@ * limitations under the License. */ -package org.rometools.certiorem.sub.request; +package com.rometools.certiorem.sub.request; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; -import org.rometools.certiorem.sub.Requester; -import org.rometools.certiorem.sub.data.Subscription; +import com.rometools.certiorem.sub.Requester; +import com.rometools.certiorem.sub.data.Subscription; /** * diff --git a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java b/src/main/java/com/rometools/certiorem/sub/request/AsyncRequester.java similarity index 96% rename from src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java rename to src/main/java/com/rometools/certiorem/sub/request/AsyncRequester.java index 62a2a82..bae5291 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/AsyncRequester.java +++ b/src/main/java/com/rometools/certiorem/sub/request/AsyncRequester.java @@ -16,14 +16,15 @@ * limitations under the License. */ -package org.rometools.certiorem.sub.request; +package com.rometools.certiorem.sub.request; import java.io.IOException; -import org.rometools.certiorem.sub.data.Subscription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.certiorem.sub.data.Subscription; + /** * A simple requester implementation that always makes requests as Async. * diff --git a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java b/src/main/java/com/rometools/certiorem/sub/request/SyncRequester.java similarity index 95% rename from src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java rename to src/main/java/com/rometools/certiorem/sub/request/SyncRequester.java index 7896991..721b0c8 100644 --- a/src/main/java/org/rometools/certiorem/sub/request/SyncRequester.java +++ b/src/main/java/com/rometools/certiorem/sub/request/SyncRequester.java @@ -20,14 +20,15 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ -package org.rometools.certiorem.sub.request; +package com.rometools.certiorem.sub.request; import java.io.IOException; -import org.rometools.certiorem.sub.data.Subscription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.certiorem.sub.data.Subscription; + /** * A simple requester implementation that always makes requests as Async. * diff --git a/src/main/java/org/rometools/certiorem/sub/request/package.html b/src/main/java/com/rometools/certiorem/sub/request/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/sub/request/package.html rename to src/main/java/com/rometools/certiorem/sub/request/package.html diff --git a/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java b/src/main/java/com/rometools/certiorem/web/AbstractHubServlet.java similarity index 95% rename from src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java rename to src/main/java/com/rometools/certiorem/web/AbstractHubServlet.java index 0a4ff7c..28ee4bf 100644 --- a/src/main/java/org/rometools/certiorem/web/AbstractHubServlet.java +++ b/src/main/java/com/rometools/certiorem/web/AbstractHubServlet.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.web; +package com.rometools.certiorem.web; import java.io.IOException; import java.util.Arrays; @@ -26,8 +26,8 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.rometools.certiorem.HttpStatusCodeException; -import org.rometools.certiorem.hub.Hub; +import com.rometools.certiorem.HttpStatusCodeException; +import com.rometools.certiorem.hub.Hub; /** * diff --git a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java b/src/main/java/com/rometools/certiorem/web/AbstractSubServlet.java similarity index 94% rename from src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java rename to src/main/java/com/rometools/certiorem/web/AbstractSubServlet.java index 6094731..3b6f343 100644 --- a/src/main/java/org/rometools/certiorem/web/AbstractSubServlet.java +++ b/src/main/java/com/rometools/certiorem/web/AbstractSubServlet.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.web; +package com.rometools.certiorem.web; import java.io.IOException; @@ -26,8 +26,8 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.rometools.certiorem.HttpStatusCodeException; -import org.rometools.certiorem.sub.Subscriptions; +import com.rometools.certiorem.HttpStatusCodeException; +import com.rometools.certiorem.sub.Subscriptions; /** * diff --git a/src/main/java/org/rometools/certiorem/web/package.html b/src/main/java/com/rometools/certiorem/web/package.html similarity index 100% rename from src/main/java/org/rometools/certiorem/web/package.html rename to src/main/java/com/rometools/certiorem/web/package.html diff --git a/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java b/src/test/java/com/rometools/certiorem/hub/AlwaysVerifier.java similarity index 90% rename from src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java rename to src/test/java/com/rometools/certiorem/hub/AlwaysVerifier.java index 5d198e8..af5f9fb 100644 --- a/src/test/java/org/rometools/certiorem/hub/AlwaysVerifier.java +++ b/src/test/java/com/rometools/certiorem/hub/AlwaysVerifier.java @@ -16,9 +16,10 @@ * limitations under the License. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; -import org.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.Verifier; +import com.rometools.certiorem.hub.data.Subscriber; /** * diff --git a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java b/src/test/java/com/rometools/certiorem/hub/ControllerTest.java similarity index 93% rename from src/test/java/org/rometools/certiorem/hub/ControllerTest.java rename to src/test/java/com/rometools/certiorem/hub/ControllerTest.java index d7dcb6d..7d5b1cd 100644 --- a/src/test/java/org/rometools/certiorem/hub/ControllerTest.java +++ b/src/test/java/com/rometools/certiorem/hub/ControllerTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -26,12 +26,14 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.rometools.certiorem.HttpStatusCodeException; -import org.rometools.certiorem.hub.data.HubDAO; -import org.rometools.certiorem.hub.data.ram.InMemoryHubDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.certiorem.HttpStatusCodeException; +import com.rometools.certiorem.hub.Hub; +import com.rometools.certiorem.hub.Notifier; +import com.rometools.certiorem.hub.data.HubDAO; +import com.rometools.certiorem.hub.data.ram.InMemoryHubDAO; import com.rometools.fetcher.FeedFetcher; import com.rometools.fetcher.impl.HashMapFeedInfoCache; import com.rometools.fetcher.impl.HttpURLFeedFetcher; diff --git a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java b/src/test/java/com/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java similarity index 89% rename from src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java rename to src/test/java/com/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java index 54c2306..00b25f0 100644 --- a/src/test/java/org/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java +++ b/src/test/java/com/rometools/certiorem/hub/DeltaSyndFeedInfoTest.java @@ -2,7 +2,7 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; import static org.junit.Assert.assertTrue; @@ -13,10 +13,11 @@ import java.util.List; import org.junit.Before; import org.junit.Test; +import com.rometools.certiorem.hub.DeltaFeedInfoCache; import com.rometools.fetcher.impl.HashMapFeedInfoCache; import com.rometools.fetcher.impl.HttpURLFeedFetcher; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndEntry; +import com.rometools.rome.feed.synd.SyndFeed; /** * diff --git a/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java b/src/test/java/com/rometools/certiorem/hub/ExceptionVerifier.java similarity index 91% rename from src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java rename to src/test/java/com/rometools/certiorem/hub/ExceptionVerifier.java index 7e7ae45..3aa877c 100644 --- a/src/test/java/org/rometools/certiorem/hub/ExceptionVerifier.java +++ b/src/test/java/com/rometools/certiorem/hub/ExceptionVerifier.java @@ -16,9 +16,10 @@ * limitations under the License. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; -import org.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.Verifier; +import com.rometools.certiorem.hub.data.Subscriber; /** * diff --git a/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java b/src/test/java/com/rometools/certiorem/hub/NeverVerifier.java similarity index 90% rename from src/test/java/org/rometools/certiorem/hub/NeverVerifier.java rename to src/test/java/com/rometools/certiorem/hub/NeverVerifier.java index e4733bf..a5aa95e 100644 --- a/src/test/java/org/rometools/certiorem/hub/NeverVerifier.java +++ b/src/test/java/com/rometools/certiorem/hub/NeverVerifier.java @@ -16,9 +16,10 @@ * limitations under the License. */ -package org.rometools.certiorem.hub; +package com.rometools.certiorem.hub; -import org.rometools.certiorem.hub.data.Subscriber; +import com.rometools.certiorem.hub.Verifier; +import com.rometools.certiorem.hub.data.Subscriber; /** * diff --git a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java b/src/test/java/com/rometools/certiorem/hub/data/AbstractDAOTest.java similarity index 95% rename from src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java rename to src/test/java/com/rometools/certiorem/hub/data/AbstractDAOTest.java index 191f5cb..e70016a 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/AbstractDAOTest.java +++ b/src/test/java/com/rometools/certiorem/hub/data/AbstractDAOTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.data; +package com.rometools.certiorem.hub.data; import java.util.List; @@ -25,6 +25,9 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.rometools.certiorem.hub.data.HubDAO; +import com.rometools.certiorem.hub.data.Subscriber; + /** * * @author robert.cooper diff --git a/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java b/src/test/java/com/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java similarity index 80% rename from src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java rename to src/test/java/com/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java index be5f0a7..26917e3 100644 --- a/src/test/java/org/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java +++ b/src/test/java/com/rometools/certiorem/hub/data/ram/InMemoryDAOTest.java @@ -16,10 +16,11 @@ * limitations under the License. */ -package org.rometools.certiorem.hub.data.ram; +package com.rometools.certiorem.hub.data.ram; -import org.rometools.certiorem.hub.data.AbstractDAOTest; -import org.rometools.certiorem.hub.data.HubDAO; +import com.rometools.certiorem.hub.data.AbstractDAOTest; +import com.rometools.certiorem.hub.data.HubDAO; +import com.rometools.certiorem.hub.data.ram.InMemoryHubDAO; /** * From 84e21766aa6018819c2e4f8a238fe000ea6b1253 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 30 May 2014 16:43:52 +0200 Subject: [PATCH 17/23] Removed "cyclic dependency" to parent POM --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 0dafbbd..8cc47c6 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,7 @@ com.rometools rome-fetcher + 1.5.0-SNAPSHOT commons-httpclient From 646676097ea7b2e31036d25f5e7888e21491cd39 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 00:13:31 +0200 Subject: [PATCH 18/23] Prepared release --- pom.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 8cc47c6..9a7b296 100644 --- a/pom.xml +++ b/pom.xml @@ -7,10 +7,11 @@ com.rometools rome-parent - 1.5.0-SNAPSHOT + 1.5.0 rome-certiorem + 1.5.0-SNAPSHOT jar rome-certiorem @@ -18,9 +19,9 @@ A PubSubHubub implementation for Java based on ROME - scm:git:git@github.com:rometools/rome-certiorem.git - scm:git:git@github.com:rometools/rome-certiorem.git - https://github.com/rometools/rome-certiorem/ + scm:git:ssh://github.com/rometools/rome-certiorem.git + scm:git:ssh://git@github.com/rometools/rome-certiorem.git + https://github.com/rometools/rome-certiorem From 8ac9f2b133a32b5991f0bc074e90460ad9408ad4 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 00:19:01 +0200 Subject: [PATCH 19/23] Prepared release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9a7b296..6b9e463 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ com.rometools rome-fetcher - 1.5.0-SNAPSHOT + 1.5.0 commons-httpclient From 2ad74e03e52e0fff569dd2854e5c87f6e9d82e87 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 00:53:18 +0200 Subject: [PATCH 20/23] [maven-release-plugin] prepare release rome-certiorem-1.5.0 --- pom.xml | 223 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 111 insertions(+), 112 deletions(-) diff --git a/pom.xml b/pom.xml index 6b9e463..e055c20 100644 --- a/pom.xml +++ b/pom.xml @@ -1,112 +1,111 @@ - - - - 4.0.0 - - - com.rometools - rome-parent - 1.5.0 - - - rome-certiorem - 1.5.0-SNAPSHOT - jar - - rome-certiorem - - A PubSubHubub implementation for Java based on ROME - - - scm:git:ssh://github.com/rometools/rome-certiorem.git - scm:git:ssh://git@github.com/rometools/rome-certiorem.git - https://github.com/rometools/rome-certiorem - - - - - Robert Cooper - kebernet@gmail.comM - http://www.kebernet.net - - - Farrukh Najmi - http://wellfleetsoftware.com - - - - - - sonatype-nexus-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - org.apache.maven.plugins - maven-site-plugin - - 9000 - ${basedir}/target/site/tempdir - - - - org.apache.maven.plugins - maven-scm-publish-plugin - - gh-pages - ${project.scm.developerConnection} - ${project.build.directory}/site - - - - - - - - com.rometools - rome-fetcher - 1.5.0 - - - commons-httpclient - commons-httpclient - - - - - javax.servlet - servlet-api - provided - - - javax.persistence - persistence-api - provided - - - org.slf4j - slf4j-api - - - ch.qos.logback - logback-classic - test - - - junit - junit - test - - - - + + + + 4.0.0 + + + com.rometools + rome-parent + 1.5.0 + + + rome-certiorem + 1.5.0 + jar + + rome-certiorem + + A PubSubHubub implementation for Java based on ROME + + + scm:git:ssh://github.com/rometools/rome-certiorem.git + scm:git:ssh://git@github.com/rometools/rome-certiorem.git + https://github.com/rometools/rome-certiorem + + + + + Robert Cooper + kebernet@gmail.comM + http://www.kebernet.net + + + Farrukh Najmi + http://wellfleetsoftware.com + + + + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + + + + org.apache.maven.plugins + maven-site-plugin + + 9000 + ${basedir}/target/site/tempdir + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + gh-pages + ${project.scm.developerConnection} + ${project.build.directory}/site + + + + + + + + com.rometools + rome-fetcher + 1.5.0 + + + commons-httpclient + commons-httpclient + + + + + javax.servlet + servlet-api + provided + + + javax.persistence + persistence-api + provided + + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + test + + + junit + junit + test + + + + From cab96cb57285c96b4f58068b1c6796db22666393 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 00:53:23 +0200 Subject: [PATCH 21/23] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e055c20..71e2a60 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ rome-certiorem - 1.5.0 + 1.6.0-SNAPSHOT jar rome-certiorem From cd613c3fc9f4c6d5488b3326b80775beeda3983e Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 22:20:44 +0200 Subject: [PATCH 22/23] Prepared next development version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 71e2a60..bfe1bf1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.rometools rome-parent - 1.5.0 + 1.6.0-SNAPSHOT rome-certiorem @@ -74,7 +74,7 @@ com.rometools rome-fetcher - 1.5.0 + 1.6.0-SNAPSHOT commons-httpclient From 718f10aded5bbb95ac88370f6d69568e1496f51e Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 7 Feb 2015 09:48:52 +0100 Subject: [PATCH 23/23] Formatted POM file --- pom.xml | 172 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/pom.xml b/pom.xml index bfe1bf1..a92e869 100644 --- a/pom.xml +++ b/pom.xml @@ -1,39 +1,39 @@ - - + - 4.0.0 + 4.0.0 - - com.rometools - rome-parent - 1.6.0-SNAPSHOT - + + com.rometools + rome-parent + 1.6.0-SNAPSHOT + - rome-certiorem - 1.6.0-SNAPSHOT - jar + rome-certiorem + 1.6.0-SNAPSHOT + jar - rome-certiorem + rome-certiorem - A PubSubHubub implementation for Java based on ROME + A PubSubHubub implementation for Java based on ROME - - scm:git:ssh://github.com/rometools/rome-certiorem.git - scm:git:ssh://git@github.com/rometools/rome-certiorem.git - https://github.com/rometools/rome-certiorem - + + scm:git:ssh://github.com/rometools/rome-certiorem.git + scm:git:ssh://git@github.com/rometools/rome-certiorem.git + https://github.com/rometools/rome-certiorem + - - - Robert Cooper - kebernet@gmail.comM - http://www.kebernet.net - - - Farrukh Najmi - http://wellfleetsoftware.com - - + + + Robert Cooper + kebernet@gmail.comM + http://www.kebernet.net + + + Farrukh Najmi + http://wellfleetsoftware.com + + @@ -48,64 +48,64 @@ - - - - org.apache.maven.plugins - maven-site-plugin - - 9000 - ${basedir}/target/site/tempdir - - - - org.apache.maven.plugins - maven-scm-publish-plugin - - gh-pages - ${project.scm.developerConnection} - ${project.build.directory}/site - - - - + + + + org.apache.maven.plugins + maven-site-plugin + + 9000 + ${basedir}/target/site/tempdir + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + gh-pages + ${project.scm.developerConnection} + ${project.build.directory}/site + + + + - - - com.rometools - rome-fetcher + + + com.rometools + rome-fetcher 1.6.0-SNAPSHOT - - - commons-httpclient - commons-httpclient - - - - - javax.servlet - servlet-api - provided - - - javax.persistence - persistence-api - provided - - - org.slf4j - slf4j-api - - - ch.qos.logback - logback-classic - test - - - junit - junit - test - - + + + commons-httpclient + commons-httpclient + + + + + javax.servlet + servlet-api + provided + + + javax.persistence + persistence-api + provided + + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + test + + + junit + junit + test + +