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.
Monday, 17 November 2008
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
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
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
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.
In SQLserver it is slightly different. The variables are defined using the syntax
:setvar var_name var_valueThen 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.propertiesFurthermore I could have a master script that calls all the scripts using the syntax:
:r C:/TEMP/my_sqlserver.propertiesThe one major gotcha is that these have to be run in SQLCMD mode.
:r C:/TEMP/script_1.sql
:r C:/TEMP/script_2.sql
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.
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.
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.
Tuesday, 26 August 2008
AmbiguousTableNameException in dbUnit
There is plenty of documentation on AmbiguousTableNameException in dbunit but I was unable to find a clear example showing the problem and the solution.
We have an application that needs to work on Oracle & SQLServer. The integration tests make extensive use of dbunits dataset classes to populate test databases. The tests clear out various tables & populate the tables as required. Previous to me being involved there would be only one database that had to be populated for use and cleaned out to run the tests. I found this a pain so I created a test database for the integration test use only.
SQL Server continued to work fine however when running the Oracle tests I got lots of AmbiguousTableNameExceptions being thrown. It took me a good while to make the connection as to the cause despite it being written in black & white.
Our code was creating the DatabaseConnection as follows:
Logically this should be absolutely fine. First off it all worked before. The Datasource fully describes the connection. In the debugger I could see the username, password and connection url. Accessing the database from the command line using the same parameters all looked cool. Upgrading to dbunit 2.2 proved fruitless.
So why would the connection come up with an AmbiguousTableNameException when that user has no privileges to see any other schema? The long answer to that defeats me.
However as I said the solution is there on the dbunit website.
Despite the fact that the connection has everything defined you still need to tell the DatabaseConnection object the schema name. In the constructor pass in the Schema name and all will be fine.
We have an application that needs to work on Oracle & SQLServer. The integration tests make extensive use of dbunits dataset classes to populate test databases. The tests clear out various tables & populate the tables as required. Previous to me being involved there would be only one database that had to be populated for use and cleaned out to run the tests. I found this a pain so I created a test database for the integration test use only.
SQL Server continued to work fine however when running the Oracle tests I got lots of AmbiguousTableNameExceptions being thrown. It took me a good while to make the connection as to the cause despite it being written in black & white.
Our code was creating the DatabaseConnection as follows:
DataSource ds = (DataSource) applicationContext.getBean(getDataSourceName());
DatabaseConnection mDbConnection = new DatabaseConnection(getConnection(ds));
Logically this should be absolutely fine. First off it all worked before. The Datasource fully describes the connection. In the debugger I could see the username, password and connection url. Accessing the database from the command line using the same parameters all looked cool. Upgrading to dbunit 2.2 proved fruitless.
So why would the connection come up with an AmbiguousTableNameException when that user has no privileges to see any other schema? The long answer to that defeats me.
However as I said the solution is there on the dbunit website.
Despite the fact that the connection has everything defined you still need to tell the DatabaseConnection object the schema name. In the constructor pass in the Schema name and all will be fine.
DatabaseConnection mDatabaseConnection = new DatabaseConnection(connection, getSchemaName());
This all appears to be a bug in dbunit and potentially a security flaw as it implies a connection with limited access can see other schemas.
Thursday, 21 August 2008
jar search tool
How often do you want to search a directory structure to see which jar a particular class is in.
I always end up doing the following:
I have done this long hand so many times that I have decided to script it.
Use this script jar_search like this.
The second parameter is optional and allows you to restrict what jars you will search through.
Here is the jar_search script:
I always end up doing the following:
list=`find . -name "*jar"`
for file in $list
do
echo $file
jar tvf $file grep Somepattern
done
I have done this long hand so many times that I have decided to script it.
Use this script jar_search like this.
jar_search ObjectPool
or
jar_search ObjectPool comm
The second parameter is optional and allows you to restrict what jars you will search through.
Here is the jar_search script:
#
# search a list of jar files for a pattern
# the jar pattern is optional
# By Bill Comer, August 2008
#
if [ $# -lt 1 ]
then
echo "Usage: jar_search [searchPattern] [jarPattern]"
exit -1
fi
searchPattern=$1
jarpattern=$2
list=`find . -name "*$jarpattern*.jar"`
for file in $list
do
found=`jar tvf $file | grep $searchPattern`
if [ ! -z "$found" ]
then
echo $file
echo $found
fi
done
Tuesday, 19 August 2008
Understanding Kaminsky's DNS Bug
See the linux journal for a very good explanation
If you are impatient or do not want to read the explanation
just go to doxpara.com and select the 'Check My DNS' button.
If you are impatient or do not want to read the explanation
just go to doxpara.com and select the 'Check My DNS' button.
Friday, 15 August 2008
importing oracle dumps using imp or impdp
Using Oracle Enterprise Manager I was trying to import a DMP file into an oracle database & I got the error:
There appears to be two import tools and Enterprise Manager only knows about 'impdp'. There is the old import tool 'imp' that is needed if the dump file was created using 'exp' as opposed to 'expdp' or via Enterprise Manager.
The solution.
Simply run:
Import Submit Failed There is a problem reading from the import files: ORA-39143: dump file "c:\temp\case9_0.DMP" may be an original export dump file .
There appears to be two import tools and Enterprise Manager only knows about 'impdp'. There is the old import tool 'imp' that is needed if the dump file was created using 'exp' as opposed to 'expdp' or via Enterprise Manager.
The solution.
Simply run:
where user & password are for the user in the dump file and it will prompt you for all the answers.
imp user/password
Friday, 25 July 2008
OutOfMemory Error from eclipse
I know there are hundreds of blog entries covering this. Here is another.
I followed the general scriptures and set the values in my eclipse.ini file. Currently mine looks like this:
However I was still getting OutOfMemory errors when trying to run an ant test coverage task. Why ?
I solved the problem, or should I say I have not seen the problem since I did the following:
In eclipse go to:
Window->Preferences->Java->Installed JREs.
Select the JRE that you are using and select 'Edit'.
Then add the following to the 'Default VM Aguments'
-Xms128m -Xmx1024m -XX:MaxPermSize=256m
I followed the general scriptures and set the values in my eclipse.ini file. Currently mine looks like this:
-showsplash
com.genuitec.myeclipse.product
--launcher.XXMaxPermSize 256m
-vmargs
-Xms128m
-Xmx1024m
-Duser.language=en
-XX:PermSize=128M
-Xss2m
-XX:MaxPermSize=256M
However I was still getting OutOfMemory errors when trying to run an ant test coverage task. Why ?
I solved the problem, or should I say I have not seen the problem since I did the following:
In eclipse go to:
Window->Preferences->Java->Installed JREs.
Select the JRE that you are using and select 'Edit'.
Then add the following to the 'Default VM Aguments'
-Xms128m -Xmx1024m -XX:MaxPermSize=256m
Thursday, 26 June 2008
Friendly if/then constructs in ant
Sometimes I wonder if a post is interesting to me because it is new to me but everyone else already knows about it.
Anyway, here goes. I wanted to do an If/else test in my build file and the < condition> construct produced some unbelievably ugly code. After considerable hunting I found ant-contrib.sourceforge.net
This has got a range of new constructs. The manual pages are here
My problem was that I wanted to test if a property had been set and to one of two specific values. This is what I ended up with.
Anyway, here goes. I wanted to do an If/else test in my build file and the < condition> construct produced some unbelievably ugly code. After considerable hunting I found ant-contrib.sourceforge.net
This has got a range of new constructs. The manual pages are here
My problem was that I wanted to test if a property had been set and to one of two specific values. This is what I ended up with.
Wednesday, 11 June 2008
In line searching in Eclipse & IE7
I hate the search pop up window you get when you type Ctrl-F in many applications.
I searched for an add-on but eventually found that Eclipse already provide it but under the odd title of 'Incremental Find'
Type Ctrl-J and the words 'Incremental Find' will appear at the bottom of your window.
Simply type away with the text you want to search for.
The cursor will automatically jump to the next occurance of that string.
Ctrl-J will then make the cursor jump too the next.
Shift-Ctrl-J will jump backwards.
And I have just discoverred this. If you type the search word
all in lower case then the search is case insensitive. If you mix case then the search is case specific.
It had been bugging me that IE7 was the same.
Then I found this add-on
After a quick try it appears to do the job.
I searched for an add-on but eventually found that Eclipse already provide it but under the odd title of 'Incremental Find'
Type Ctrl-J and the words 'Incremental Find' will appear at the bottom of your window.
Simply type away with the text you want to search for.
The cursor will automatically jump to the next occurance of that string.
Ctrl-J will then make the cursor jump too the next.
Shift-Ctrl-J will jump backwards.
And I have just discoverred this. If you type the search word
all in lower case then the search is case insensitive. If you mix case then the search is case specific.
It had been bugging me that IE7 was the same.
Then I found this add-on
After a quick try it appears to do the job.
Tuesday, 29 April 2008
Using the ruby oracle_adapter on Windows XP
I have been having some problems getting my windows install of ruby to connect to oracle. It is so much easier on ubuntu. Looking at the blog of a friend Andrew Beacock other people have had the same problem, admittedly a while ago.
I tried the gem install command:
I tried
Then I tried this. I am sure it is not the purist solution but it works !!!
Download the oracle_adapter.rb
Then copy this into the relevant directory under where you have ruby installed.
And bobs your father's brother ...
My database.yml file looks like this:
I tried the gem install command:
gem install activerecord-oracle-adapterwith no luck.
I tried
gem install activerecord-oracle-adapter --source http://gems.rubyforge.orgalso with no luck.
Then I tried this. I am sure it is not the purist solution but it works !!!
Download the oracle_adapter.rb
Then copy this into the relevant directory under where you have ruby installed.
C:\ruby\lib\ruby\gems\1.8\gems\activerecord-2.0.2\lib\active_record\connection_adapters
And bobs your father's brother ...
My database.yml file looks like this:
development:
adapter: oracle
database: my_sid
username: my_user
password: my_password
Saturday, 5 April 2008
hibernate3 - hibernateQueryException - Class is not mapped
I have been having a problem for a while trying to get a basic hibernate3 and Spring 2.5 example working. Using old style hibernate CLASS_NAME.hbm.xml files worked fine. When I changed the context.xml file to try & use annotations instead I got the following error:
Check the imports of your '@Entity' annotations in your beans
If it is:
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException:
Test is not mapped [from Test t where t.name = ?];
nested exception is org.hibernate.hql.ast.QuerySyntaxException:
Test is not mapped [from Test t where t.name = ?] at
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:640)
Check the imports of your '@Entity' annotations in your beans
If it is:
org.hibernate.annotations.Entity;Then change it to:
import javax.persistence.Entity;and life will be sweet.
Thursday, 13 March 2008
Getting mysql gui tools working on ubuntu 7.10
I had three hurdles to get over to get mysql gui tools to work.
1. My first problem was that I got the error
when I tried running mysql-administrator
This was because my mounted directory did not have exec permissions. Adding 'exec to the row in /etc/fstab, then umount & mount solved this.
2. My next problem was the following error:
I eventually found this. The fix is right at the end.
To cut a long story short.
3. My third and hopefully last problem was that I could not connect to localhost:3306
However I could connect to 127.0.0.1:3306
My /etc/hosts looked like this.
1. My first problem was that I got the error
/bin/sh: bad interpreter: Permission denied
when I tried running mysql-administrator
This was because my mounted directory did not have exec permissions. Adding 'exec to the row in /etc/fstab, then umount & mount solved this.
/dev/hdb1 /media/d_drive auto rw,user,exec 0 0
2. My next problem was the following error:
./mysql-administrator
(mysql-administrator-bin:7476): Gtk-WARNING **: Unable to locate theme engine in module_path: "ubuntulooks",
Fontconfig warning: line 32: unknown element "cachedir"
Fontconfig warning: line 33: unknown element "cachedir"
Fontconfig warning: "/etc/fonts/conf.d/80-delicious.conf", line 18: invalid match target "scan"
./mysql-administrator-bin: symbol lookup error: /usr/lib/libbonoboui-2.so.0: undefined symbol: g_once_init_enter_impl
I eventually found this. The fix is right at the end.
To cut a long story short.
cd to where you have unpacked the gui tools
mv lib lib_
& if
/etc/mysql/conf.d does not exist
mkdir /etc/mysql/conf.d
3. My third and hopefully last problem was that I could not connect to localhost:3306
However I could connect to 127.0.0.1:3306
My /etc/hosts looked like this.
I am not sure if this is a good fix but the cure was to comment out the line
127.0.0.1 localhost
127.0.1.1 billspc
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
#::1 ip6-localhost ip6-loopback
Wednesday, 5 March 2008
IntelliJ Live Templates for Eclipse
D you miss all those IntelliJ Templates when in Eclipse.
If so, then go thekua.com for all the instructions you need.
If so, then go thekua.com for all the instructions you need.
UnitTest and spring-mock or spring-test
I have just installed spring 2.5.1
I wanted to create some unit tests and all the sites I found referred to spring-mock.jar.
It is now spring-test.jar.
You will find it in the directory spring-framework-2.5.1/dist/modules after you have extracted the zip. I downloaded spring-framework-2.5.1-with-dependencies.zip although I see they have gone to 2.5.2 already.
I wanted to create some unit tests and all the sites I found referred to spring-mock.jar.
It is now spring-test.jar.
You will find it in the directory spring-framework-2.5.1/dist/modules after you have extracted the zip. I downloaded spring-framework-2.5.1-with-dependencies.zip although I see they have gone to 2.5.2 already.
Tuesday, 26 February 2008
Eclipse on ubuntu throws ClassNotFoundException
I have just performed a fresh install on my pc with the latest ubuntu 7.10 (Gutsy Gibbon). After installing Eclipse I got the following Exception java.lang.ClassNotFoundException: org.eclipse.core.runtime.Plugin
The problem is that the default java that is installed is not compatible.
ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2008-02-26 14:52 /usr/bin/java -> /etc/alternatives/java
The solution is to install the latest version of java from www.sun.com
and change the java link in /usr/bin. I installed this in /tools/java6 and then created a link called java
cd /tools
sudo ln -fs /tools/java6 java
cd /usr/bin
sudo mv java java_alternatives
sudo ln -fs /tools/java/jdk/bin/java
Welcome
After several years of taking the michael out of a long lasting friend & colleague Andrew Beacock I have come to realise the benefits of blogging to all. Andrews blog has come to be an invaluable resource for our team. So here goes with my little contribution.
Subscribe to:
Posts (Atom)