Sunday, 19 September 2010

Fixing my HTC Desire's wifi

I recently did an Over The Air (OTA) update of my new HTC Desire from 2.09 to 2.10. The update all seemed to run correctly. However I soon noticed that the wifi wasn't working. Looking in settings, it showed wifi was disabled and when you try and enable it, you just get "error". Seems like other people have been getting this as well. I tried following their advice, reset the factory defaults but that didn't work. I couldn't get the recovery mode to load (in order to wipe the caches) - after some brief searching it appeared that this was due to root access so I gave up on that.
NOTE: it turns out I was doing it wrong. After selecting the recovery option a red triangle with an exclamation point is show. At which point you need to press volume+ and power to show the next menu.

Next I tried using latest RUU (2.10) but got Error 170 Usb Connection Error. One post mentions under 'update':
HTC has released a new Froyo OTA update. You can install this directly as an RUU. You may need the latest version of HTC Sync for this version. There appear to be a lot of issues installing this RUU due to drivers. I'd recommend you install the earlier version and update OTA to this version (you can do this manually too).

Using 1.21.405.2 gave me ERROR [131] customer id error. After some poking around, turns out that branded phones don't have a CID... That's what you get with a phone from Hong Kong I guess. However I'm not really sure if that's true...

Eventually I came across this thread which mentions fixing the wifi error with this update: Froyo (2.09.405.8) update - Windows not required. It all installed correctly and after starting it up, it ran through the first-time setup and this time said it detected a wireless network. Success! I didn't try the windows RUU for 2.09 so I'm not sure if that will work.

Next I downloaded the update manually as per the instructions here. The phone started downloading OTA_Bravo_HTC_EU_2.10.405.2-2.09.405.8_release567cypyi0feo4th5.zip so I'm using that instead of the one in the post.

This thread has a better discussion of the problem, with some simple instructions on how to revert and reload when a goldcard isn't needed.

Friday, 17 September 2010

Escaping a regex expression

I was working on a project where I needed to dynamically generate a regular expression based on some user input but the string to search for needed to be escaped. Below is the quick and dirty way to do it:
/**
 * Utility function to replace regular expressions.
 *
 * @param input
 * @return
 */
private static String escapeRegex(String input)
{
    String special[] = { "\\", "[", "]", "^", "$", ".", "|", "?", "*", "+", "(", ")" };
    String val = input;
    for (String replace : special)
    {
        val = val.replace(replace, "\\" + replace);
    }

    return val;
}

Tuesday, 14 September 2010

Tomcat DBCP: Data source is closed

After updating to the latest version of Tomcat I started getting the following error when redeploying a webapp from inside eclipse:
java.sql.SQLException: Data source is closed
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1362)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)

It seemed to be related to an updated version of DBCP that is used inside tomcat (I get Tomcat to manage my datasource). After tracing the code a bit I discovered it was because I called this, in my Filter.destroy() to do clean up:
((BasicDataSource) dataSource).close();

Older versions of Tomcat (6.0.26 and below), didn't care if you called it. When the webapp was reloaded, the datasource still worked. But as of 6.0.28, the newer version of DBCP seems to cause problems.

So if you want to clean up after the webapp, use the removeAbandoned attribute in the Tomcat Configuration on the datasource, that way DBCP just cleans up after itself.

NOTE: I'm using the tomcat-dbcp.jar from Tomcat 7 in my Tomcat 6 instance so that I'm able to use the JDBC 4 functionality. Hence the link to the new documentation, Tomcat 6 Configuration also has it though.

Wednesday, 8 September 2010

Portable java environments on windows

I always seem to be copying my development environment between PCs and latops which end up being time consuming. Its not the size of the data, its the number of small files (mainly javadoc & java source) that slow the whole process down. I already store the source code and workspace for my clients in a TrueCrypt Volume, to prevent my code being stolen if someone were to get hold of my laptop.

All the other necessary files I need for development; such as libraries, jdk, tomcat/jboss, elcipse etc; are stored on my hard drive. In some cases on different drive letters on different computers. So to simplify this I wanted to store them in a similar way to a TrueCrypt volume but without the overhead of encryption and the hassle of mounting it. After some poking around I remember that Windows 7 came with built-in support for creating and mounting Virtual Hard Disk (VHD) straight from the Storage Manager. The VHD are used by Virtual PC. For those running Vista, Virtual PC 2007 should support this.

For windows 7, you can easily mount an image using the admin interfaces or even create a shourtcut/bat script to mount it. However I wanted the image mounted on start up so it was ready to use. I eventually came across this neat utility (vhdattach) to add shell extension to mount an image with the option to mount at startup. Vista has this alternative.

Now all I need to do to swap PC's is to copy my TrueCrypt volume and my VHD across, mount them on the same letters and done! No need to change paths etc.