Monday, 17 November 2008

Spring source for minor spring projects and many others !

A while ago I struggled to find a Spring security test class TestingAuthenticationToken following an upgrade to spring-security from acegi.

Turned out it had been moved out of the standard release causing my tests to fail with a ClassNotFoundException. You will find it in spring-security-core-x.y.z-tests.jar for the relevant version.

Similarly, I wanted to see the source for a test class
org.springframework.test.AbstractTransactionalDataSourceSpringContextTests. This again can found on the same site as can the source for all spring modules. The root for spring modules is here.

Being more nosey you will find the source for may other projects (such as apache, eclipse, dbunit) by navigating further up the tree. Happy hunting.

Tuesday, 11 November 2008

MySQL and PHP on windows

The last few days I have been setting up a wiki at work using MediaWiki

MediaWiki needs PHP and some sort of database. I chose MySQL.

If I was on a linux server then all would probably have been fairly easy but sadly I am saddled with windows servers here.

If it was a fresh intall then I could probably have used WAMP but apache was already is use for other applications.

So I had to install MySQL & PHP manually. I installed MySQL with no problems, set up the required database and all looked good.

I installed PHP using the provided msi file and selected MySQL from the list of extensions.
When I ran a test php file to see phpinfo() there was no mention of MySQL. This appears to be a very common problem and no mention of the solution was easy at hand.

So the solution.
Copy the file libmySQL.dll from the bin directory of your MySQL install to your WINDOWS/system32 directory

Thursday, 6 November 2008

Variables in Microsoft SQLServer scripts

In Oracle you can create a script that takes configurable variables using the '&&var_name' syntax.

In SQLserver it is slightly different. The variables are defined using the syntax
:setvar var_name var_value
Then they are used using the syntax
CREATE TABLE $(var_name)
I have about ten scripts that all want the same selection of variables. First off I
duplicated the 'setvar' commands in each script but that is rubbish.

A better solution is to pull all these out into a separate file.

And then in the script you can refer to this file with the syntax
:r C:/TEMP/
Furthermore I could have a master script that calls all the scripts using the syntax:
:r C:/TEMP/
:r C:/TEMP/script_1.sql

:r C:/TEMP/script_2.sql
The one major gotcha is that these have to be run in SQLCMD mode.
To run the scripts from within SQL Server Manager Studio click on the SQLCMD Mode button. That's the one with the red exclamation mark before you execute the script.

There are more MS SQL tips here.

Tuesday, 4 November 2008

DWR, Spring and namespace configuration

I am in the process of upgrading an existing Spring based web application that also uses DWR for alot of its dynamic pages.

The current version of Spring is 1.2.7 and part of the upgrade is to move to Spring 2.5.5

Spring 2.x now supports the namespace style of XML config files which produces a dramatically smaller & easier to read configuration. I produced a working version of configuration in both the old style and the namespace style but stuck with the latter as this is the future.

The version of DWR is 1.1.3 and its configuration requires a config file dwr.xml in the old style.

All was going well until I started spotting Exceptions being thrown by DWR. The specified call count is not a number: null
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(

Upgrading to DWR 2.0.5 simply caused the Exception to disappear, but instead I got a popup stating much the same.

The problem is because I chose to use the namespace syntax for my configuration. One solution was to revert to the old style. Due to the size of the app and timescales I chose this option.

The other option is far nicer but a lot more work and that is to upgrade my DWR to 2.0.5 and change the configuration to also use the namespace syntax. This would create a solution with much better integration between DWR and Spring. I will try that out on my next application.

See DWRs documentation and Bram Smeet's blog on this topic for an excellent how-to.