Unknown winmail.dat attachment in email Tuesday, Jul 29 2008 

From my colleague I received an email but with unknown type : winmail.dat
He should send me office document.
I asked him to sent it again, he forwarded the email again but I still received winmail.dat in attachment.

After googling about this I found out that winmail.dat is generated by Outlook (I using thunderbird).
From About.com :

It’s Outlook’s fault, in a way. Or the recipient’s email client’s. If Outlook sends a message using the RTF format (which is not very common outside Outlook) for bold text and other text enhancements, it includes the formatting commands in the winmail.dat file. Receiving email clients that do not understand the code therein display it as a stale attachment. To make matters worse, Outlook may also pack other, regular file attachments in the winmail.dat file.

Fortunately, you can get rid of winmail.dat altogether by making sure Outlook does not even try to send mail using RTF.

And there’s also a way to disable this feature on Outlook. You can open it for more detail.
I would focus on how non-Outlook user can handle this format.
I know I can not ask all Outlook user who sent me attachment to turn off this feature.

So I search a program to open this content type “application/ms-tnef”.
I encounter this good console program : WMdecode
You just need to extract this. When running the program it’ll search winmail.dat in current folder and extract it.
The program working great although it just console application, no GUI.

Other tool I search is add on for Thunderbird.
I found : LookOut
This add on will automatically decode the winmail.dat
Also working great but it won’t decode winmail.dat in emails that you received before installing the add-on.
So I think it’ll only decode winmail.dat on new email received.

Cheers ๐Ÿ™‚

Java Application – Make sure only single/one instance running – with File Lock and ShutdownHook Monday, Jul 21 2008 

Often we want to make sure that only 1 instance our application running.
Because something terrible could happen when more than 1 instance running (for example the whole server would exploded and that would make you fired ๐Ÿ˜‰ )

Nevertheless what the reason, one of the way to make this happen is by creating a lock file as a sign that an instance is currently running.
So you application will have this flow:

  1. Check if the lock file exists.
  2. Try to delete the lock file to check if there’s really a running process lock the file.
  3. Get the file lock.
  4. If failed to get the lock file, show error that there’s already an instance running –> the end
  5. If successfully get the lock then go on with your application want to do.
  6. When application ended/closed release the lock and delete the file lock.

package test.jimmy.filelock;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

public class MyApp {

    private static File f;
    private static FileChannel channel;
    private static FileLock lock;

