pwad on GitHub

This week-end I moved pwad to GitHub.

I already blogged about pwad, a utility software I wrote to download pictures from picasa web. I was hosting it on my server but since I’m using git as SCM I decided to move it to GitHub (well, the main reason is that I wanted to play with GitHub :-) ).

Anyway, now pwad’s official website is http://github.com/ldesgrange/pwad (and current version is 0.4).

pwad

I’m not very fond of services like picasa, but some of my friends use that to share pictures with me. Unfortunately, retrieving pictures from a friend’s picasa web album is a pain. I have tried to find how to do that and usually the tips I found were not so great and softwares were outdated/not maintained anymore.

Being a software developer, I decided to write a small software to do that, so I created “pwad” (aka Picasa Web Album Downloader). Yes, I know, I’m bad at finding names.

You just have to copy the link provided in the picasa email you receive when a friend shares an album with you, paste it in pwad and click on the download button.

It’s open source (Apache License 2.0), it’s written in Java, so you need Java (at least version 6) installed on your computer. I haven’t packaged the application with an installer yet, double-clicking on it should be enough to launch it, but first you have to download it from: http://pwad.desgrange.net/wiki/download (current version is 0.3).

If you find this application useful, bugged, etc. you can leave feedback and comments on this post.

UPDATE: pwad has been moved to GitHub http://github.com/ldesgrange/pwad.

Les Cast Codeurs

Si vous êtes développeur Java, vous connaissez certainement le podcast The Java Posse, 4 experts (Tor Norbye, Carl Quinn, Dick Wall et Joe Nuxoll) du monde Java (au sens large) parlant des news concernant Java, la JVM et tout ce qui touche de près ou de loin (voire de très loin) à ça, sur un ton en général très décontracté et humoristique.

Il y a un peu plus d’un an maintenant, 4 français (Emmanuel Bernard, Guillaume Laforge, Antonio Goncalves et Vincent Massol) ont décidé de faire quelque chose de similaire, le podcast Les Cast Codeurs, mais dans la langue de Molière. Je dois avouer qu’au début je ne voyais pas trop l’intérêt, étant donné que nous travaillons dans un secteur très anglophone, ça me semblait assez redondant avec The Java Posse, à part peut-être pour les quelques irréductibles gaulois qui ne comprennent toujours rien à l’anglais (et il semblerait qu’il y en ait encore pas mal en France ;-) ).

Récemment je me suis décidé à en écouter quelques épisodes, et c’est plutôt pas mal, même si dans l’idée c’est assez proche du Java Posse, le contenu et l’approche sont assez différents pour que ce ne soit pas complètement redondant. Sans compter que l’actualité française et européenne du domaine (si si, il y en a) est un peu plus abordée. C’est entre autre par Les Cast Codeurs que j’ai découvert le BruJUG.

Continuez comme ça les gars, ça me fait quelque chose de plus à écouter dans le métro ;-) .

BruJUG

Last wednesday (May 26th) was the first BruJUG session, and I was there ;-) .

So, what’s BruJUG? It’s Brussels’ Java User Group, so if you are a Java developer living/working in Brussels, you might be interested to attend BruJUG sessions in order to learn some stuff, talk with other developers, exchange some ideas, have a good beer…

When I was in Paris, I was going quite often to the ParisJUG, which was the first JUG in France. BruJUG just started but it’s not the first one in Belgium, there is also BeJUG which is moving from cities to cities in Belgium.

What happens in Wednesday’s session? First of all it was in Google‘s office, aka GooglePlex,  which is quite a nice one and there was two presentations, a non-technical one on content strategy and a technical one on ehcache (and a bit of terracotta of course). Both were very interesting, you can read the session post on BruJUG website or on BruJUG’s wiki (there are some pictures too!).

Logging in Weblogic console with Log4J

If you have developed a JEE web application using Log4J for logging and have it deployed on a WebLogic application server, you may wonder how to display the logs in WebLogic console:

Preparation

You simply need to create and add a Log4J appender. This appender will redirect Log4J events to WebLogic by using the NonCatalogLogger class. You can found this class in wls-api.jar or wlclient.jar (depending on your WebLogic version) from your WebLogic’s lib directory. For instance if you are using maven, you need to add one the following dependencies in your maven’s pom.xml (enter the version corresponding to your WebLogic installation):

<dependency>
    <groupId>weblogic</groupId>
    <artifactId>wlclient</artifactId>
    <version>10.3</version>
    <scope>provided</scope>
</dependency>

or

<dependency>
    <groupId>weblogic</groupId>
    <artifactId>wls-api</artifactId>
    <version>10.0</version>
    <scope>provided</scope>
</dependency>

Obviously WebLogic JARs are not in official Maven repositories (due to license/distribution restrictions, proprietary softwares always here to hassle you). So type the following command in your shell to add the API in your local maven repository:

mvn install:install-file -DgroupId=weblogic -DartifactId=wlclient -Dversion=10.3 -Dpackaging=jar -Dfile=wlclient.jar

or

mvn install:install-file -DgroupId=weblogic -DartifactId=wls-api -Dversion=10.0 -Dpackaging=jar -Dfile=wls-api.jar
Creating the appender

The appender needs to implement Log4J’s Appender interface, but it’s more convenient to extends AppenderSkeleton. WebLogic’s NonCatalogLogger class has some “debug”, “info”… methods like Log4J so the appender is just going to map one to the other.

