Child pages
  • Creating a wonder app to deploy as a servlet

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


If this were not a project wonder project (that is, if its Application and Session classes did not extend ERXApplication and ERXSession), we could copy over the JSPHelloWorld folder from dist into tomcat's webapps folder, restart tomcat, pull up a browser, type in http://localhost:8080/JSPHelloWorld/WebObjects/JSPHelloWorld.woaImage Removed, and see the same boring hello world page we saw when we ran the application as a standalone WO app. If you really want to verify this, just make your Application and Session classes extend WOApplication and WOSession instead, rebuild the thing, deploy it into tomcat as described above, and have a go.


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
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="">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) {

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

	public ERXServletAdaptor() throws ServletException {

	public void init() throws ServletException {