Archive for February 2008

Spring PropertyPlaceholderConfigurer with Velocity

2008/02/25

Part of the configuration magic is (one of several) Spring post-processors, that allows load the property file or files and refer to the values in these files inside XML configuration files. The rationale behind these is that property files are much easier to edit that possibly huge XML config file and using property values prevents repeating same value over and over again. With this approach, the following configuration:

 	
		
		
	

can be written as

 	
		
			
				WEB-INF/mail.properties
				WEB-INF/jdbc.properties
			
		
	


 	
		
		
	

 

and (in jdbc.properties)

jdbc.username=some_user
jdbc.password=secret

If you are using in the same project Velocity and want to utilize the VTL macros inside the configured values, the approach above will not work, because PropertyPlaceholderConfigurer will try to replace ALL macros in form ${something} with a value from property file – and throw exception if not found.The solution is easy: you need to switch the prefix of the PropertyPlaceholderConfigurer to something else than the default ${ and avoid conflict wih Velocity. The modified configuration could look like:

 

	
		
		
			
				WEB-INF/mail.properties
				WEB-INF/jdbc.properties
			
		
	
 
	
		
		
	

 
Advertisements

Oracle SQLDeveloper and mystery of the missing host

2008/02/23

If you work with Oracle database, a very good tool you should not ignore is the Oracle SQL Developer. It gives you much more power when it comes to manipulating data or managing database. I use most of the time MyEclipseIDE plugins, but when I need e.g. export data, the SQLDeveloper is way to go.

Today I tried it for first time on the Mac. I started to configure and database connection and was completely confused by the error message “Port must contain numerical value”. Here was the dialog box:

picture-6.png

I typed the hostname:1521 but the error message kept coming back. There was no obvious way how to put 3 values – host, port and SID into two field. After checking the documentation, I remembered that the Windows version did have 3 text fields instead of two.

What was the problem ? The layout manager in Java did unfortunately completely hide one of the 3 fields. After resizing the dialog, all fields would be visible:

picture-4.png

After this, everything worked OK.

Obviously, Mac version of the SQLDeveloper could use some minor improvement. For example, the menu looks everything but like a finished Mac application:

picture-5.png

Why so quiet

2008/02/22

I have been sick for last two weeks, most of the time offline, listening to podcasts and audiobooks and doing more or less nothing. I have caught up with the backlog of episodes, saw lots of videos from Macworld.

Among the audiobooks I was listening two, some recommendations:

The Company is good parody of the corporate life. Starting with missing donut, it tells the story of a new hire in large corporation, governed by strange rules. It soon has an interesting twist – find for yourself. The book is available as MP3 CD, so you can save time ripping it to iPod.

Another book that I liked was cult classic that I have read before (in at least 3 languages), but never heard it: The Dune. Nicely done, and an excellent way how to make time fly faster when you are locked to bed and too sick to do any serious reading or coding 🙂

As of yesterday, I am back in circulation, trying to catch up with everything I missed for last two weeks.

Leopard 10.5.2 update

2008/02/11

Apple released today the 10.5.2 update. After over a year and half with Mac platform (and over 2 months on Mac only work environment) I become fearless and installed update without too much worries :-). Year ago, I guess I would be quite concerned whether the Service Pack will or will not render my work notebook useless with unreparable registry … I still remember the fun after SP2 got installed …

But back to the topic. Upgrade went smooth and after 2 bangs (reboots) everything seems to work OK. Finally there is an option to “tigerize” the translucent menu, without add-ons and hacks. Time machine has small menu item to access preferences. The update promises WiFi improvements (tests pending). What seems not get fixed is the annoying rfc1323 TCP/IP stack setting (see here).

So far the only things broken is the Beta version of fantastic little utility Library books (highly recommended – it does support many libraries, including our). The error message that comes after the program start says:


NSInvalidArgumentException

*** -[DebugController length]: unrecognized selector sent to instance 0x2ade20

Stack trace:

