Adapting TileCache to work as a Java servlet
NOTE! This project is no longer active and has been superseded by GeoWebCache
Summary
This page describes briefly how I (
JonBlower) adapted
MetaCarta's
TileCache software (which is written in Python) so that it functions as a Java servlet. This is achieved using
Jython, which is an implementation of Python in Java. Some small modifications to the TileCache code were necessary but the vast majority is left unchanged.
Motivation
The primary reason for wanting to do this was that I am looking for a caching solution to increase the performance of
ncWMS, a Web Map Service for
NetCDF data. ncWMS is written in Java and I need tight coupling between the cache and the ncWMS code. This is because I need to cache arrays of
data, not images: the client can style the same data in different ways and the rate-limiting step in a typical ncWMS request is the extraction of the data array, not the rendering of the image.
How I did it
I used
NetBeans 5.5 as my development environment, but this isn't really necessary: the main reason to use NetBeans is that it creates a skeleton web application with the correct directory structure and config files automatically. Here are the steps I followed:
- Installed Jython version 2.2 beta 1 as a standalone, callable jar file. This bundles all the Jython libraries into a single jar archive, simplifying installation. This created a single jar file,
jython.jar, which I renamed to jython-2.2b1.jar.
- Created a new web application called
TileCache in NetBeans.
- Jython-enabled the web application by copying
jython-2.2b1.jar into WEB-INF/lib and editing web.xml to associate .py files with the Jython servlet engine (see here or look inside the attached WAR file for details).
- Downloaded the TileCache 1.4 code from http://www.tilecache.org and extracted the code (i.e. just the Python files) into
WEB-INF/jython.
- Created
TileCacheServlet.py. This was the hardest bit: this is a Java servlet that is written in Python. It handles requests from clients through a TileCache.Service object that it creates from the configuration file. See inside the WAR file for details.
Instructions for use
Installation
- Install Java and the servlet container (Tomcat/Jetty/Geoserver etc)
- Download the WAR file into the
webapps directory of the servlet container.
- Rename the WAR file
TileCache.war. (You don't have to do this but it saves editing the URLs in the OpenLayers test page).
Configuration
- Create a TileCache configuration file (see the TileCache web site for details) and place it in
$HOME/.tilecache. On Windows, your $HOME directory is something like C:\Documents and Settings\yourusername.
Starting the TileCache server
Troubleshooting
- I get a load of pink tiles in index.html: Open
index.html in a text editor and edit the URL to the TileCache server to match your setup.
Notes
- The configuration file could be bundled in the WAR file, but this would mean that every time the WAR file is upgraded, the config file could be overwritten. Also, some servlet containers do not expand the WAR file, meaning that it would be impossible to edit the config file.
- I needed to modify TileCache's
Cache.py file because Jython does not implement the os.access() function.
- This has not been thoroughly tested! I have simply verified correct operation with a WMS back-end. I have not tested performance.
Feedback
If you have tried this out and have any comments, please email
jdb@mailNOSPAMPLEASE.nerc-essc.ac.uk.
--
JonBlower - 25 Mar 2007
Topic revision: r5 - 19 Jun 2008 - 13:25:53 -
JonBlower