Thursday, 23 July 2009

Dummy SMTP Server

Papercut is, in my opinion, one of the best tools for a dummy SMTP server. The interface is nice, clean, and best of all, simple and easy to use. Installation took me a few minutes, and all you need to do next is point your application's smtp server to localhost and you can start testing.

Thursday, 14 May 2009

Null Check for Java Bean Properties

I was trying to find out an easy way to check nulls in my Java Bean. There is this filter screen where I need to throw an Exception if all the properties are blank. This is required so that the database don't get hit with "Search All" query. I used BeanUtils from Apache Commons to get all the properties and StringUtils to check if the property is blank. Here is a snippet of the code that I used:


.
.
.
Map<String, String> map = BeanUtils.describe(searchCriteria);
boolean allBlank = true;
if (map != null) {
for (String key : map.keySet()) {
if ("class".equalsIgnoreCase(key) || "metaClass".equalsIgnoreCase(key))
continue;
if (StringUtils.isNotBlank(map.get(key))) {
LOG.info("key " + key + " is not null");
allBlank = false;
break;
}
}
}
if (allBlank) {
throw new IllegalArgumentException("searchCriteria cannot be blank"));
}
.
.
.

Wednesday, 26 November 2008

java.lang.ClassCastException: oracle.sql.BLOB

This is by far the most annoying problem I've ever had. What ClassCastException??? This is my code:

oracle.sql.BLOB blob = (oracle.sql.BLOB) resultSet.getObject("fileBlob");

It turned out that there are 2 Oracle JDBC jars in my Tomcat directory (common/lib and WEB-INF/lib), so I removed the one from WEB-INF, restarted the application, and it all worked fine.

Tuesday, 9 September 2008

Custom Authentication Using Spring Security

Customising Spring Security could be a challenge as there seems to be lack of practical examples. Recently I tried to customise my login page when authentication fails. I found this blog really useful: Spring Security - Using custom Authentication Processing Filter

Monday, 14 July 2008

JSCalendar Problem - Stack overflow at line: 1797

I posted a blog regarding this JSCalendar earlier in the year, and it has been working great.. until recently when I got "Stack overflow at line: 1797" on my IE. This is caused by duplication in the javascript declaration, causing the calendar script to be loaded a couple of times. I cleaned up my HTML code and made sure that it was only declared once, and the problem went away.

Spring Security (Acegi) and Sitemesh

Sitemesh is a great tool to decorate your java-based web page. I am currently using it to decorate my web application so that I can have the menu on the left panel, a header, and a footer withouth worrying about including it in all my jsp pages. Spring Security (formerly known as Acegi Security System) is another great tool that I also use together with Sitemesh for authentication and authorisation. My Spring Security "authorize" tag recently did not work properly, and the problem was because in my web.xml, I declared Sitemesh BEFORE Spring Security. Spring Security would clean up before Sitemesh is able to decorate the pages, causing Spring Security tags to stop working. The solution is to declare Sitemesh after Spring Security.

Thursday, 10 April 2008

Spring JMS

Using Spring JMS to send and receive messages to Queues is not difficult nowadays. I followed this tutorial in order to communicate to IBM MQ Series with no problem. It is simple, straightforward, and you can set up your applications in a very short amount of time.

Search

Google