    public static void main(String[] args) {
        try {
            f = new File("RingOnRequest.lock");
            // Check if the lock exist
            if (f.exists()) {
                // if exist try to delete it
            // Try to get the lock
            channel = new RandomAccessFile(f, "rw").getChannel();
            lock = channel.tryLock();
            if(lock == null)
                // File is lock by other application
                throw new RuntimeException("Only 1 instance of MyApp can run.");
            // Add shutdown hook to release lock when application shutdown
            ShutdownHook shutdownHook = new ShutdownHook();

            //Your application tasks here..
            try {
            } catch (InterruptedException e) {

        catch(IOException e)
            throw new RuntimeException("Could not start process.", e);


    public static void unlockFile() {
        // release and delete file lock
        try {
            if(lock != null) {
        } catch(IOException e) {

    static class ShutdownHook extends Thread {

        public void run() {


Technorati Tags: , , , , , ,

Microsoft + Yahoo = ? Tuesday, Feb 5 2008 

Microsoft planning to buy Yahoo for $44.6 billion. Until now Yahoo hasn’t give final answer it.
I’m wondering why do Microsoft want to buy Yahoo, is it for fighting Google?
Or Microsoft just want to kill one of hisย  rival.

Let’s see
IM : Microsoft has Windows Live Messenger, Yahoo has Yahoo Messenger.
Search Engine : Microsoft has Live Search, Yahoo has it’s own search engine.
Email : Microsoft has Windows Live Hotmail, Yahoo has Yahoo Mail.

Let’s wait for Yahoo’s final answer.
And how will Google respond about this ๐Ÿ™‚

NetBeans 6 T-shirt Friday, Dec 28 2007 

NetBeans 6 T-shirtย (front)NetBeans 6 T-shirtย (back)

After waiting for 16 days finally the NetBeans T-shirt arrived.
They sent me this t-shirt because my participation in NetBeans Community Docs program although I only contribute 1 article (this) :p

Thanks to Sun and James Branam (NetBeans Community Docs Manager) for this cool t-shirt ๐Ÿ˜‰
It’s a great pleasure to be part of the NetBeans community & I would love to contribute more.

Using mock object with jmock 2 Wednesday, Dec 26 2007 

Okay, finally you decide it’s time to create a unit testing for your project (after a long ad hoc programming life :p).
When you create a sample unit testing, it’s all seem so simple.. you fascinate by the junit easiness, how it can do reflection and make it simple.

When you want to create a real unit testing for your project, you realize that a ‘real’ method is not like just adding 2 int argument and return a result. It’s more complex and using interface as parameter is common…
Now a thought cross your mind “do I have to create all stupid classes to implement all the interface I need?”, you starting to think that creating unit testing is really waste of time & you don’t want to do it anymore :p

It’s time mock object framework come to rescue… before you fall to the darkness of untested code ๐Ÿ™‚
There’re several mock object framework like jMock, easymock, etc

Here’s an example creatin HttpMethod mock-object with jMock 2 & JUnit 3

public class sampleJMockTest extends MockObjectTestCase {
  public void testCreateHTTPMethod() {
    final HttpMethod httpMethod = mock(HttpMethod.class);
    checking(new Expectations() {
      will(returnValue("sample response"));
    SomeObject someObject = new SomeObject();

This sample will create an instance of HttpMethod (which is an interface) and when this mock object’s ‘getResponseBodyAsString’ method called it’ll return “sample response”.
So now we can easily create all interface implementation we need.Of course there’re more in jMock than just this simple feature, check it more at jMock Cookbook

Java – Adding new Classpath at Runtime Wednesday, Dec 19 2007 

There are cases where we need to add classpath at runtime. For example adding jar to classpath, but depends on configuration or some logic at runtime.

The class who responsible for handling classpath list is URLClassloader.
You can get current system URLClassLoader with:
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();

If you check javadoc about this class you’ll see:

protected void addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources.

So you’ll just need to call the addUrl method to add new path/jar file.
But wait a minute, the method is protected… ๐Ÿ˜ฆ do I need to create a subclass or put the caller class on same package?
Creating a subclass is one way to do it, but there’s simpler way (I’ll create article about creating URLClassLoader subclass next time :p)

Here come the savior : Reflection
By using reflection we can break OOP concept about encapsulating method. It’s feel good to break the rules right (warning : use this at your own risk, you know you’re breaking the OO rule. So I won’t responsible if your computer explode or you’ll fighting with OO fans because of this)

Here a sample how to called it with reflection:

public static void addPath(String s) throws Exception {
  File f = new File(s);
  URL u = f.toURL();
  URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
  Class urlClass = URLClassLoader.class;
  Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});
  method.invoke(urlClassLoader, new Object[]{u});

Happy reflecting.. ๐Ÿ™‚

NetBeans 6 Bug – ConfigurationException Class in Apache Common Configuration is not Throwable? Wednesday, Dec 12 2007 

When I using Netbeans 6 (final released) and using Apache Common Configuration library, I encounter this bug.
Here’s how I found the bug :

  • Create a java application project
  • Add the library, I create a library name ‘Apache_Common_Configuration’ and add commons-configuration-1.5.jar to that library
  • Then I wrote the code

public static void main(String[] args) {
try {
INIConfiguration ini = new INIConfiguration("sample.ini");
} catch (ConfigurationException ex) {

  • But the editor showing error on ‘ConfigurationException ex’ saying that ConfigurationException is not subclass of Throwable Class (I’ve upload the screenshot)

NetBeans 6 Bug - ConfigurationException Class

  • When I try to build it’s showing different error “class file for org.apache.commons.lang.exception.NestableException not found”
  • It’s look like Apache Common Configuration is using Apache Common Lang library (I also look to the source-code ‘ConfigurationException extends NestableException’). Error when compile showing me more help than error in editor.
  • So I create a library name ‘Apache_Common_Lang’ and add commons-lang-2.3.jar to that library
  • After add the library the editor still showing the same error : “ConfigurationException is not subclass of Throwable Class”
  • But when I run build, it run successful . No error at all. (Now I confused)
  • It’s look like there’s a bug in the Editor. And that red line & error icon in project window really bugging me, although I know it’s the editor bug not my code error.
  • So to make this ‘red-line’ disappeared, I combined commons-configuration-1.5.jar & commons-lang-2.3.jar into 1 jar file. And set a library to this jar (instead using 2 library or 2 jar file).
  • After this combined the editor not showing the error again.

Anyone having this problem too?

You can vote for this bug on : http://www.netbeans.org/issues/show_bug.cgi?id=124241

NetBeans IDE 6 final released Tuesday, Dec 4 2007 

Finally Netbeans 6 final released ๐Ÿ™‚
Download it at NetBeans 6 Download

Can’t wait to download and install it.
I hope they’ve already fixed bugs in previous release (RC2).

Netbeans 6 – Configure which editor (representative class) for new type extension Tuesday, Nov 20 2007 

A friend who is using Netbeans 6 ask how to configure Netbeans so it’ll open his start.tml as an html file not just as ordinary text file (So the editor will full with color I assume, not just black text :p)

I didn’t asked him why the hell he using .tml not just .html ๐Ÿ™‚ but I tell him that he can configure Netbeans 6 with:

  1. Choose Tools – Options
  2. Click on ‘Advanced Options’ button (on bottom left)
  3. Open the tree : ‘IDE Configuration’ – ‘System’ – ‘Object Types’
  4. Find ‘HTML Objects’
  5. Add extension tml to ‘Extension and MIME Types’ property
  6. Close
  7. Now evertime you double click .tml file it’ll call HTML objects’ representative class ๐Ÿ™‚

*Check this article on NetBeans Community Doc ^^

Simple Log4J implementation Thursday, Nov 15 2007 

Why do we need a library for logger? doesn’t System.out.println help us enough?
When you try log4j you wouldn’t use System.out.println ever again… (Ok.. you will still used it.. occasionally :p)

What do you need? of course you need to download log4j first ๐Ÿ˜‰ , get it at log4j download page
And open your favorite Java IDE.

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
* @author jimmy
public class SampleLog4j {

private final static Logger LOGGER = Logger.getLogger(SampleLog4j.class);

public static void main(String[] args) {
LOGGER.trace(“Level trace”);
LOGGER.debug(“Level debug”);
LOGGER.info(“Level info”);
LOGGER.warn(“Level warn”);
LOGGER.fatal(“Level fatal”);


This program will read file log4j.properties in the folder for log4j configuration.
Example of log4j.properties:

### file appender
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} — %p %C(%M):%L — %m%n
### console appender
log4j.appender.console.layout.ConversionPattern=%d{ISO8601} — %p %C(%M):%L — %m%nlog4j.rootLogger=debug, console
# uncomment the line below if you want log output to file
# log4j.rootLogger=debug, file

And it’ll produce output:

2007-11-15 18:19:09,812 — DEBUG testing.SampleLog4j(main):26 — Level debug
2007-11-15 18:19:09,828 — INFO testing.SampleLog4j(main):27 — Level info
2007-11-15 18:19:09,828 — WARN testing.SampleLog4j(main):28 — Level warn
2007-11-15 18:19:09,828 — FATAL testing.SampleLog4j(main):29 — Level fatal

Why the log “Level trace” doesn’t logged, because we set the log level only to debug.
You should learn the configuration. There are 2 appender, 1 will log to console and other will log to a file.

Now why shouldn’t I used standard System.out.println?

  • You can’t set the level of log with println only
  • You will end up delete/comment the log using println
  • It won’t be that easy to create log to file with different filename daily (daily-rolling)
  • I wonder how your println can print class name, line number easily ๐Ÿ™‚
  • … you can add more after you try it ๐Ÿ˜‰

Next Page »