Allowing the server to specify real public URL
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 09 Mar 2010 19:33:46 +0100
changeset 2340a71b6bd786f
parent 233 ecddc9f373bb
child 235 782848b5f533
Allowing the server to specify real public URL
freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java
freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/ChangeEmailTest.java
freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java
pom.xml
     1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Thu Mar 04 19:37:58 2010 +0100
     1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Tue Mar 09 19:33:46 2010 +0100
     1.3 @@ -41,6 +41,8 @@
     1.4  import java.io.StringWriter;
     1.5  import java.net.URI;
     1.6  import java.text.MessageFormat;
     1.7 +import java.util.ArrayList;
     1.8 +import java.util.Arrays;
     1.9  import java.util.Date;
    1.10  import java.util.HashMap;
    1.11  import java.util.List;
    1.12 @@ -474,19 +476,28 @@
    1.13      // start the server
    1.14      //
    1.15  
    1.16 -    public static void main(String[] args) throws Exception {
    1.17 +    public static void main(String[] params) throws Exception {
    1.18 +        List<String> args = new ArrayList<String>(Arrays.asList(params));
    1.19 +
    1.20 +        String publicURL = null;
    1.21 +        if (args.size() >= 2 && args.get(0).equals("--url")) {
    1.22 +            publicURL = args.get(1);
    1.23 +            args.remove(0);
    1.24 +            args.remove(0);
    1.25 +        }
    1.26 +
    1.27          int port = 9333;
    1.28 -        if (args.length > 1) {
    1.29 -            port = Integer.parseInt(args[0]);
    1.30 +        if (args.size() > 1) {
    1.31 +            port = Integer.parseInt(args.get(0));
    1.32          }
    1.33 -        String remoteAPI = args.length >= 2 ? args[1] : null;
    1.34 -        String remoteStatistics = args.length >= 3 ? args[2] : null;
    1.35 +        String remoteAPI = args.size() >= 2 ? args.get(1) : null;
    1.36 +        String remoteStatistics = args.size() >= 3 ? args.get(2) : null;
    1.37  
    1.38          Locale.setDefault(Locale.ROOT);
    1.39  
    1.40 -        Callable<Void> r = startServers(port, remoteAPI, remoteStatistics);
    1.41 +        Callable<Void> r = startServers(port, remoteAPI, remoteStatistics, publicURL);
    1.42  
    1.43 -        if (args.length < 3 || !args[args.length - 1].equals("--kill")) {
    1.44 +        if (args.size() < 3 || !args.get(args.size() - 1).equals("--kill")) {
    1.45              System.out.println("Hit enter to stop it...");
    1.46              System.in.read();
    1.47          } else {
    1.48 @@ -498,7 +509,7 @@
    1.49          System.exit(0);
    1.50      }
    1.51  
    1.52 -    static Callable<Void> startServers(int port, String remoteAPI, String remoteStatistics) throws Exception {
    1.53 +    static Callable<Void> startServers(int port, String remoteAPI, String remoteStatistics, String publicURL) throws Exception {
    1.54          Client client = new Client();
    1.55          Client client1 = new Client();
    1.56  
    1.57 @@ -521,9 +532,12 @@
    1.58          );
    1.59  
    1.60          final String baseUri = "http://localhost:" + port + "/";
    1.61 +        if (publicURL == null) {
    1.62 +            publicURL = baseUri;
    1.63 +        }
    1.64          final HttpServer server = HttpServerFactory.create(baseUri, rc);
    1.65          Client c3 = new Client();
    1.66 -        web = c3.resource(baseUri);
    1.67 +        web = c3.resource(publicURL);
    1.68          server.start();
    1.69          System.out.println("Quoridor started at port " + port);
    1.70  
     2.1 --- a/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/ChangeEmailTest.java	Thu Mar 04 19:37:58 2010 +0100
     2.2 +++ b/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/ChangeEmailTest.java	Tue Mar 09 19:33:46 2010 +0100
     2.3 @@ -79,7 +79,7 @@
     2.4          System.setProperty("quoridor.dir", dir.getPath());
     2.5          stopAPI = Quoridor.start(7990);
     2.6          stopStatistics = Quoridor.start(7992);
     2.7 -        stop = UI.startServers(7991, "http://localhost:7990", "http://localhost:7992");
     2.8 +        stop = UI.startServers(7991, "http://localhost:7990", "http://localhost:7992", null);
     2.9  
    2.10          File passwd = new File(dir, "passwd");
    2.11          FileOutputStream os = new FileOutputStream(passwd);
     3.1 --- a/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java	Thu Mar 04 19:37:58 2010 +0100
     3.2 +++ b/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java	Tue Mar 09 19:33:46 2010 +0100
     3.3 @@ -78,7 +78,7 @@
     3.4          System.setProperty("quoridor.dir", dir.getPath());
     3.5          stopAPI = Quoridor.start(9990);
     3.6          stopStatistics = Quoridor.start(9992);
     3.7 -        stop = UI.startServers(9991, "http://localhost:9990", "http://localhost:9992");
     3.8 +        stop = UI.startServers(9991, "http://localhost:9990", "http://localhost:9992", null);
     3.9  
    3.10          File passwd = new File(dir, "passwd");
    3.11          FileOutputStream os = new FileOutputStream(passwd);
     4.1 --- a/pom.xml	Thu Mar 04 19:37:58 2010 +0100
     4.2 +++ b/pom.xml	Tue Mar 09 19:33:46 2010 +0100
     4.3 @@ -37,7 +37,7 @@
     4.4        <quoridorVersion>1.1</quoridorVersion>
     4.5        <webidorVersion>1.15</webidorVersion>
     4.6        <visidorVersion>1.0-SNAPSHOT</visidorVersion>
     4.7 -      <freemarkerVersion>1.59</freemarkerVersion>
     4.8 +      <freemarkerVersion>1.60</freemarkerVersion>
     4.9        <emailerVersion>1.0</emailerVersion>
    4.10        <statisticsVersion>1.8</statisticsVersion>
    4.11    </properties>