# HG changeset patch # User Jaroslav Tulach # Date 1268159626 -3600 # Node ID 0a71b6bd786fa79c7673e19ae74d8bb049cd7b4b # Parent ecddc9f373bba27e0c45880cf2dbcda67b212558 Allowing the server to specify real public URL diff -r ecddc9f373bb -r 0a71b6bd786f freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Thu Mar 04 19:37:58 2010 +0100 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Tue Mar 09 19:33:46 2010 +0100 @@ -41,6 +41,8 @@ import java.io.StringWriter; import java.net.URI; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -474,19 +476,28 @@ // start the server // - public static void main(String[] args) throws Exception { + public static void main(String[] params) throws Exception { + List args = new ArrayList(Arrays.asList(params)); + + String publicURL = null; + if (args.size() >= 2 && args.get(0).equals("--url")) { + publicURL = args.get(1); + args.remove(0); + args.remove(0); + } + int port = 9333; - if (args.length > 1) { - port = Integer.parseInt(args[0]); + if (args.size() > 1) { + port = Integer.parseInt(args.get(0)); } - String remoteAPI = args.length >= 2 ? args[1] : null; - String remoteStatistics = args.length >= 3 ? args[2] : null; + String remoteAPI = args.size() >= 2 ? args.get(1) : null; + String remoteStatistics = args.size() >= 3 ? args.get(2) : null; Locale.setDefault(Locale.ROOT); - Callable r = startServers(port, remoteAPI, remoteStatistics); + Callable r = startServers(port, remoteAPI, remoteStatistics, publicURL); - if (args.length < 3 || !args[args.length - 1].equals("--kill")) { + if (args.size() < 3 || !args.get(args.size() - 1).equals("--kill")) { System.out.println("Hit enter to stop it..."); System.in.read(); } else { @@ -498,7 +509,7 @@ System.exit(0); } - static Callable startServers(int port, String remoteAPI, String remoteStatistics) throws Exception { + static Callable startServers(int port, String remoteAPI, String remoteStatistics, String publicURL) throws Exception { Client client = new Client(); Client client1 = new Client(); @@ -521,9 +532,12 @@ ); final String baseUri = "http://localhost:" + port + "/"; + if (publicURL == null) { + publicURL = baseUri; + } final HttpServer server = HttpServerFactory.create(baseUri, rc); Client c3 = new Client(); - web = c3.resource(baseUri); + web = c3.resource(publicURL); server.start(); System.out.println("Quoridor started at port " + port); diff -r ecddc9f373bb -r 0a71b6bd786f freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/ChangeEmailTest.java --- a/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/ChangeEmailTest.java Thu Mar 04 19:37:58 2010 +0100 +++ b/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/ChangeEmailTest.java Tue Mar 09 19:33:46 2010 +0100 @@ -79,7 +79,7 @@ System.setProperty("quoridor.dir", dir.getPath()); stopAPI = Quoridor.start(7990); stopStatistics = Quoridor.start(7992); - stop = UI.startServers(7991, "http://localhost:7990", "http://localhost:7992"); + stop = UI.startServers(7991, "http://localhost:7990", "http://localhost:7992", null); File passwd = new File(dir, "passwd"); FileOutputStream os = new FileOutputStream(passwd); diff -r ecddc9f373bb -r 0a71b6bd786f freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java --- a/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java Thu Mar 04 19:37:58 2010 +0100 +++ b/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java Tue Mar 09 19:33:46 2010 +0100 @@ -78,7 +78,7 @@ System.setProperty("quoridor.dir", dir.getPath()); stopAPI = Quoridor.start(9990); stopStatistics = Quoridor.start(9992); - stop = UI.startServers(9991, "http://localhost:9990", "http://localhost:9992"); + stop = UI.startServers(9991, "http://localhost:9990", "http://localhost:9992", null); File passwd = new File(dir, "passwd"); FileOutputStream os = new FileOutputStream(passwd); diff -r ecddc9f373bb -r 0a71b6bd786f pom.xml --- a/pom.xml Thu Mar 04 19:37:58 2010 +0100 +++ b/pom.xml Tue Mar 09 19:33:46 2010 +0100 @@ -37,7 +37,7 @@ 1.1 1.15 1.0-SNAPSHOT - 1.59 + 1.60 1.0 1.8