Migrated logging to SLF4J

This commit is contained in:
Patrick Gotthard 2014-04-14 19:10:23 +02:00
parent bf527ec7aa
commit 00c4101063
12 changed files with 141 additions and 114 deletions

View file

@ -78,6 +78,15 @@
<artifactId>persistence-api</artifactId> <artifactId>persistence-api</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View file

@ -25,8 +25,6 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.HttpStatusCodeException;
import org.rometools.certiorem.hub.Notifier.SubscriptionSummaryCallback; 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.Subscriber;
import org.rometools.certiorem.hub.data.SubscriptionSummary; import org.rometools.certiorem.hub.data.SubscriptionSummary;
import org.rometools.fetcher.FeedFetcher; import org.rometools.fetcher.FeedFetcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
/** /**
* The basic business logic controller for the Hub implementation. It is * The basic business logic controller for the Hub implementation. It is intended to be usable under
* intended to be usable under a very thin servlet wrapper, or other, non-HTTP * a very thin servlet wrapper, or other, non-HTTP notification methods you might want to use.
* notification methods you might want to use.
* *
* @author robert.cooper * @author robert.cooper
*/ */
public class Hub { public class Hub {
private static final Logger LOG = LoggerFactory.getLogger(Hub.class);
private static final HashSet<String> STANDARD_SCHEMES = new HashSet<String>(); private static final HashSet<String> STANDARD_SCHEMES = new HashSet<String>();
static { static {
@ -82,12 +84,9 @@ public class Hub {
* *
* @param dao The persistence HubDAO to use * @param dao The persistence HubDAO to use
* @param verifier The verification strategy to use * @param verifier The verification strategy to use
* @param validSchemes A list of valid URI schemes for callbacks (default: * @param validSchemes A list of valid URI schemes for callbacks (default: http, https)
* http, https) * @param validPorts A list of valid port numbers for callbacks (default: any)
* @param validPorts A list of valid port numbers for callbacks (default: * @param validTopics A set of valid topic URIs which can be subscribed to (default: any)
* 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<String> validSchemes, public Hub(final HubDAO dao, final Verifier verifier, final Notifier notifier, final FeedFetcher fetcher, final Set<String> validSchemes,
final Set<Integer> validPorts, final Set<String> validTopics) { final Set<Integer> validPorts, final Set<String> validTopics) {
@ -118,20 +117,19 @@ public class Hub {
/** /**
* Sends a notification to the subscribers * Sends a notification to the subscribers
* *
* @param requestHost the host name the hub is running on. (Used for the * @param requestHost the host name the hub is running on. (Used for the user agent)
* user agent)
* @param topic the URL of the topic that was updated. * @param topic the URL of the topic that was updated.
* @throws HttpStatusCodeException a wrapper exception with a recommended * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the
* status code for the request. * request.
*/ */
public void sendNotification(final String requestHost, final String 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; 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 { try {
final List<? extends Subscriber> subscribers = dao.subscribersForTopic(topic); final List<? extends Subscriber> subscribers = dao.subscribersForTopic(topic);
if (subscribers.isEmpty()) { 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; return;
} }
@ -149,7 +147,7 @@ public class Hub {
final StringBuilder userAgent = new StringBuilder("ROME-Certiorem (+http://").append(requestHost).append("; ").append(total) final StringBuilder userAgent = new StringBuilder("ROME-Certiorem (+http://").append(requestHost).append("; ").append(total)
.append(" subscribers)").append(hosts); .append(" subscribers)").append(hosts);
final SyndFeed feed = fetcher.retrieveFeed(userAgent.toString(), new URL(topic)); 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() { notifier.notifySubscribers(subscribers, feed, new SubscriptionSummaryCallback() {
@Override @Override
public void onSummaryInfo(final SubscriptionSummary summary) { public void onSummaryInfo(final SubscriptionSummary summary) {
@ -157,7 +155,7 @@ public class Hub {
} }
}); });
} catch (final Exception ex) { } 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); throw new HttpStatusCodeException(500, ex.getMessage(), ex);
} }
} }
@ -171,15 +169,14 @@ public class Hub {
* @param lease_seconds Duration of the lease * @param lease_seconds Duration of the lease
* @param secret Secret value * @param secret Secret value
* @param verify_token verify_token; * @param verify_token verify_token;
* @return Boolean.TRUE if the subscription succeeded synchronously, * @return Boolean.TRUE if the subscription succeeded synchronously, Boolean.FALSE if the
* Boolean.FALSE if the subscription failed synchronously, or null * subscription failed synchronously, or null if the request is asynchronous.
* if the request is asynchronous. * @throws HttpStatusCodeException a wrapper exception with a recommended status code for the
* @throws HttpStatusCodeException a wrapper exception with a recommended * request.
* status code for the request.
*/ */
public Boolean subscribe(final String callback, final String topic, final String verify, final long lease_seconds, final String secret, public Boolean subscribe(final String callback, final String topic, final String verify, final long lease_seconds, final String secret,
final String verify_token) { 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 {
try { try {
assert callback != null : "Callback URL is required."; assert callback != null : "Callback URL is required.";
@ -206,8 +203,7 @@ public class Hub {
@Override @Override
public void onVerify(final boolean verified) { public void onVerify(final boolean verified) {
if (verified) { if (verified) {
Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Verified {0} subscribed to {1}", LOG.debug("Verified {} subscribed to {}", subscriber.getCallback(), subscriber.getTopic());
new Object[] { subscriber.getCallback(), subscriber.getTopic() });
dao.addSubscriber(subscriber); dao.addSubscriber(subscriber);
} }
} }
@ -248,8 +244,7 @@ public class Hub {
@Override @Override
public void onVerify(final boolean verified) { public void onVerify(final boolean verified) {
Logger.getLogger(Hub.class.getName()).log(Level.FINE, "Unsubscribe for {0} at {1} verified {2}", LOG.debug("Unsubscribe for {} at {} verified {}", subscriber.getTopic(), subscriber.getCallback(), verified);
new Object[] { subscriber.getTopic(), subscriber.getCallback(), verified });
if (verified) { if (verified) {
dao.removeSubscriber(topic, callback); dao.removeSubscriber(topic, callback);
} }

View file

@ -26,12 +26,12 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.List; 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.Notifier;
import org.rometools.certiorem.hub.data.Subscriber; import org.rometools.certiorem.hub.data.Subscriber;
import org.rometools.certiorem.hub.data.SubscriptionSummary; 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.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException; import com.sun.syndication.io.FeedException;
@ -42,20 +42,23 @@ import com.sun.syndication.io.SyndFeedOutput;
* @author robert.cooper * @author robert.cooper
*/ */
public abstract class AbstractNotifier implements Notifier { 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 * This method will serialize the synd feed and build Notifications for the implementation class
* implementation class to handle. * to handle.
* *
* @see enqueueNotification * @see enqueueNotification
* *
* @param subscribers List of subscribers to notify * @param subscribers List of subscribers to notify
* @param value The SyndFeed object to send * @param value The SyndFeed object to send
* @param callback A callback that will be invoked each time a subscriber is * @param callback A callback that will be invoked each time a subscriber is notified.
* notified.
* *
*/ */
@Override @Override
public void notifySubscribers(final List<? extends Subscriber> subscribers, final SyndFeed value, final SubscriptionSummaryCallback callback) { public void notifySubscribers(final List<? extends Subscriber> subscribers, final SyndFeed value, final SubscriptionSummaryCallback callback) {
String mimeType = null; String mimeType = null;
if (value.getFeedType().startsWith("rss")) { if (value.getFeedType().startsWith("rss")) {
@ -71,10 +74,10 @@ public abstract class AbstractNotifier implements Notifier {
output.output(value, new OutputStreamWriter(baos)); output.output(value, new OutputStreamWriter(baos));
baos.close(); baos.close();
} catch (final IOException ex) { } 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); throw new RuntimeException("Unable to output the feed.", ex);
} catch (final FeedException 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); 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); protected abstract void enqueueNotification(Notification not);
/** /**
* POSTs the payload to the subscriber's callback and returns a * POSTs the payload to the subscriber's callback and returns a SubscriptionSummary with
* SubscriptionSummary with subscriber counts (where possible) and the * subscriber counts (where possible) and the success state of the notification.
* success state of the notification.
* *
* @param subscriber subscriber data. * @param subscriber subscriber data.
* @param mimeType MIME type for the request * @param mimeType MIME type for the request
@ -114,7 +116,7 @@ public abstract class AbstractNotifier implements Notifier {
try { try {
final 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()); LOG.info("Posting notification to subscriber {}", subscriber.getCallback());
result.setHost(target.getHost()); result.setHost(target.getHost());
final HttpURLConnection connection = (HttpURLConnection) target.openConnection(); final HttpURLConnection connection = (HttpURLConnection) target.openConnection();
@ -132,9 +134,8 @@ public abstract class AbstractNotifier implements Notifier {
connection.disconnect(); connection.disconnect();
if (responseCode != 200) { 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); result.setLastPublishSuccessful(false);
return result; return result;
} }
@ -142,17 +143,17 @@ public abstract class AbstractNotifier implements Notifier {
try { try {
result.setSubscribers(Integer.parseInt(subscribers)); result.setSubscribers(Integer.parseInt(subscribers));
} catch (final NumberFormatException nfe) { } 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); result.setSubscribers(-1);
} }
} else { } else {
result.setSubscribers(-1); result.setSubscribers(-1);
} }
} catch (final MalformedURLException ex) { } catch (final MalformedURLException ex) {
Logger.getLogger(AbstractNotifier.class.getName()).log(Level.WARNING, null, ex); LOG.warn(null, ex);
result.setLastPublishSuccessful(false); result.setLastPublishSuccessful(false);
} catch (final IOException ex) { } catch (final IOException ex) {
Logger.getLogger(AbstractNotifier.class.getName()).log(Level.SEVERE, null, ex); LOG.error(null, ex);
result.setLastPublishSuccessful(false); result.setLastPublishSuccessful(false);
} }

View file

@ -27,19 +27,22 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.UUID; 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.Verifier;
import org.rometools.certiorem.hub.data.Subscriber; 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 * An abstract verifier based on the java.net HTTP classes. This implements only synchronous
* synchronous operations, and expects a child class to do Async ops. * operations, and expects a child class to do Async ops.
* *
* @author robert.cooper * @author robert.cooper
*/ */
public abstract class AbstractVerifier implements Verifier { public abstract class AbstractVerifier implements Verifier {
private static final Logger LOG = LoggerFactory.getLogger(AbstractVerifier.class);
@Override @Override
public boolean verifySubcribeSyncronously(final Subscriber subscriber) { public boolean verifySubcribeSyncronously(final Subscriber subscriber) {
return doOp(Verifier.MODE_SUBSCRIBE, subscriber); return doOp(Verifier.MODE_SUBSCRIBE, subscriber);
@ -85,11 +88,10 @@ public abstract class AbstractVerifier implements Verifier {
return true; return true;
} }
} catch (final UnsupportedEncodingException ex) { } 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); throw new RuntimeException("Should not happen. UTF-8 threw unsupported encoding", ex);
} catch (final IOException ex) { } catch (final IOException ex) {
Logger.getLogger(AbstractVerifier.class.getName()).log(Level.SEVERE, null, ex); LOG.error("An IOException occured", ex);
return false; return false;
} }
} }

View file

@ -25,8 +25,9 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.concurrent.ThreadPoolExecutor; 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.SyndFeed;
import com.sun.syndication.feed.synd.SyndLink; import com.sun.syndication.feed.synd.SyndLink;
@ -37,18 +38,19 @@ import com.sun.syndication.feed.synd.SyndLink;
* @author robert.cooper * @author robert.cooper
*/ */
public class Publisher { public class Publisher {
private static final Logger LOG = LoggerFactory.getLogger(Publisher.class);
private ThreadPoolExecutor executor; private ThreadPoolExecutor executor;
/** /**
* Constructs a new publisher. This publisher will spawn a new thread for * Constructs a new publisher. This publisher will spawn a new thread for each async send.
* each async send.
*/ */
public Publisher() { public Publisher() {
} }
/** /**
* Constructs a new publisher with an optional ThreadPoolExector for sending * Constructs a new publisher with an optional ThreadPoolExector for sending updates.
* updates.
*/ */
public Publisher(final ThreadPoolExecutor executor) { public Publisher(final ThreadPoolExecutor executor) {
this.executor = executor; this.executor = executor;
@ -84,17 +86,16 @@ public class Publisher {
} }
} catch (final UnsupportedEncodingException ex) { } 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); throw new NotificationException("Could not encode URL", ex);
} catch (final IOException 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); throw new NotificationException("Unable to communicate with " + hub, ex);
} }
} }
/** /**
* Sends a notification for a feed located at "topic". The feed MUST contain * Sends a notification for a feed located at "topic". The feed MUST contain rel="hub".
* rel="hub".
* *
* @param topic URL for the feed * @param topic URL for the feed
* @param feed The feed itself * @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 * Sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links.
* rel="self" links.
* *
* @param feed The feed to notify * @param feed The feed to notify
* @throws NotificationException Any failure * @throws NotificationException Any failure
@ -176,8 +176,8 @@ public class Publisher {
} }
/** /**
* Asynchronously sends a notification for a feed located at "topic". The * Asynchronously sends a notification for a feed located at "topic". The feed MUST contain
* feed MUST contain rel="hub". * rel="hub".
* *
* @param topic URL for the feed * @param topic URL for the feed
* @param feed The feed itself * @param feed The feed itself
@ -205,8 +205,8 @@ public class Publisher {
} }
/** /**
* Asyncronously sends a notification for a feed. The feed MUST contain * Asyncronously sends a notification for a feed. The feed MUST contain rel="hub" and rel="self"
* rel="hub" and rel="self" links. * links.
* *
* @param feed The feed to notify * @param feed The feed to notify
* @param callback A callback invoked when the notification completes. * @param callback A callback invoked when the notification completes.

View file

@ -28,8 +28,6 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rometools.certiorem.HttpStatusCodeException; import org.rometools.certiorem.HttpStatusCodeException;
import org.rometools.certiorem.sub.Requester.RequestCallback; 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.certiorem.sub.data.SubscriptionCallback;
import org.rometools.fetcher.impl.FeedFetcherCache; import org.rometools.fetcher.impl.FeedFetcherCache;
import org.rometools.fetcher.impl.SyndFeedInfo; 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.SyndFeed;
import com.sun.syndication.feed.synd.SyndLink; import com.sun.syndication.feed.synd.SyndLink;
@ -50,7 +50,7 @@ import com.sun.syndication.io.SyndFeedInput;
*/ */
public class Subscriptions { public class Subscriptions {
private static final Logger LOGGER = Logger.getLogger(Subscriptions.class.getName()); private static final Logger LOG = LoggerFactory.getLogger(Subscriptions.class);
// TODO unsubscribe. // TODO unsubscribe.
private FeedFetcherCache cache; private FeedFetcherCache cache;
@ -72,7 +72,7 @@ public class Subscriptions {
try { try {
this.callback(callbackPath, feed.getBytes("UTF-8")); this.callback(callbackPath, feed.getBytes("UTF-8"));
} catch (final UnsupportedEncodingException ex) { } 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); throw new HttpStatusCodeException(400, "Unable to parse feed.", ex);
} }
} }
@ -83,10 +83,10 @@ public class Subscriptions {
try { try {
this.callback(callbackPath, input.build(new InputStreamReader(feed))); this.callback(callbackPath, input.build(new InputStreamReader(feed)));
} catch (final IllegalArgumentException ex) { } 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); throw new HttpStatusCodeException(500, "Unable to parse feed.", ex);
} catch (final FeedException 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); throw new HttpStatusCodeException(400, "Unable to parse feed.", ex);
} }
} }
@ -102,7 +102,7 @@ public class Subscriptions {
} }
final String id = callbackPath.substring(callbackPrefix.length()); 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); final Subscription s = dao.findById(id);
if (s == null) { if (s == null) {
@ -118,7 +118,7 @@ public class Subscriptions {
url = new URL(s.getSourceUrl()); url = new URL(s.getSourceUrl());
info = cache.getFeedInfo(url); info = cache.getFeedInfo(url);
} catch (final MalformedURLException ex) { } catch (final MalformedURLException ex) {
LOGGER.log(Level.SEVERE, null, ex); LOG.error("Malformed URL", ex);
} }
if (info == null) { if (info == null) {
@ -196,7 +196,7 @@ public class Subscriptions {
} }
final String id = callbackPath.substring(callbackPrefix.length()); 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); final Subscription s = dao.findById(id);
if (s == null) { if (s == null) {
throw new HttpStatusCodeException(404, "Not a valid subscription id", null); throw new HttpStatusCodeException(404, "Not a valid subscription id", null);
@ -221,7 +221,7 @@ public class Subscriptions {
} else { } else {
throw new HttpStatusCodeException(400, "Unsupported mode " + mode, null); throw new HttpStatusCodeException(400, "Unsupported mode " + mode, null);
} }
LOGGER.log(Level.FINE, "Validated. Returning {0}", challenge); LOG.debug("Validated. Returning {}", challenge);
return challenge; return challenge;
} }
@ -248,7 +248,7 @@ public class Subscriptions {
break; break;
} catch (final URISyntaxException ex) { } catch (final URISyntaxException ex) {
LOGGER.log(Level.SEVERE, null, ex); LOG.error(null, ex);
} }
} }
} }

