Saturday, May 24, 2008

» Embedded Jetty + WicketFilter - web.xml

I searched quite a bit on lazyweb but couldn't find anything conclusive so.. for posterity, here is how to start an embedded Jetty (a lightweight Java Servlet container/webserver) without any XML, add <init-param/> values without XML (Wicket's WicketFilter requires a applicationClassName init-param that contains the fully qualified class name of your WebApplication) and with Wicket:
import org.apache.wicket.protocol.http.ContextParamWebApplicationFactory;
import org.apache.wicket.protocol.http.WicketFilter;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.DefaultServlet;
import org.mortbay.jetty.servlet.FilterHolder;

public class EmbeddedJettyWithWicket {
   // change these accordingly:
   private static final String LISTEN_HOST = "localhost";
   private static final int LISTEN_PORT = 8888;
   private static final String WICKET_WEBAPP_CLASS_NAME =

   public static final void main(String[] argsthrows Exception {
      Server server = new Server();
      SelectChannelConnector connector = new SelectChannelConnector();
      server.setConnectors(new Connector[] { connector });
      Context root = new Context(server, "/", Context.SESSIONS);
      root.addServlet(DefaultServlet.class, "/*");
      FilterHolder filterHolder = new FilterHolder(WicketFilter.class);
      root.addFilter(filterHolder, "/*"1);
UPDATE: replaced with code that actually works

Labels: , ,


Post a Comment

<< Home