Since you may deploy your application on something else than WebLogic (for instance I usually use Tomcat and/or Jetty for development/testing) you don’t want have it crashing your application because WebLogic classes are not here. The appender can check if the class is in the classpath (using Class.forName()) and do nothing if the NonCatalogLogger is not here.

In WebLogic’s console, there is a “Subsystem” column, we can set it in the appender to display the application name.

package sample.project;
 
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
 
import weblogic.logging.NonCatalogLogger;
 
public class WeblogicAppender extends AppenderSkeleton {
    private static final String SUBSYSTEM = "SampleProject";
    private NonCatalogLogger logger;
 
    public WeblogicAppender() {
        try {
            Class.forName("weblogic.logging.NonCatalogLogger");
            logger = new NonCatalogLogger(SUBSYSTEM);
        } catch (ClassNotFoundException e) {
            // Not running on WebLogic server.
        }
    }
 
    @Override
    protected void append(LoggingEvent event) {
        if (logger == null) {
            return;
        }
        if (Level.TRACE.equals(event.getLevel())) {
            logger.trace(getMessage(event), getThrowable(event));
        } else if (Level.DEBUG.equals(event.getLevel())) {
            logger.debug(getMessage(event), getThrowable(event));
        } else if (Level.INFO.equals(event.getLevel())) {
            logger.info(getMessage(event), getThrowable(event));
        } else if (Level.WARN.equals(event.getLevel())) {
            logger.warning(getMessage(event), getThrowable(event));
        } else if (Level.ERROR.equals(event.getLevel())) {
            logger.error(getMessage(event), getThrowable(event));
        } else if (Level.FATAL.equals(event.getLevel())) {
            logger.critical(getMessage(event), getThrowable(event));
        }
    }
 
    @Override
    public void close() {
        // Nothing to do here.
    }
 
    @Override
    public boolean requiresLayout() {
        return false;
    }
 
    private String getMessage(LoggingEvent event) {
        return String.valueOf(event.getMessage());
    }
 
    private Throwable getThrowable(LoggingEvent event) {
        if (event.getThrowableInformation() != null) {
            return event.getThrowableInformation().getThrowable();
        } else {
            return null;
        }
    }
}
Log4J configuration

In your log4j.xml just define a new appender using the above class and add it to the root logger. Here is an example:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
	<appender name="console" class="org.apache.log4j.ConsoleAppender">
		<param name="Target" value="System.out" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%-5p %c{1} - %m%n" />
		</layout>
	</appender>
 
	<appender name="weblogic" class="sample.project.WeblogicAppender" />
 
	<root>
		<priority value="debug" />
		<appender-ref ref="console" />
		<appender-ref ref="weblogic" />
	</root>
</log4j:configuration>
Check

I have created a simple servlet logging some messages in debug, info and warn levels, let’s call it and see what happens:

It works! (OK, I was not going to write all that just to show something that does not work ;-) ). But be careful, as you can see, the debug message is not displayed even after setting Log4J’s level to debug. My WebLogic console is configured to display higher level messages. Don’t forget to check that it’s logging at the right level for you.

Notes

All source code in this post is in public domain, do what ever you want with it. I did it quickly so it may not work as you want, you are strongly advised to adapt it to your needs. I’m not mastering WebLogic at all (in fact I don’t really like that application server) so it may not be the best way to do it (and usually you should not need to do such things), and it is not at all certified in any way to be “production ready”.

Java Black Belt

Java Black Belt is a community website aiming at “building better developers“. Given the name, it’s targeting mainly Java developers but some exams cover Ruby, .NET C#

Every user has a belt like in karate, the color (from white to black) represents user’s knowledge of Java, common frameworks, tools… To get next belt you need to pass some specific exams and have a certain amount of knowledge points.

You get knowledge points by passing exams. An exam is usually a list of multiple choices questions, you need a certain amount of good answers to pass the test (around 80 % successful answers). If you fail an exam you need to wait some time before trying it again (around 15 days).

To get an exam you need some contribution points (except if you decide to follow the “Belt Track”, doing the exams in a predefined order). Contribution points are obtained when writing a question, reporting problems on a question, etc. So all the questions are created by the community, voted by the users (to have them accepted or rejected).

Since I mostly didn’t write anything in Java for a year and a half, I need to train myself a bit before taking an exam (I don’t really want to be forced to wait 15 days before trying an exam again).

So basically the website (until the black belt) is just checking your knowledge of Java and does not check if you are really able to write good code. In order to check that, the exam to get the black belt IS a programming task, but it’s not yet released (so nobody as a black belt yet).

One drawback I see is that several questions are useless. Since there is no point using Java without a proper IDE (as one of my colleagues says: “The power of Java is IntelliJ.”), questions about knowing by heart all the details of Java APIs, questions like “Does the following program compile?” are meaningless.

During my (short) career, I was interviewed several times and I interviewed several people. Quite often there are some technical questions to be sure that the interviewee knows a bit of Java, so sometimes I was asking questions like the ones found on Java Black Belt. Seeing the belt somebody obtained on this website will reduce the number of technical questions I have to ask, Java Black Belt already did it.

But in fact, if I need somebody in the team I’m working in, Java Black Belt is not enough. Of course it’s a hint about is knowledge, but it does not tell me how the guy works. But at least I have more time in the interview to ask those questions.

Posted in Uncategorized. Tags: , . No Comments »