View file

@ -25,11 +25,11 @@ package org.rometools.certiorem.sub.data.ram;
import java.util.Date; import java.util.Date;
import java.util.concurrent.ConcurrentHashMap; 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.SubDAO;
import org.rometools.certiorem.sub.data.Subscription; 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 { public class InMemorySubDAO implements SubDAO {
private static final Logger LOG = LoggerFactory.getLogger(InMemorySubDAO.class);
private final ConcurrentHashMap<String, Subscription> subscriptions = new ConcurrentHashMap<String, Subscription>(); private final ConcurrentHashMap<String, Subscription> subscriptions = new ConcurrentHashMap<String, Subscription>();
@Override @Override
@ -46,8 +48,7 @@ public class InMemorySubDAO implements SubDAO {
return null; return null;
} }
if (s.getExpirationTime() > 0 && s.getExpirationTime() <= System.currentTimeMillis()) { if (s.getExpirationTime() > 0 && s.getExpirationTime() <= System.currentTimeMillis()) {
Logger.getLogger(InMemorySubDAO.class.getName()).log(Level.FINE, "Subscription {0} expired at {1}", LOG.debug("Subscription {} expired at {}", s.getSourceUrl(), new Date(s.getExpirationTime()));
new Object[] { s.getSourceUrl(), new Date(s.getExpirationTime()) });
subscriptions.remove(id); subscriptions.remove(id);
return null; return null;
@ -58,7 +59,7 @@ public class InMemorySubDAO implements SubDAO {
@Override @Override
public Subscription addSubscription(final Subscription s) { public Subscription addSubscription(final Subscription s) {
subscriptions.put(s.getId(), 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; return s;
} }

View file

@ -19,10 +19,10 @@
package org.rometools.certiorem.sub.request; package org.rometools.certiorem.sub.request;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rometools.certiorem.sub.data.Subscription; 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. * A simple requester implementation that always makes requests as Async.
@ -30,18 +30,20 @@ import org.rometools.certiorem.sub.data.Subscription;
* @author robert.cooper * @author robert.cooper
*/ */
public class AsyncRequester extends AbstractRequester { public class AsyncRequester extends AbstractRequester {
private static final Logger LOG = LoggerFactory.getLogger(AsyncRequester.class);
@Override @Override
public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds, public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds,
final String secret, final String callbackUrl, final RequestCallback callback) { 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}", LOG.debug("Sending subscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl);
new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl });
final Runnable r = new Runnable() { final Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback); sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback);
} catch (final Exception ex) { } catch (final Exception ex) {
Logger.getLogger(AsyncRequester.class.getName()).log(Level.SEVERE, null, ex); LOG.error(null, ex);
callback.onFailure(ex); callback.onFailure(ex);
} }
} }
@ -52,15 +54,14 @@ public class AsyncRequester extends AbstractRequester {
@Override @Override
public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret, public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret,
final String callbackUrl, final RequestCallback callback) { final String callbackUrl, final RequestCallback callback) {
Logger.getLogger(AsyncRequester.class.getName()).log(Level.FINE, "Sending unsubscribe request to {0} for {1} to {2}", LOG.debug("Sending unsubscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl);
new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl });
final Runnable r = new Runnable() { final Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback); sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback);
} catch (final IOException ex) { } catch (final IOException ex) {
Logger.getLogger(AsyncRequester.class.getName()).log(Level.SEVERE, null, ex); LOG.error(null, ex);
callback.onFailure(ex); callback.onFailure(ex);
} }
} }

