Gotcha with Struts/WebLogic and forwarding multi-part requests

Turns out that, with Struts 1.1. at least, this can be a bad thing to do. Why? You lose the parameters on the request.
Continue reading “Gotcha with Struts/WebLogic and forwarding multi-part requests”

Creational vs access patterns, and other diversions

A little while back, I blogged about how static and singleton are not synonymous, and one of the things I mentioned in there was the concept of an “access pattern”. This is a term I’ve been kicking around for a while (in person, anyway… I think that was the first time I’d written about it), and I wanted to explore it a bit more here.
Continue reading “Creational vs access patterns, and other diversions”

Follow-up on IoC with Struts

Don Brown made a very good point about a gotcha with the IoC technique I demonstrated with Struts: it’s potentially not threadsafe.
Continue reading “Follow-up on IoC with Struts”

Roll-Your-Own IoC with Hibernate

It can be pretty useful to supply dependencies to domain objects that you’re loading via Hibernate This is where Hibernate Interceptors come into play.
Continue reading “Roll-Your-Own IoC with Hibernate”

Roll-Your-Own IoC with Struts

IoC, aka dependency injection, is the current trend. The idea is simple: create your normal class, and rather than going and fetching things you might want (like datasources, factories, and so on), get them given to you instead. This greatly facilitates things like unit testing, because you’ve got a lot less dependencies to set up.

Struts uses Actions to drive an application. This describes a way to use dependency injection techniques with Struts.
Continue reading “Roll-Your-Own IoC with Struts”

Unit testing email

The JavaMail API is a nice, simple, and effective API. But it’s got one problem: it’s a bugger to unit test. This is mostly because (unlike most other Sun Java APIs) there are no real interfaces in place, which makes it hard to mock pieces out. An excellent solution to this problem is Dumbster

Continue reading “Unit testing email”

“Pass-the-parcel” exceptions.

Hani makes a surprisingly unbilish point about wrapped exceptions Wrapping already wrapped exceptions isn’t the best idea in the world.

This technique reminds me of the children’s game of “Pass the Parcel”, where you put multiple layers of wrapping on a gift, and the children never know when they will reach the last one.

I’m as guilty of this as the next person, but I think in future I will modify the constructors of my wrapping exceptions so that if a cause already exists, it uses that as the cause, not the one supplied…

(FWIW, I’m not against wrapping exceptions; what is an ObjectNotFound at one layer is a ConfigurationException at another, and should be reflected as such).

This may, of course, just be a stupid idea, but it’s worth exploring.

Unit testing privates, and other unsavoury topics

Brian Duff gives a good example of a technique to get around visibility problems when unit testing. Believe it or not, this can be a good idea (and this is a strong TDD advocate saying this).

Continue reading “Unit testing privates, and other unsavoury topics”

Beware of unlocalised JREs

This is a cautionary tale of US-only JREs and non-US countries, such as The Lucky Country I call home.
Continue reading “Beware of unlocalised JREs”