1    NSExceptionHandlerExceptionRaiser (in ExceptionHandling)

2    objc_exception_throw (in libobjc.A.dylib)

3    -[NSObject doesNotRecognizeSelector:] (in CoreFoundation)

4    ___forwarding___ (in CoreFoundation)

5    _CF_forwarding_prep_0 (in CoreFoundation)

6    -[Parser initWithString:] (in Library Books)

7    +[Parser parserWithString:] (in Library Books)

8    -[Dynix booksOnHoldFormat1:] (in Library Books)

9    -[Dynix booksOnHold] (in Library Books)

10    -[MainController _updateLibraryBooks] (in Library Books)

11    -[MainController _updateThread:] (in Library Books)

12    -[NSThread main] (in Foundation)

13    __NSThread__main__ (in Foundation)

14    _pthread_start (in libSystem.B.dylib)

15    thread_start (in libSystem.B.dylib)

What helps is to roll back to version 2.5 which works just fine.

Book recommendation: Java Concurrency in Practice

2008/02/06

After long time, I stumbled upon something that is both educational and practical. Since Doug Lea’s classic, this is very readworthy work on concurrency in Java world. It focuses on Java 5 features and addresses both Web applications as well as GUI apps – each group having their own share of concurrency related problems

jcp.jpg

Here is the Amazon page for the book – check the reviews. There is also a sample chapter available on the book’s website. If you have Safari subscription, you can read it there as well.

Recommended.

Spring Framework – the biggest missing piece

2008/02/04

I am having the pleasure working with Spring 2.x since about October last year. It is my return back to Spring, after first encounter in 2005 (counting only larger projects). Same as in previous project, it has been so much fun :-). So much fun in fact, that I was spending my evening playing with code and reading up what is new in 2.5, rather that blogging 😉

I am still amazed about how nice is the whole thing designed and how many ways it can be used. It’s flexibility is simply breathtaking. The price for the flexibility is complexity – sometimes it is not obvious what of many options should be chosen and what are all these options anyway :-).

Spring has very good documentation, compared to most of the open source projects I have looked at (and it was pretty large number over last 10 years). There are also many books on Spring, several of them pretty good. All this makes the fairly steep learning curve more accessible. But what is still missing are good examples.

But wait a moment, you may say – Spring source distribution DOES have several examples – for example JPetstore (offering two alternative implementations of UI – once using Spring MVC, once using Struts), Petclinic, and several others. The source code is nicely readable and well commented. So what is the big deal ?

The big deal is the ratio of options and possibilities offered by the framework to the options actually presented and demonstrated by the examples. Let’s take only the Spring MVC, which is certainly less than 30 % of the area covered by framework. Considering the possible combination of components would easily justify 20 examples just on that topic, not 2 or 3. The examples select one or two of possible URL mappers, provide some examples of controllers, view resolution and then the actual view. What is missing are alternatives and explanation of the differences. How would using SimpleUrlHandlerMapping instead of BeanNameUrlHandlerMapping impact the application, is explained pretty well in Chapter 13 of the documentation. For an experienced developer this (and a source code itself) is usually enough. If you try to explain Spring based application to somebody without prior IoC / DI experience, you may find out that it is not as obvious and that having an example of working code that would show the actual different implementation and letting him/her to compare and experiment, turning one into another would probably be the easiest way how to get started.

I realize that creating enough examples could be possibly a code maintenance nightmare – at least if the pace of Spring development will remain the same. In many cases, more documentation on the samples, explaining how it works at the high level and discussing the alternatives would be almost as helpful as the full source. The otherwise very good documentation is quite brief on the Samples side – the Chapters 26 has about two screens, and that for all the samples.

And because this is definitely NOT a rant, but an attempt to make a constructive suggestions, I plan to do something about the situation myself and will post the notes from “dissecting the Spring App” that I used for explaining how things works in Spring MVC and around. As soon as I get them to presentable form ;-). Stay tuned.