package au.edu.educationau.opensource.devsupport; import java.util.ArrayList; import java.util.List; import org.mortbay.jetty.Handler; import org.mortbay.jetty.Server; import org.mortbay.jetty.bio.SocketConnector; import org.mortbay.jetty.handler.DefaultHandler; import org.mortbay.jetty.handler.HandlerCollection; import org.mortbay.jetty.security.SslSocketConnector; import org.mortbay.jetty.webapp.WebAppContext; import au.edu.educationau.opensource.spring20.EnvironmentPropertyConfigurer; /** *
Use this in development to run a Jetty instance which will use the classes + resources straight out of the source tree (ie. no need to package + redeploy * etc. each time a file is changed). The expanded web application will be run from the directory src/main/webapp relative to the project root.
* *It will default to running on port 80, but this can be altered using the test.webserver.port system property.
* *Turn SSL on using the test.webserver.usessl system property (true/false), and set the SSL port with the test.webserver.sslport
* system property (default is 443). If you use SSL you will need to create a key. The best docs for that are
* http://docs.codehaus.org/display/JETTY/How+to+configure+SSL#HowtoconfigureSSL-step4
* but the easiest way is
* keytool -keystore keystore -alias jetty -genkey -keyalg RSA
* The key should be deployed to src/test/resources/keystore relative to the project root. Passwords for the keystore password,
* key and truststore all default to password but may be specified using the
* test.webserver.ssl.storepassword, test.webserver.ssl.keypassword and test.webserver.ssl.trustpassword system properties.
*
Note that the the web application will be loaded before the webserver ports are set. This means that code in the web application has a * chance to set the relevent system properties. This enables the use of {@link EnvironmentPropertyConfigurer} for configuration. * *
The dependencies required to get this to work with JSP support are as follows: *
* *javax.servlet servlet-api 2.5 provided javax.servlet.jsp jsp-api 2.1 provided org.mortbay.jetty jetty 6.1.5 test org.mortbay.jetty jetty-util 6.1.5 test org.apache.tomcat el-api 6.0.18 org.apache.tomcat jasper-el 6.0.18 org.apache.tomcat jasper 6.0.13 test org.apache.tomcat jasper-jdt 6.0.18 test * org.apache.tomcat juli 6.0.18
Many of these come from the tomcat release Maven repository: * *
* */ public class TestWebServer { public static void main(String[] args) throws Exception { Server server = new Server(); // don't specify the port here WebAppContext firstWebappContext = new WebAppContext(); firstWebappContext.setContextPath(System.getProperty("test.webserver.webapp.context") != null ? System.getProperty("test.webserver.webapp.context") : "/"); firstWebappContext.setWar(System.getProperty("test.webserver.webapp.war") != null ? System.getProperty("test.webserver.webapp.war") : "src/main/webapp"); List* tomcat-repo http://tomcat.apache.org/dev/dist/m2-repository/org/apache/tomcat