Dataset Source Plugin


In order for the TDS to serve data through any of the subsetting protocols like OPenDAP, WCS and the Netcdf Subsetting Service, it must be able to read the data into the Common Data Model. When the data is contained in a file, this is done with an I/O Service Provider (IOSP). When the dataset depends on request parameters that are passed to the TDS by the client, then a more general interface is needed, since the IOSP does not have access to the HttpServletRequest object.

Create a DatasetSource implementation class

Your class must implement the thredds.servlet.DatasetSource interface:

public interface DatasetSource {

  public boolean isMine( HttpServletRequest req);
public NetcdfFile getNetcdfFile( HttpServletRequest req, HttpServletResponse res) throws IOException; }

The implementor of DatasetSource must quickly determine if it can service the request by returning true or false from the isMine method. If true, then it must be able to return a NetcdfFile from the getNetcdfFile(). Any caching or performance optimizations must be handled by the DatasetSource implementor. It is usually important for performance reasons to cache the NetcdfFile object for subsequent access, since clients typically access a NetcdfFile several or many times, not just once.

It should handle any errors other than IOException, and send appropriate status responses back in the HttpServletResponse. If it returns null, the calling routine will assume that you have sent the response yourself, and will terminate processing without further action.

Example

public class ExampleDataSource  implements thredds.servlet.DatasetSource {
HashMap hash = new HashMap(); init() { ... }
 public boolean isMine(HttpServletRequest req) {
   String path = req.getPathInfo();
   return path.startsWith("/special/");
 }
 public NetcdfFile getNetcdfFile(HttpServletRequest req, HttpServletResponse res) throws IOException {
   String path = req.getPathInfo();
   path = path.substring("/special/".length());
   String specialMap = (String) hash.get(path);
   if (specialMap == null) {
    res.sendError(HttpServletResponse.SC_NOT_FOUND);
    return null;
   }  
   return new MyNetcdfFile(req.getRequestURI(), specialMap);
 }
 public class MyNetcdfFile extends NetcdfFile {
   MyNetcdfFile(String location, String specialMap) throws IOException {
   super( new MyIOSP(specialMap), null, location, null);
 }
}

Loading your class at runtime

You must place your DatasetSource class into the ${tomcat_home}/webapps/thredds/WEB-INF/lib or classes directory.

Then tell the TDS to load it by adding a line to the ${tomcat_home}/content/thredds/threddsConfig.xml file, for example:

  <datasetSource>my.package.DatasetSourceImpl</datasetSource>


This document is maintained by John Caron and was last updated on Feb 15, 2007