Commits

Stephen McKamey committed 7a9a208

enabling HTTPS

Comments (0)

Files changed (5)

war-bootstrap/src/main/java/org/duelengine/bootstrap/Bootstrap.java

 			"  -war <context>=<path>  : set the context of war (e.g., /=./root.war)\n" +
 			"  -p <port>              : set the HTTP listening port (default: 8080)\n"+
 			"  -s <port>              : set the HTTPS listening port (default: none)\n" +
+			"  -ks <keystore=file>    : set the path to the keystore file (default: null)\n" +
+			"  -kp <keystore-pass>    : set the password to the keystore (default: null)\n" +
 			"  --tomcat               : use Tomcat as servlet container (default)\n" +
 			"  --jetty                : use Jetty as servlet container\n" +
 			"  --glassfish            : use GlassFish as servlet container";
 		int port = 8080;
 		int https = -1;
 		ServletServer server = null;
+		String keystoreFile = null;
+		String keystorePass = null;
 		try {
 			System.out.println(SEPARATOR);
 			System.out.println("WAR Bootstrap\n");
 				} else if ("-s".equals(arg)) {
 					https = Integer.parseInt(args[++i]);
 
+				} else if ("-ks".equals(arg)) {
+					keystoreFile = args[++i];
+
+				} else if ("-kp".equals(arg)) {
+					keystorePass = args[++i];
+
 				} else if ("-war".equals(arg)) {
 					String contextPath;
 					String warPath = args[++i];
 			System.out.println(SEPARATOR);
 			System.out.println();
 
-			server.start(contexts, port, https);
+			server.start(contexts, port, https, keystoreFile, keystorePass);
 
 			System.in.read();
 

war-bootstrap/src/main/java/org/duelengine/bootstrap/GlassFishServletServer.java

 		return "GlassFish";
 	}
 
-	public void start(Map<String, String> contexts, int httpPort, int httpsPort) throws Exception {
+	public void start(Map<String, String> contexts, int httpPort, int httpsPort, String keystoreFile, String keystorePass)
+		throws Exception {
+
 		if (server != null) {
 			throw new IllegalStateException("Web server is already running.");
 		}
 		if (httpPort > 0) {
 			gfProps.setPort("http-listener", httpPort);
 		}
-//		if (httpsPort > 0) {
-//			gfProps.setPort("https-listener", httpsPort);
-//		}
+		if (httpsPort > 0) {
+			gfProps.setPort("https-listener", httpsPort);
+		}
 
 		server = GlassFishRuntime.bootstrap().newGlassFish(gfProps);
 		server.start();

war-bootstrap/src/main/java/org/duelengine/bootstrap/JettyServletServer.java

 		return "Jetty";
 	}
 
-	public void start(Map<String, String> contexts, int httpPort, int httpsPort) throws Exception {
+	public void start(Map<String, String> contexts, int httpPort, int httpsPort, String keystoreFile, String keystorePass)
+		throws Exception {
+
 		if (server != null) {
 			throw new IllegalStateException("Web server is already running.");
 		}

war-bootstrap/src/main/java/org/duelengine/bootstrap/ServletServer.java

 
 	String getName();
 
-	void start(Map<String, String> contexts, int httpPort, int httpsPort) throws Exception;
+	void start(Map<String, String> contexts, int httpPort, int httpsPort, String keystoreFile, String keystorePass)
+			throws Exception;
 
 	void stop() throws Exception;
 }

war-bootstrap/src/main/java/org/duelengine/bootstrap/TomcatServletServer.java

 import java.util.Map;
 
 import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.connector.Connector;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.ContextConfig;
 import org.apache.catalina.startup.Tomcat;
 		return "Tomcat";
 	}
 
-	public void start(Map<String, String> contexts, int httpPort, int httpsPort) throws Exception {
+	public void start(Map<String, String> contexts, int httpPort, int httpsPort, String keystoreFile, String keystorePass)
+		throws Exception {
+
 		if (server != null) {
 			throw new IllegalStateException("Web server is already running.");
 		}
 		tmpDir = new File("tomcat");
 
 		server = new Tomcat();
+		if (httpsPort > 0) {
+			Connector httpsConnector = new Connector();
+			httpsConnector.setPort(httpsPort);
+			httpsConnector.setSecure(true);
+			httpsConnector.setScheme("https");
+			httpsConnector.setAttribute("keystoreFile", keystoreFile);
+			httpsConnector.setAttribute("keystorePass", keystorePass);
+			httpsConnector.setAttribute("clientAuth", "false");
+			httpsConnector.setAttribute("sslProtocol", "TLS");
+			httpsConnector.setAttribute("SSLEnabled", true);
+			server.getService().addConnector(httpsConnector);
+		}
+
+		server.setPort(httpPort);
 		server.setBaseDir(tmpDir.getCanonicalPath());
-		server.setPort(httpPort);
 
 		boolean loadJSP = getClass().getResource("/javax/servlet/jsp/resources/jsp_2_0.xsd") != null;