From 10729903735335a92733a34b2840668cf6a828a0 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 14 Apr 2014 19:21:54 +0200 Subject: [PATCH] Migrated logging to SLF4J --- pom.xml | 5 ++ .../atom/client/ClientAtomService.java | 10 +-- .../propono/atom/client/ClientEntry.java | 13 ++-- .../propono/atom/client/ClientMediaEntry.java | 9 ++- .../propono/atom/client/EntryIterator.java | 9 ++- .../atom/server/AtomHandlerFactory.java | 74 +++++++++++-------- .../propono/atom/server/AtomServlet.java | 38 +++++----- .../server/impl/FileBasedAtomHandler.java | 46 ++++++------ .../propono/atom/server/impl/FileStore.java | 6 +- .../blogclient/atomprotocol/AtomEntry.java | 16 +--- .../atomprotocol/AtomEntryIterator.java | 9 ++- .../propono/atom/client/AtomClientTest.java | 6 +- .../atom/server/AtomClientServerTest.java | 27 +++---- .../blogclient/SimpleBlogClientTest.java | 6 +- src/test/resources/logback-test.xml | 13 ++++ 15 files changed, 151 insertions(+), 136 deletions(-) create mode 100644 src/test/resources/logback-test.xml diff --git a/pom.xml b/pom.xml index ae8a226..abd146f 100644 --- a/pom.xml +++ b/pom.xml @@ -89,6 +89,11 @@ servlet-api provided + + ch.qos.logback + logback-classic + test + junit junit diff --git a/src/main/java/org/rometools/propono/atom/client/ClientAtomService.java b/src/main/java/org/rometools/propono/atom/client/ClientAtomService.java index 148768a..b6909d8 100644 --- a/src/main/java/org/rometools/propono/atom/client/ClientAtomService.java +++ b/src/main/java/org/rometools/propono/atom/client/ClientAtomService.java @@ -23,13 +23,13 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.input.SAXBuilder; import org.rometools.propono.atom.common.AtomService; import org.rometools.propono.utils.ProponoException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.atom.Entry; import com.sun.syndication.io.impl.Atom10Parser; @@ -42,7 +42,7 @@ import com.sun.syndication.io.impl.Atom10Parser; */ public class ClientAtomService extends AtomService { - private static final Log LOGGER = LogFactory.getLog(ClientAtomService.class); + private static final Logger LOG = LoggerFactory.getLogger(ClientAtomService.class); private String uri = null; private HttpClient httpClient = null; @@ -106,12 +106,12 @@ public class ClientAtomService extends AtomService { final SAXBuilder builder = new SAXBuilder(); final String doc = method.getResponseBodyAsString(); - LOGGER.debug(doc); + LOG.debug(doc); return builder.build(method.getResponseBodyAsStream()); } catch (final Throwable t) { final String msg = "ERROR retrieving Atom Service Document, code: " + code; - LOGGER.debug(msg, t); + LOG.debug(msg, t); throw new ProponoException(msg, t); } finally { if (method != null) { diff --git a/src/main/java/org/rometools/propono/atom/client/ClientEntry.java b/src/main/java/org/rometools/propono/atom/client/ClientEntry.java index 29653ae..2e79e25 100644 --- a/src/main/java/org/rometools/propono/atom/client/ClientEntry.java +++ b/src/main/java/org/rometools/propono/atom/client/ClientEntry.java @@ -33,10 +33,10 @@ import org.apache.commons.httpclient.methods.EntityEnclosingMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.rometools.propono.utils.ProponoException; import org.rometools.propono.utils.Utilities; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.atom.Content; import com.sun.syndication.feed.atom.Entry; @@ -51,7 +51,8 @@ import com.sun.syndication.io.impl.Atom10Parser; public class ClientEntry extends Entry { private static final long serialVersionUID = 1L; - private static final Log LOGGER = LogFactory.getLog(ClientEntry.class); + + private static final Logger LOG = LoggerFactory.getLogger(ClientEntry.class); private ClientAtomService service = null; private ClientCollection collection = null; @@ -154,7 +155,7 @@ public class ClientEntry extends Entry { } catch (final Exception e) { final String msg = "ERROR: updating entry, HTTP code: " + code; - LOGGER.debug(msg, e); + LOG.debug(msg, e); throw new ProponoException(msg, e); } finally { method.releaseConnection(); @@ -221,14 +222,14 @@ public class ClientEntry extends Entry { } catch (final Exception e) { final String msg = "ERROR: saving entry, HTTP code: " + code; - LOGGER.debug(msg, e); + LOG.debug(msg, e); throw new ProponoException(msg, e); } finally { method.releaseConnection(); } final Header locationHeader = method.getResponseHeader("Location"); if (locationHeader == null) { - LOGGER.warn("WARNING added entry, but no location header returned"); + LOG.warn("WARNING added entry, but no location header returned"); } else if (getEditURI() == null) { final List links = getOtherLinks(); final Link link = new Link(); diff --git a/src/main/java/org/rometools/propono/atom/client/ClientMediaEntry.java b/src/main/java/org/rometools/propono/atom/client/ClientMediaEntry.java index 5ce7dd0..8d3ceeb 100644 --- a/src/main/java/org/rometools/propono/atom/client/ClientMediaEntry.java +++ b/src/main/java/org/rometools/propono/atom/client/ClientMediaEntry.java @@ -33,11 +33,11 @@ import org.apache.commons.httpclient.methods.InputStreamRequestEntity; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jdom2.JDOMException; import org.rometools.propono.utils.ProponoException; import org.rometools.propono.utils.Utilities; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.atom.Content; import com.sun.syndication.feed.atom.Entry; @@ -53,7 +53,8 @@ import com.sun.syndication.io.impl.Atom10Parser; public class ClientMediaEntry extends ClientEntry { private static final long serialVersionUID = 1L; - private static final Log LOGGER = LogFactory.getLog(ClientMediaEntry.class); + + private static final Logger LOG = LoggerFactory.getLogger(ClientMediaEntry.class); private String slug = null; private byte[] bytes; @@ -279,7 +280,7 @@ public class ClientMediaEntry extends ClientEntry { } final Header locationHeader = method.getResponseHeader("Location"); if (locationHeader == null) { - LOGGER.warn("WARNING added entry, but no location header returned"); + LOG.warn("WARNING added entry, but no location header returned"); } else if (getEditURI() == null) { final List links = getOtherLinks(); final Link link = new Link(); diff --git a/src/main/java/org/rometools/propono/atom/client/EntryIterator.java b/src/main/java/org/rometools/propono/atom/client/EntryIterator.java index 0420eaa..3151629 100644 --- a/src/main/java/org/rometools/propono/atom/client/EntryIterator.java +++ b/src/main/java/org/rometools/propono/atom/client/EntryIterator.java @@ -20,11 +20,11 @@ import java.util.List; import java.util.NoSuchElementException; import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jdom2.Document; import org.jdom2.input.SAXBuilder; import org.rometools.propono.utils.ProponoException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.atom.Entry; import com.sun.syndication.feed.atom.Feed; @@ -36,7 +36,8 @@ import com.sun.syndication.io.WireFeedInput; */ public class EntryIterator implements Iterator { - private static final Log LOGGER = LogFactory.getLog(EntryIterator.class); + private static final Logger LOG = LoggerFactory.getLogger(EntryIterator.class); + private final ClientCollection collection; private Iterator members = null; @@ -60,7 +61,7 @@ public class EntryIterator implements Iterator { try { getNextEntries(); } catch (final Exception ignored) { - LOGGER.error("ERROR getting next entries", ignored); + LOG.error("An error occured while getting next entries", ignored); } } return members.hasNext(); diff --git a/src/main/java/org/rometools/propono/atom/server/AtomHandlerFactory.java b/src/main/java/org/rometools/propono/atom/server/AtomHandlerFactory.java index 27b4447..6a13e6b 100644 --- a/src/main/java/org/rometools/propono/atom/server/AtomHandlerFactory.java +++ b/src/main/java/org/rometools/propono/atom/server/AtomHandlerFactory.java @@ -1,10 +1,10 @@ -/* +/* * Copyright 2007 Sun Microsystems, Inc. - * + * * 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 @@ -18,24 +18,25 @@ package org.rometools.propono.atom.server; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * Defines a factory that enables the {@link com.sun.syndication.propono.atom.server.AtomServlet} to obtain an - * {@link com.sun.syndication.propono.atom.server.AtomHandler} that handles an Atom request. - * + * Defines a factory that enables the {@link com.sun.syndication.propono.atom.server.AtomServlet} to + * obtain an {@link com.sun.syndication.propono.atom.server.AtomHandler} that handles an Atom + * request. + * *

- * To create your own Atom protocol implementation you must sub-class this class with your own factory that is capable of creating instances of your + * To create your own Atom protocol implementation you must sub-class this class with your own + * factory that is capable of creating instances of your * {@link com.sun.syndication.propono.atom.server.AtomHandler} impementation. *

*/ public abstract class AtomHandlerFactory { - private static Log log = LogFactory.getFactory().getInstance(AtomHandlerFactory.class); + private static final Logger LOG = LoggerFactory.getLogger(AtomHandlerFactory.class); private static final String DEFAULT_PROPERTY_NAME = "org.rometools.propono.atom.server.AtomHandlerFactory"; - private static final String FALLBACK_IMPL_NAME = "org.rometools.propono.atom.server.impl.FileBasedAtomHandlerFactory"; /* @@ -45,46 +46,55 @@ public abstract class AtomHandlerFactory { } /** - * Obtain a new instance of a AtomHandlerFactory. This static method creates a new factory instance. This method uses the following ordered - * lookup procedure to determine the AtomHandlerFactory implementation class to load: + * Obtain a new instance of a AtomHandlerFactory. This static method creates a new + * factory instance. This method uses the following ordered lookup procedure to determine the + * AtomHandlerFactory implementation class to load: *
    *
  • - * Use the com.sun.syndication.propono.atom.server.AtomHandlerFactory system property.
  • + * Use the com.sun.syndication.propono.atom.server.AtomHandlerFactory system + * property. *
  • - * Use the properties file "/propono.properties" in the classpath. This configuration file is in standard java.util.Properties format and - * contains the fully qualified name of the implementation class with the key being the system property defined above. - * - * The propono.properties file is read only once by Propono and it's values are then cached for future use. If the file does not exist when the first - * attempt is made to read from it, no further attempts are made to check for its existence. It is not possible to change the value of any property in - * propono.properties after it has been read for the first time.
  • + * Use the properties file "/propono.properties" in the classpath. This configuration file is in + * standard java.util.Properties format and contains the fully qualified name of + * the implementation class with the key being the system property defined above. + * + * The propono.properties file is read only once by Propono and it's values are then cached for + * future use. If the file does not exist when the first attempt is made to read from it, no + * further attempts are made to check for its existence. It is not possible to change the value + * of any property in propono.properties after it has been read for the first time. *
  • - * If not available, to determine the classname. The Services API will look for a classname in the file: - * META-INF/services/com.sun.syndication.AtomHandlerFactory in jars available to the runtime.
  • + * If not available, to determine the classname. The Services API will look for a classname in + * the file: META-INF/services/com.sun.syndication.AtomHandlerFactory in jars + * available to the runtime. *
  • * Platform default AtomHandlerFactory instance.
  • *
- * - * Once an application has obtained a reference to a AtomHandlerFactory it can use the factory to configure and obtain parser instances. - * + * + * Once an application has obtained a reference to a AtomHandlerFactory it can use + * the factory to configure and obtain parser instances. + * * @return New instance of a AtomHandlerFactory - * - * @throws FactoryConfigurationError if the implementation is not available or cannot be instantiated. + * + * @throws FactoryConfigurationError if the implementation is not available or cannot be + * instantiated. */ public static AtomHandlerFactory newInstance() { try { return (AtomHandlerFactory) FactoryFinder.find(DEFAULT_PROPERTY_NAME, FALLBACK_IMPL_NAME); } catch (final ConfigurationError e) { - log.error("ERROR: finding factory", e); + LOG.error("An error occured while finding factory", e); throw new FactoryConfigurationError(e.getException(), e.getMessage()); } } /** - * Creates a new instance of a {@link com.sun.syndication.propono.atom.server.AtomHandler} using the currently configured parameters. - * + * Creates a new instance of a {@link com.sun.syndication.propono.atom.server.AtomHandler} using + * the currently configured parameters. + * * @return A new instance of a AtomHandler. - * - * @throws AtomConfigurationException if a AtomHandler cannot be created which satisfies the configuration requested. + * + * @throws AtomConfigurationException if a AtomHandler cannot be created which satisfies the + * configuration requested. */ public abstract AtomHandler newAtomHandler(HttpServletRequest req, HttpServletResponse res); } diff --git a/src/main/java/org/rometools/propono/atom/server/AtomServlet.java b/src/main/java/org/rometools/propono/atom/server/AtomServlet.java index 99530a7..f64b56d 100644 --- a/src/main/java/org/rometools/propono/atom/server/AtomServlet.java +++ b/src/main/java/org/rometools/propono/atom/server/AtomServlet.java @@ -32,14 +32,14 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jdom2.Document; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; import org.rometools.propono.atom.common.AtomService; import org.rometools.propono.atom.common.Categories; import org.rometools.propono.utils.Utilities; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.atom.Content; import com.sun.syndication.feed.atom.Entry; @@ -66,7 +66,7 @@ public class AtomServlet extends HttpServlet { public static final String FEED_TYPE = "atom_1.0"; private static String contextDirPath = null; - private static Log log = LogFactory.getFactory().getInstance(AtomServlet.class); + private static final Logger LOG = LoggerFactory.getLogger(AtomServlet.class); static { Atom10Parser.setResolveURIs(true); @@ -87,7 +87,7 @@ public class AtomServlet extends HttpServlet { */ @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { - log.debug("Entering"); + LOG.debug("Entering"); final AtomHandler handler = createAtomRequestHandler(req, res); final String userName = handler.getAuthenticatedUsername(); if (userName != null) { @@ -150,16 +150,16 @@ public class AtomServlet extends HttpServlet { } } catch (final AtomException ae) { res.sendError(ae.getStatus(), ae.getMessage()); - log.debug("ERROR processing GET", ae); + LOG.debug("An error occured while processing GET", ae); } catch (final Exception e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); - log.debug("ERROR processing GET", e); + LOG.debug("An error occured while processing GET", e); } } else { res.setHeader("WWW-Authenticate", "BASIC realm=\"AtomPub\""); res.sendError(HttpServletResponse.SC_UNAUTHORIZED); } - log.debug("Exiting"); + LOG.debug("Exiting"); } // ----------------------------------------------------------------------------- @@ -169,7 +169,7 @@ public class AtomServlet extends HttpServlet { */ @Override protected void doPost(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { - log.debug("Entering"); + LOG.debug("Entering"); final AtomHandler handler = createAtomRequestHandler(req, res); final String userName = handler.getAuthenticatedUsername(); if (userName != null) { @@ -256,16 +256,16 @@ public class AtomServlet extends HttpServlet { } } catch (final AtomException ae) { res.sendError(ae.getStatus(), ae.getMessage()); - log.debug("ERROR processing POST", ae); + LOG.debug("An error occured while processing POST", ae); } catch (final Exception e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); - log.debug("ERROR processing POST", e); + LOG.debug("An error occured while processing POST", e); } } else { res.setHeader("WWW-Authenticate", "BASIC realm=\"AtomPub\""); res.sendError(HttpServletResponse.SC_UNAUTHORIZED); } - log.debug("Exiting"); + LOG.debug("Exiting"); } // ----------------------------------------------------------------------------- @@ -275,7 +275,7 @@ public class AtomServlet extends HttpServlet { */ @Override protected void doPut(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { - log.debug("Entering"); + LOG.debug("Entering"); final AtomHandler handler = createAtomRequestHandler(req, res); final String userName = handler.getAuthenticatedUsername(); if (userName != null) { @@ -304,10 +304,10 @@ public class AtomServlet extends HttpServlet { } } catch (final AtomException ae) { res.sendError(ae.getStatus(), ae.getMessage()); - log.debug("ERROR processing PUT", ae); + LOG.debug("An error occured while processing PUT", ae); } catch (final Exception e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); - log.debug("ERROR processing PUT", e); + LOG.debug("An error occured while processing PUT", e); } } else { res.setHeader("WWW-Authenticate", "BASIC realm=\"AtomPub\""); @@ -315,7 +315,7 @@ public class AtomServlet extends HttpServlet { // when I do that, so sticking with setStatus() for time being. res.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } - log.debug("Exiting"); + LOG.debug("Exiting"); } // ----------------------------------------------------------------------------- @@ -324,7 +324,7 @@ public class AtomServlet extends HttpServlet { */ @Override protected void doDelete(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { - log.debug("Entering"); + LOG.debug("Entering"); final AtomHandler handler = createAtomRequestHandler(req, res); final String userName = handler.getAuthenticatedUsername(); if (userName != null) { @@ -338,10 +338,10 @@ public class AtomServlet extends HttpServlet { } } catch (final AtomException ae) { res.sendError(ae.getStatus(), ae.getMessage()); - log.debug("ERROR processing DELETE", ae); + LOG.debug("An error occured while processing DELETE", ae); } catch (final Exception e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); - log.debug("ERROR processing DELETE", e); + LOG.debug("An error occured while processing DELETE", e); } } else { res.setHeader("WWW-Authenticate", "BASIC realm=\"AtomPub\""); @@ -349,7 +349,7 @@ public class AtomServlet extends HttpServlet { // when I do that, so sticking with setStatus() for time being. res.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } - log.debug("Exiting"); + LOG.debug("Exiting"); } /** diff --git a/src/main/java/org/rometools/propono/atom/server/impl/FileBasedAtomHandler.java b/src/main/java/org/rometools/propono/atom/server/impl/FileBasedAtomHandler.java index 2f777e4..a8a0bbe 100644 --- a/src/main/java/org/rometools/propono/atom/server/impl/FileBasedAtomHandler.java +++ b/src/main/java/org/rometools/propono/atom/server/impl/FileBasedAtomHandler.java @@ -22,8 +22,6 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.rometools.propono.atom.common.AtomService; import org.rometools.propono.atom.common.Categories; import org.rometools.propono.atom.server.AtomException; @@ -31,6 +29,8 @@ import org.rometools.propono.atom.server.AtomHandler; import org.rometools.propono.atom.server.AtomMediaResource; import org.rometools.propono.atom.server.AtomRequest; import org.rometools.propono.atom.server.AtomServlet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.atom.Entry; import com.sun.syndication.feed.atom.Feed; @@ -42,7 +42,7 @@ import com.sun.syndication.feed.atom.Feed; */ public class FileBasedAtomHandler implements AtomHandler { - private static final Log LOGGER = LogFactory.getFactory().getInstance(FileBasedAtomHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(FileBasedAtomHandler.class); private String userName = null; private String atomProtocolURL = null; @@ -65,7 +65,7 @@ public class FileBasedAtomHandler implements AtomHandler { * @param uploaddir File storage upload dir. */ public FileBasedAtomHandler(final HttpServletRequest req, final String uploaddir) { - LOGGER.debug("ctor"); + LOG.debug("ctor"); userName = authenticateBASIC(req); @@ -134,12 +134,12 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public Categories getCategories(final AtomRequest areq) throws AtomException { - LOGGER.debug("getCollection"); + LOG.debug("getCollection"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); final String handle = pathInfo[0]; final String collection = pathInfo[1]; final FileBasedCollection col = service.findCollectionByHandle(handle, collection); - return (Categories) col.getCategories(true).get(0); + return col.getCategories(true).get(0); } /** @@ -152,7 +152,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public Feed getCollection(final AtomRequest areq) throws AtomException { - LOGGER.debug("getCollection"); + LOG.debug("getCollection"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); final String handle = pathInfo[0]; final String collection = pathInfo[1]; @@ -172,7 +172,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public Entry postEntry(final AtomRequest areq, final Entry entry) throws AtomException { - LOGGER.debug("postEntry"); + LOG.debug("postEntry"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); final String handle = pathInfo[0]; @@ -197,7 +197,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public Entry getEntry(final AtomRequest areq) throws AtomException { - LOGGER.debug("getEntry"); + LOG.debug("getEntry"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); final String handle = pathInfo[0]; final String collection = pathInfo[1]; @@ -223,7 +223,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public void putEntry(final AtomRequest areq, final Entry entry) throws AtomException { - LOGGER.debug("putEntry"); + LOG.debug("putEntry"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); final String handle = pathInfo[0]; final String collection = pathInfo[1]; @@ -244,7 +244,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public void deleteEntry(final AtomRequest areq) throws AtomException { - LOGGER.debug("deleteEntry"); + LOG.debug("deleteEntry"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); final String handle = pathInfo[0]; final String collection = pathInfo[1]; @@ -255,7 +255,7 @@ public class FileBasedAtomHandler implements AtomHandler { } catch (final Exception e) { final String msg = "ERROR in atom.deleteResource"; - LOGGER.error(msg, e); + LOG.error(msg, e); throw new AtomException(msg); } } @@ -274,8 +274,8 @@ public class FileBasedAtomHandler implements AtomHandler { // get incoming slug from HTTP header final String slug = areq.getHeader("Slug"); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("postMedia - title: " + entry.getTitle() + " slug:" + slug); + if (LOG.isDebugEnabled()) { + LOG.debug("postMedia - title: " + entry.getTitle() + " slug:" + slug); } try { @@ -290,7 +290,7 @@ public class FileBasedAtomHandler implements AtomHandler { } catch (final Exception e) { e.printStackTrace(); final String msg = "ERROR reading posted file"; - LOGGER.error(msg, e); + LOG.error(msg, e); throw new AtomException(msg, e); } finally { if (tempFile != null) { @@ -312,7 +312,7 @@ public class FileBasedAtomHandler implements AtomHandler { @Override public void putMedia(final AtomRequest areq) throws AtomException { - LOGGER.debug("putMedia"); + LOG.debug("putMedia"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); final String handle = pathInfo[0]; final String collection = pathInfo[1]; @@ -328,7 +328,7 @@ public class FileBasedAtomHandler implements AtomHandler { @Override public AtomMediaResource getMediaResource(final AtomRequest areq) throws AtomException { - LOGGER.debug("putMedia"); + LOG.debug("putMedia"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); final String handle = pathInfo[0]; final String collection = pathInfo[1]; @@ -359,7 +359,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public boolean isCategoriesURI(final AtomRequest areq) { - LOGGER.debug("isCategoriesDocumentURI"); + LOG.debug("isCategoriesDocumentURI"); final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); if (pathInfo.length == 3 && "categories".equals(pathInfo[2])) { return true; @@ -372,7 +372,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public boolean isCollectionURI(final AtomRequest areq) { - LOGGER.debug("isCollectionURI"); + LOG.debug("isCollectionURI"); // workspace/collection-plural // if length is 2 and points to a valid collection then YES final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); @@ -392,7 +392,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public boolean isEntryURI(final AtomRequest areq) { - LOGGER.debug("isEntryURI"); + LOG.debug("isEntryURI"); // workspace/collection-singular/fsid // if length is 3 and points to a valid collection then YES final String[] pathInfo = StringUtils.split(areq.getPathInfo(), "/"); @@ -411,7 +411,7 @@ public class FileBasedAtomHandler implements AtomHandler { */ @Override public boolean isMediaEditURI(final AtomRequest areq) { - LOGGER.debug("isMediaEditURI"); + LOG.debug("isMediaEditURI"); // workspace/collection-singular/fsid/media/fsid // if length is 4, points to a valid collection and fsid is mentioned // twice then YES @@ -433,7 +433,7 @@ public class FileBasedAtomHandler implements AtomHandler { * BASIC authentication. */ public String authenticateBASIC(final HttpServletRequest request) { - LOGGER.debug("authenticateBASIC"); + LOG.debug("authenticateBASIC"); boolean valid = false; String userID = null; String password = null; @@ -458,7 +458,7 @@ public class FileBasedAtomHandler implements AtomHandler { } } } catch (final Exception e) { - LOGGER.debug(e); + LOG.debug("An error occured while processing Basic authentication", e); } if (valid) { // For now assume userID as userName diff --git a/src/main/java/org/rometools/propono/atom/server/impl/FileStore.java b/src/main/java/org/rometools/propono/atom/server/impl/FileStore.java index 6c3589b..43112eb 100644 --- a/src/main/java/org/rometools/propono/atom/server/impl/FileStore.java +++ b/src/main/java/org/rometools/propono/atom/server/impl/FileStore.java @@ -26,15 +26,15 @@ import java.io.InputStream; import java.io.OutputStream; import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Class which helps in handling File persistence related operations. */ class FileStore { - private static final Log LOG = LogFactory.getFactory().getInstance(FileStore.class); + private static final Logger LOG = LoggerFactory.getLogger(FileStore.class); private static final FileStore fileStore = new FileStore(); diff --git a/src/main/java/org/rometools/propono/blogclient/atomprotocol/AtomEntry.java b/src/main/java/org/rometools/propono/blogclient/atomprotocol/AtomEntry.java index 0f8bca6..5e72660 100644 --- a/src/main/java/org/rometools/propono/blogclient/atomprotocol/AtomEntry.java +++ b/src/main/java/org/rometools/propono/blogclient/atomprotocol/AtomEntry.java @@ -17,11 +17,8 @@ package org.rometools.propono.blogclient.atomprotocol; import java.util.ArrayList; import java.util.Date; -import java.util.Iterator; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.rometools.propono.atom.client.ClientEntry; import org.rometools.propono.atom.common.rome.AppModule; import org.rometools.propono.atom.common.rome.AppModuleImpl; @@ -39,7 +36,6 @@ import com.sun.syndication.feed.synd.SyndPerson; * Atom protocol implementation of BlogEntry. */ public class AtomEntry extends BaseBlogEntry implements BlogEntry { - static final Log logger = LogFactory.getLog(AtomCollection.class); String editURI = null; AtomCollection collection = null; @@ -61,9 +57,6 @@ public class AtomEntry extends BaseBlogEntry implements BlogEntry { copyFromRomeEntry(entry); } - /** - * {@inheritDoc} - */ @Override public String getToken() { return editURI; @@ -91,9 +84,6 @@ public class AtomEntry extends BaseBlogEntry implements BlogEntry { return false; } - /** - * {@inheritDoc} - */ @Override public void save() throws BlogClientException { final boolean create = getToken() == null; @@ -120,9 +110,6 @@ public class AtomEntry extends BaseBlogEntry implements BlogEntry { } } - /** - * {@inheritDoc} - */ @Override public void delete() throws BlogClientException { if (getToken() == null) { @@ -216,8 +203,7 @@ public class AtomEntry extends BaseBlogEntry implements BlogEntry { } if (categories != null) { final List romeCats = new ArrayList(); - for (final Iterator iter = categories.iterator(); iter.hasNext();) { - final BlogEntry.Category cat = iter.next(); + for (final Category cat : categories) { final com.sun.syndication.feed.atom.Category romeCategory = new com.sun.syndication.feed.atom.Category(); romeCategory.setTerm(cat.getId()); romeCategory.setScheme(cat.getUrl()); diff --git a/src/main/java/org/rometools/propono/blogclient/atomprotocol/AtomEntryIterator.java b/src/main/java/org/rometools/propono/blogclient/atomprotocol/AtomEntryIterator.java index 9b7ec21..506534c 100644 --- a/src/main/java/org/rometools/propono/blogclient/atomprotocol/AtomEntryIterator.java +++ b/src/main/java/org/rometools/propono/blogclient/atomprotocol/AtomEntryIterator.java @@ -17,19 +17,20 @@ package org.rometools.propono.blogclient.atomprotocol; import java.util.Iterator; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.rometools.propono.atom.client.ClientEntry; import org.rometools.propono.atom.client.ClientMediaEntry; import org.rometools.propono.blogclient.BlogClientException; import org.rometools.propono.blogclient.BlogEntry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Atom protocol implementation of BlogClient entry iterator. */ public class AtomEntryIterator implements Iterator { - private static final Log logger = LogFactory.getLog(AtomEntryIterator.class); + private static final Logger LOG = LoggerFactory.getLogger(AtomEntryIterator.class); + private Iterator iterator = null; private AtomCollection collection = null; @@ -63,7 +64,7 @@ public class AtomEntryIterator implements Iterator { return new AtomEntry(collection, entry); } } catch (final Exception e) { - logger.error("ERROR fetching entry", e); + LOG.error("An error occured while fetching entry", e); } return null; } diff --git a/src/test/java/org/rometools/propono/atom/client/AtomClientTest.java b/src/test/java/org/rometools/propono/atom/client/AtomClientTest.java index 4d20be3..0c26f7d 100644 --- a/src/test/java/org/rometools/propono/atom/client/AtomClientTest.java +++ b/src/test/java/org/rometools/propono/atom/client/AtomClientTest.java @@ -23,12 +23,12 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.junit.Ignore; import org.rometools.propono.atom.common.Categories; import org.rometools.propono.atom.common.Collection; import org.rometools.propono.utils.ProponoException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.atom.Category; import com.sun.syndication.feed.atom.Content; @@ -39,7 +39,7 @@ import com.sun.syndication.feed.atom.Content; @Ignore public class AtomClientTest extends TestCase { - private static Log log = LogFactory.getFactory().getInstance(AtomClientTest.class); + private static Logger log = LoggerFactory.getLogger(AtomClientTest.class); private static ClientAtomService service = null; diff --git a/src/test/java/org/rometools/propono/atom/server/AtomClientServerTest.java b/src/test/java/org/rometools/propono/atom/server/AtomClientServerTest.java index cde332b..fa45eed 100644 --- a/src/test/java/org/rometools/propono/atom/server/AtomClientServerTest.java +++ b/src/test/java/org/rometools/propono/atom/server/AtomClientServerTest.java @@ -23,12 +23,7 @@ import static junit.framework.TestCase.assertTrue; import java.io.FileInputStream; import java.util.ArrayList; import java.util.List; -import java.util.logging.ConsoleHandler; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -47,6 +42,8 @@ import org.rometools.propono.atom.common.Categories; import org.rometools.propono.atom.common.Collection; import org.rometools.propono.atom.common.Workspace; import org.rometools.propono.utils.ProponoException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.atom.Category; import com.sun.syndication.feed.atom.Content; @@ -57,7 +54,7 @@ import com.sun.syndication.feed.atom.Content; */ public class AtomClientServerTest { - private static final Log log = LogFactory.getFactory().getInstance(AtomClientServerTest.class); + private static final Logger LOG = LoggerFactory.getLogger(AtomClientServerTest.class); private HttpServer server = null; public static final int TESTPORT = 8283; @@ -85,14 +82,10 @@ public class AtomClientServerTest { @Before public void setUpClass() throws Exception { - log.info("---------------------------------------------"); - log.info("Starting Jetty"); - log.info("---------------------------------------------"); - final ConsoleHandler handler = new ConsoleHandler(); - final Logger logger = Logger.getLogger("org.rometools.propono"); - logger.setLevel(Level.FINEST); - logger.addHandler(handler); + LOG.info("---------------------------------------------"); + LOG.info("Starting Jetty"); + LOG.info("---------------------------------------------"); setupServer(); final HttpContext context = createContext(); @@ -107,7 +100,7 @@ public class AtomClientServerTest { @After public void tearDownClass() throws Exception { if (server != null) { - log.info("Stoping Jetty"); + LOG.info("Stoping Jetty"); server.stop(); server.destroy(); server = null; @@ -151,11 +144,11 @@ public class AtomClientServerTest { for (final Workspace workspace : service.getWorkspaces()) { final ClientWorkspace space = (ClientWorkspace) workspace; assertNotNull(space.getTitle()); - log.debug("Workspace: " + space.getTitle()); + LOG.debug("Workspace: {}", space.getTitle()); for (final Object element : space.getCollections()) { final ClientCollection col = (ClientCollection) element; - log.debug(" Collection: " + col.getTitle() + " Accepts: " + col.getAccepts()); - log.debug(" href: " + col.getHrefResolved()); + LOG.debug(" Collection: {} Accepts: {}", col.getTitle(), col.getAccepts()); + LOG.debug(" href: {}", col.getHrefResolved()); assertNotNull(col.getTitle()); } } diff --git a/src/test/java/org/rometools/propono/blogclient/SimpleBlogClientTest.java b/src/test/java/org/rometools/propono/blogclient/SimpleBlogClientTest.java index f5584ac..b63ecf3 100644 --- a/src/test/java/org/rometools/propono/blogclient/SimpleBlogClientTest.java +++ b/src/test/java/org/rometools/propono/blogclient/SimpleBlogClientTest.java @@ -25,6 +25,8 @@ import junit.framework.TestSuite; import org.junit.Ignore; import org.rometools.propono.blogclient.Blog.Collection; import org.rometools.propono.utils.Utilities; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.io.impl.Atom10Parser; @@ -35,6 +37,8 @@ import com.sun.syndication.io.impl.Atom10Parser; @Ignore public class SimpleBlogClientTest extends TestCase { + private static final Logger LOG = LoggerFactory.getLogger(SimpleBlogClientTest.class); + private final String metaweblogEndpoint = "http://localhost:8080/roller/roller-services/xmlrpc"; // private String atomEndpoint = "http://localhost:8080/roller/roller-services/app"; private final String atomEndpoint = "http://localhost:8080/sample-atomserver/app"; @@ -68,7 +72,7 @@ public class SimpleBlogClientTest extends TestCase { int blogCount = 0; for (final Blog blog : conn.getBlogs()) { - System.out.println(blog.getName()); + LOG.debug(blog.getName()); blogCount++; } assertTrue(blogCount > 0); 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