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
$(var_name)
IE:
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.
EG c:/TEMP/my_sqlserver.properties

And then in the script you can refer to this file with the syntax
:r C:/TEMP/my_sqlserver.properties
Furthermore I could have a master script that calls all the scripts using the syntax:
:r C:/TEMP/my_sqlserver.properties
: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.
java.io.IOException: The specified call count is not a number: null
at uk.ltd.getahead.dwr.impl.ExecuteQuery.parseParameters(ExecuteQuery.java:427)
at uk.ltd.getahead.dwr.impl.ExecuteQuery.execute(ExecuteQuery.java:89)
at uk.ltd.getahead.dwr.impl.DefaultExecProcessor.handle(DefaultExecProcessor.java:48)
at uk.ltd.getahead.dwr.impl.DefaultProcessor.handle(DefaultProcessor.java:81)
at uk.ltd.getahead.dwr.AbstractDWRServlet.doPost(AbstractDWRServlet.java:162)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
......

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.