View file

@ -23,10 +23,10 @@
package org.rometools.certiorem.sub.request; package org.rometools.certiorem.sub.request;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rometools.certiorem.sub.data.Subscription; 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. * A simple requester implementation that always makes requests as Async.
@ -34,16 +34,18 @@ import org.rometools.certiorem.sub.data.Subscription;
* @author Farrukh Najmi * @author Farrukh Najmi
*/ */
public class SyncRequester extends AbstractRequester { public class SyncRequester extends AbstractRequester {
private static final Logger LOG = LoggerFactory.getLogger(SyncRequester.class);
@Override @Override
public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds, public void sendSubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final long leaseSeconds,
final String secret, final String callbackUrl, final RequestCallback callback) { 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}", LOG.info("Sending subscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl);
new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl });
try { try {
sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback); sendRequest(hubUrl, "subscribe", subscription, verifySync, leaseSeconds, secret, callbackUrl, callback);
callback.onSuccess(); callback.onSuccess();
} catch (final Exception ex) { } catch (final Exception ex) {
Logger.getLogger(SyncRequester.class.getName()).log(Level.SEVERE, null, ex); LOG.error(null, ex);
callback.onFailure(ex); callback.onFailure(ex);
} }
} }
@ -51,13 +53,12 @@ public class SyncRequester extends AbstractRequester {
@Override @Override
public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret, public void sendUnsubscribeRequest(final String hubUrl, final Subscription subscription, final String verifySync, final String secret,
final String callbackUrl, final RequestCallback callback) { final String callbackUrl, final RequestCallback callback) {
Logger.getLogger(SyncRequester.class.getName()).log(Level.INFO, "Sending unsubscribe request to {0} for {1} to {2}", LOG.info("Sending unsubscribe request to {} for {} to {}", hubUrl, subscription.getSourceUrl(), callbackUrl);
new Object[] { hubUrl, subscription.getSourceUrl(), callbackUrl });
try { try {
sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback); sendRequest(hubUrl, "unsubscribe", subscription, verifySync, -1, secret, callbackUrl, callback);
callback.onSuccess(); callback.onSuccess();
} catch (final IOException ex) { } catch (final IOException ex) {
Logger.getLogger(SyncRequester.class.getName()).log(Level.SEVERE, null, ex); LOG.error(null, ex);
callback.onFailure(ex); callback.onFailure(ex);
} }
} }

