tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Wille <mwi...@donerus.com>
Subject Subclassing WebdavServlet
Date Mon, 26 Jul 2004 18:26:29 GMT
Hello All,

I would like to know if its possible to subclass the webdav servlet 
that comes with Tomcat 5.x.  We have need of webdav in our application, 
but need to provide a different JNDI InitialContext then the file 
system.  The thought was we could just override the getResources() 
method in WebdavServlet to return our own context.

What follows is a description of what we are doing:

It seems there is at least one obstacle to doing this.  We would have 
to move/copy the jar files: servlets-default.jar, servlets-common.jar, 
and servlets-webdav.jar to the common/lib folder.  It seemed when we 
attempted to move the files to common/lib, all of the default webapps 
couldn't be loaded as well as some of our application servlets.  When 
we leave the servlets*.jar files in both server/lib and common/lib, an 
exception is thrown when accessing our servlet:

javax.servlet.ServletException: Error instantiating servlet class 
com.test.webdav.XDav

And this is caused by:

java.lang.NoClassDefFoundError: 
org.apache.catalina.servlets.DefaultServlet

This seems strange considering the app should have access to the 
servlets-default.jar now that it is in common.  Or is there an issue 
with libs in both server and common?

Any help is hugely appreciated.

Thanks!

-Mike Wille

Our subclassed servlet (with only test code for the InitialContext):

package com.test.webdav;

import javax.servlet.*;
import javax.servlet.http.*;

import javax.naming.directory.InitialDirContext;
import javax.naming.directory.DirContext;

import org.apache.catalina.servlets.*;

public class XDav extends WebdavServlet  {

	// need to dup this here because these have
	// private access in apaches webdavservlet	
	protected static final String METHOD_HEAD		= "HEAD";
	protected static final String METHOD_PROPFIND	= "PROPFIND";
	protected static final String METHOD_PROPPATCH	= "PROPPATCH";
	protected static final String METHOD_MKCOL		= "MKCOL";
	protected static final String METHOD_COPY		= "COPY";
	protected static final String METHOD_MOVE		= "MOVE";
	protected static final String METHOD_LOCK		= "LOCK";
	protected static final String METHOD_UNLOCK		= "UNLOCK";
	
	protected Logger logger;

	public void init (ServletConfig config) throws ServletException {
		// wake your parents
		super.init(config);
	}

	public void destroy() {
		// kill your parents
		super.destroy();
	}
	
	/**
	 * Get resources. This method will try to retrieve the resources 
through
	 * JNDI first, then in the servlet context if JNDI has failed (it 
could be
	 * disabled). It will return null.
	 *
	 * @return A JNDI DirContext, or null.
	 */
	protected DirContext getResources() {

		InitialDirContext result = null;

		// Try the servlet context
		try {
			//result = new IntitialLibraryContext();
			result.bind("directory 1", "directory 1");
			result.bind("directory 2", "directory 2");
			result.bind("directory 3", "directory 3");
			result.bind("directory 4", "directory 4");
			result.bind("directory 3/subdirectory 5", "subdirectory 5");
			
			
		} catch(Exception e) {
			logger.warning(UtilityTank.getErrorDetail(e));
		}
		return result;

	}	
}
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message