J2ME Recipe Browser

As an exercise, I wrote up a J2ME client for Karensrecipes.com. As I mentioned a couple days ago, it sends HTTP requests to a servlet to receive a list of recipes as XML, and then (given a specific recipe), sends another HTTP request for the recipe details (again returned as XML). It works great on the emulator, not so good on the 3650. It looks like the phone can’t establish a connection to my server, because as I tail the Apache logs, I don’t see the request come through (I do see the request when using the emulator). I’m guessing it has something to do with the default connection for Java apps on the phone. Anyone have any experience with making wireless connections on the 3650 through J2ME?

If you’re interested, you can download the application and the source:

RecipeViewer source


I mentioned a couple days ago that my current project is based on a C# and ASP.NET. I don’t have access to Visual Studio (should I try to get it? is it worth it?) so I’ve been using the Improv C# plugin with Eclipse. The combination works alright, but there are a couple things that need improvement. First, when compiling an assembly in C#, you have to specify each module that it references per class, there isn’t a way to to say that MyProject.dll should be included in the classpath for the entire C# project. Second, there’s no way to say that you want all the compiled assemblies to be placed in ../classes/ instead of ../build (ie: you can’t specify an output folder). But that’s where NAnt comes to the rescue. I downloaded NAnt today and was able to get a build script running within a couple minutes that accomplishes the two things I needed above.

I do have a question for those of you who have done .NET programming before. In Java, you compile .java files to .class files. Using C#, you compile a .cs file to a .dll (or .exe, etc..) which is called an assembly. Then in Java you’d usually package up your class files into a jar file. After using NAnt today, I see that you can compile a bunch of .cs files into a single dll, also called an assembly, which you can then use just like a jar file. Do I have that right? Are there different ways of doing this?

Parsing XML in J2ME

Spent a couple hours tonight working on a MIDP client for the recipe site. Initially I tried serving up pipe delimited plain text (ie: response.setContentType(“text/plain”);) and then parsing that using the J2ME classes, but then I saw the light that is XML, in this case kXML. kXML “… provides an XML pull parser and writer suitable for all Java platforms including the Java 2 Micro Edition (CLDC/MIDP/CDC). Because of its small footprint size, it is especially suited for Applets or Java appications running on mobile devices like Palm Pilots or MIDP enabled cell phones.” I’ll post some code after I’m done with it, this article is a great introduction.

Alternative Uses for RSS

At work we use a homemade bug tracking system I built a couple years ago during a slow month. Although the code isn’t exactly stellar, it works pretty well and most importantly, people actually use it(!). My biggest beef with it (and all our internal web-based applications) is that every time I want to use the application, you have to login. It might be ok if I only used it once a day, but it’s something that I want to see immediately. Multiple times throughout the day someone will say “hey, what’s the status on issue #14044?” so after falling in love with SharpReader this week, I created an RSS feed for each project. Now I can keep SharpReader open in the system tray, it’ll automatically refresh the data every n minutes, and I don’t have to login each time to view the bugs.

I mention it because I think it’s one of those examples of an application being used for something that wasn’t originally intended by their creators. Luke Hutteman, who created SharpReader, probably never imagined that his 3 paned aggregator would be used to view tickets in a bug tracking system. What other ways are you using RSS?

Logging in C#

I wrote up a very simple C# class that provides logging for C# applications since the C# Logger on sourceforge is still in alpha (and doesn’t appear to be active) and the .NET framework doesn’t seem to provide normal text file logging outside of the EventLog (correct me if I’m wrong):

using System;
using System.IO;
namespace com.ignitionlabs.logging {  
  public class Logger {
    private static int _ALL = 100;
    private static int _INFO = 75;
    private static int _ERROR = 50;
    private static int _OFF = 0;
    private static String logDirectory = System.Configuration.ConfigurationSettings.AppSettings["logging.directory"].ToString();
    public static int ALL {
      get { return _ALL; }
    public static int ERROR {
      get { return _ERROR; }
    public static int INFO {
      get { return _INFO; }
    public static int OFF {
      get { return _OFF; }
    public static void append(String message, int level) {
      int logLevel = _OFF;
      String strLogLevel = System.Configuration.ConfigurationSettings.AppSettings["logging.level"].ToString();
      switch(strLogLevel) {
        case "ALL":
          logLevel = _ALL;
        case "ERROR":
          logLevel = _ERROR;
        case "INFO":
          logLevel = _INFO;
          logLevel = _OFF;
      if (logLevel >= level) {
        DateTime dt = DateTime.Now;
        String filePath = logDirectory + dt.ToString("yyyyMMdd") + ".log";
        if (!File.Exists(filePath)) {
          FileStream fs = File.Create(filePath);
        try {
          StreamWriter sw = File.AppendText(filePath);
          sw.WriteLine(dt.ToString("hh:mm:ss") + "|" + message);
        } catch (Exception e) {

After compiling, you’ll need to add 2 elements to your <appsettings> in web.config:

<add key=”logDirectory” value=”c:\myapp\logs\” />
<add key=”logLevel” value=”ALL|INFO|ERROR|OFF” />

and then you can use the class like this:

Logger.append(“your application message…”, Logger.ALL);

As always, I’m interested in any design flaws or critiques.

Test versus Type

Oliver Steele, who is the Chief Software Architect at Laszlo Systems, wrote a short essay about the cost and time difference between “Explicity-Typed Languages” and “Implicitly-Typed Languages”.

A couple people pointed out in the comments that you gain back some of the time lost by developing types & tests in an Explicitly Typed Language when refactoring because your IDE can help you where it can’t in an Implicitly Typed Language. In my humble opinion, this (refactoring) is an example of one of the reasons why J2EE developers don’t look very long at ColdFusion. Moving to ColdFusion requires them to think procedurally rather than in objects (although CFC’s now provide pseudo OO behavior). Testing becomes stickier (although DRK 3 includes the CFunit component framework for testing ColdFusion components). Of course, Oliver’s article is also a great reason TO use a tool like ColdFusion. Instead of spending time writing recursively types,tests, & code, you can code/test/code/test.