To edit or add content to this Wiki, you can simply create a new account at http://wocommunity.org/account.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Henrique created a class called ERXServletAdaptor and it is submitted as a pending project wonder patch as we speak (or as I type, as the case may be). I could not get the code in that patch to run as is, so I have changed it just a bit. Here is my version of the class that works for me. Something very similar to this may soon be bundled with project wonder, but for now, you can just toss this class into your project's Sources folder:

Code Block
java
java
titleERXServletAdaptor.javajava
 
package er.extensions.jspservlet;

import java.lang.reflect.Method;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;

import com.webobjects.jspservlet.WOServletAdaptor;

import er.extensions.appserver.ERXApplication;

/**
 * This class is just a wrapper around <code>WOServletAdaptor</code>.
 * <code>ERXServletAdaptor</code> must be used to make Wonder applications
 * compliant with WAR deployment.
 * <p>
 * This class is responsible to invoke the
 * {@link ERXApplication#setup(String[])} method before the application
 * initialization.
 * 
 * @see WOServletAdaptor
 * @author <a href="mailto:hprange@moleque.com.br">Henrique Prange</a>
 */
public class ERXServletAdaptor extends WOServletAdaptor {

	/**
	 * Overrides the <code>_appliationInit</code> and invoke the
	 * {@link ERXApplication#setup(String[])} method before the application
	 * initialization.
	 * 
	 * @see WOServletAdaptor#_applicationInit(ServletContext)
	 */
	
	/*
	 * 
	 * @param servletContext
	 *            The servlet context to get the application class
	 * @throws UnavailableException
	 *             If something wrong happens while trying to invoke the
	 *             application setup method.
	 */
	static void invokeApplicationSetupMethod(ServletContext servletContext) throws UnavailableException {
		ClassLoader classLoader = WOServletAdaptor.class.getClassLoader();

		try {
			String applicationClassName = servletContext.getInitParameter("WOApplicationClass");

			if (applicationClassName == null || "".equals(applicationClassName)) {
				throw new UnavailableException("WOApplicationClass must be defined. Verify your web.xml configuration.");
			}

			Class applicationClass = classLoader.loadClass(applicationClassName);

			Method method = applicationClass.getMethod("setup", new Class[] { String[].class });

			method.invoke(null, new Object[] { new String[0] });
		}
		catch (Exception e) {
			e.printStackTrace();

			throw new UnavailableException("Error initializing ERXServletAdaptor: " + e.getMessage());
		}
	}

	public ERXServletAdaptor() throws ServletException {
		super();
	}

	@Override
	public void init() throws ServletException {
		ERXServletAdaptor.invokeApplicationSetupMethod(getServletContext());
		super.init();
	}
	
}

...