View file

@ -21,8 +21,6 @@ package org.rometools.certiorem.hub;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.util.logging.Logger;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; 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.FeedFetcher;
import org.rometools.fetcher.impl.HashMapFeedInfoCache; import org.rometools.fetcher.impl.HashMapFeedInfoCache;
import org.rometools.fetcher.impl.HttpURLFeedFetcher; import org.rometools.fetcher.impl.HttpURLFeedFetcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
* @author robert.cooper * @author robert.cooper
*/ */
public class ControllerTest { public class ControllerTest {
private static final Logger LOG = LoggerFactory.getLogger(ControllerTest.class);
public ControllerTest() { public ControllerTest() {
} }
@ -64,7 +67,8 @@ public class ControllerTest {
*/ */
@Test @Test
public void testSubscribe() { public void testSubscribe() {
Logger.getLogger(ControllerTest.class.getName()).info("subscribe");
LOG.info("subscribe");
final String callback = "http://localhost/doNothing"; final String callback = "http://localhost/doNothing";
final String topic = "http://feeds.feedburner.com/screaming-penguin"; final String topic = "http://feeds.feedburner.com/screaming-penguin";
@ -92,7 +96,7 @@ public class ControllerTest {
fail(); fail();
} catch (final HttpStatusCodeException e) { } catch (final HttpStatusCodeException e) {
assertEquals(400, e.getStatus()); assertEquals(400, e.getStatus());
Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); LOG.info(e.getMessage());
} }
try { try {
@ -100,7 +104,7 @@ public class ControllerTest {
fail(); fail();
} catch (final HttpStatusCodeException e) { } catch (final HttpStatusCodeException e) {
assertEquals(400, e.getStatus()); assertEquals(400, e.getStatus());
Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); LOG.info(e.getMessage());
} }
try { try {
@ -108,7 +112,7 @@ public class ControllerTest {
fail(); fail();
} catch (final HttpStatusCodeException e) { } catch (final HttpStatusCodeException e) {
assertEquals(400, e.getStatus()); assertEquals(400, e.getStatus());
Logger.getLogger(ControllerTest.class.getName()).info(e.getMessage()); LOG.info(e.getMessage());
} }
// test general exception // test general exception

View file

@ -19,10 +19,10 @@
package org.rometools.certiorem.hub.data; package org.rometools.certiorem.hub.data;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
@ -30,14 +30,14 @@ import org.junit.Test;
*/ */
public abstract class AbstractDAOTest { 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(); protected abstract HubDAO get();
@Test @Test
public void testSubscribe() { public void testSubscribe() {
final HubDAO instance = get(); final HubDAO instance = get();
LOGGER.log(Level.INFO, "{0} testSubscribe", instance.getClass().getName()); LOG.info("{} testSubscribe", instance.getClass().getName());
final Subscriber subscriber = new Subscriber(); final Subscriber subscriber = new Subscriber();
subscriber.setCallback("http://localhost:9797/noop"); subscriber.setCallback("http://localhost:9797/noop");
subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin");
@ -56,7 +56,7 @@ public abstract class AbstractDAOTest {
@Test @Test
public void testLeaseExpire() throws InterruptedException { public void testLeaseExpire() throws InterruptedException {
final HubDAO instance = get(); final HubDAO instance = get();
LOGGER.log(Level.INFO, "{0} testLeaseExpire", instance.getClass().getName()); LOG.info("{} testLeaseExpire", instance.getClass().getName());
final Subscriber subscriber = new Subscriber(); final Subscriber subscriber = new Subscriber();
subscriber.setCallback("http://localhost:9797/noop"); subscriber.setCallback("http://localhost:9797/noop");
subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin");
@ -78,7 +78,7 @@ public abstract class AbstractDAOTest {
@Test @Test
public void testUnsubscribe() throws InterruptedException { public void testUnsubscribe() throws InterruptedException {
final HubDAO instance = get(); final HubDAO instance = get();
LOGGER.log(Level.INFO, "{0} testUnsubscribe", instance.getClass().getName()); LOG.info("{} testUnsubscribe", instance.getClass().getName());
final Subscriber subscriber = new Subscriber(); final Subscriber subscriber = new Subscriber();
subscriber.setCallback("http://localhost:9797/noop"); subscriber.setCallback("http://localhost:9797/noop");
subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin"); subscriber.setTopic("http://feeds.feedburner.com/screaming-penguin");

View file

@ -0,0 +1,13 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<root level="warn">
<appender-ref ref="STDOUT" />
</root>
</configuration>