Currently, I am moving this blog onto the latest version of Sling. Part of this effort is the migration of the comment spam checker into an OSGi bundle (mostly, that means wrangling with Maven). Here's two little bits of information I encountered along the way. Maybe they can be useful to someone.
The actual backend services that are used for comment verification are Akismet and Typepad's Anti Spam. I took David Czarnecki's Akismet-Java library that wraps the respectice REST APIs of these services (both service providers actually use the same API).
The trouble with David's code is that it uses commons-httpclient which depends on commons-logging. That clashes with Sling's use of log4j (note to the Java community: how could we get into this logging mess?). I found the solution for this annoying problem in Sling's parent pom.xml. Here's the relevant bit:
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
The second thing I would like to point out: it is quite simple to make OSGi bundles configurable through the web console (at http://localhost:7402/system/console).
This is useful e.g. for configuring the API key of the above-mentioned service providers. In order to expose a property in the console use the annotation @scr.property:
/** @scr.property */ public static final String PARAM_API_KEY = "akismet.service.api.key";
Other types like integer or boolean can also be used:
/** @scr.property value="0" type="Integer" options 0="Akismet" 1="Typepad" */ public static final String PARAM_SERVICE_PROVIDER = "akismet.service.provider";
The values are read in the service's setup method:
Object key = configuration.get(PARAM_API_KEY);
if (key != null) {
this.apiKey = key.toString();
}
As usual, the full sources are attached.


> we get into this logging mess?).
Probably we should write our own logging framework to resolve the mess... ;-)
Internally the Sling log bundle uses SLF4J, that is JCL, Log4J and OSGi LogService are implemented on top of SLF4J. In addition, we have our own SLF4J SPI implementation.
So using httpclient is really no big deal in Sling because the required JCL library is already present.