Ability to use a free port for running the query server, using this ability in tests.
1.1 --- a/remoting/server/tests/run-declarative-tests Mon Dec 26 19:35:24 2011 +0100
1.2 +++ b/remoting/server/tests/run-declarative-tests Wed Jan 04 14:03:32 2012 +0100
1.3 @@ -39,11 +39,16 @@
1.4 do_index
1.5
1.6 (cd ../web/web.main; ant jar)
1.7 -java -jar ../web/web.main/dist/web.main.jar cache >/dev/null 2>/dev/null &
1.8 +OUT=`mktemp`;
1.9 +trap "rm $OUT" EXIT
1.10 +java -jar ../web/web.main/dist/web.main.jar --freeport cache >"$OUT" &
1.11
1.12 trap "kill %1" EXIT
1.13
1.14 -sleep 1s; #XXX
1.15 +while [ -z "$PORT" ] ; do
1.16 + sleep 1s;
1.17 + PORT=`cat "$OUT" | grep "Running on port: " | cut -d ':' -f 2 | tr -d ' '`;
1.18 +done
1.19
1.20 rm -rf results
1.21 mkdir results
1.22 @@ -52,7 +57,7 @@
1.23 REQUEST=`cat $tc/request`;
1.24 TEST_NAME=`basename $tc`;
1.25 RESULT_FILE="`pwd`/results/TEST-$TEST_NAME.xml"
1.26 - if wget -O - "http://localhost:9998$REQUEST" | diff -w - $tc/response; then
1.27 + if wget -O - "http://localhost:${PORT}$REQUEST" | diff -w - $tc/response; then
1.28 write_passed_results_file
1.29 else
1.30 write_failure_results_file
2.1 --- a/remoting/server/web/web.main/src/web/main/WebMain.java Mon Dec 26 19:35:24 2011 +0100
2.2 +++ b/remoting/server/web/web.main/src/web/main/WebMain.java Wed Jan 04 14:03:32 2012 +0100
2.3 @@ -46,10 +46,16 @@
2.4 import com.sun.grizzly.tcp.http11.GrizzlyAdapter;
2.5 import com.sun.grizzly.tcp.http11.GrizzlyRequest;
2.6 import com.sun.grizzly.tcp.http11.GrizzlyResponse;
2.7 +import com.sun.jersey.api.container.httpserver.HttpServerFactory;
2.8 +import com.sun.jersey.api.core.PackagesResourceConfig;
2.9 import com.sun.jersey.spi.container.servlet.ServletContainer;
2.10 +import com.sun.net.httpserver.HttpServer;
2.11 import java.io.File;
2.12 import java.io.IOException;
2.13 import java.net.URL;
2.14 +import java.util.ArrayList;
2.15 +import java.util.Arrays;
2.16 +import java.util.List;
2.17 import org.netbeans.modules.jackpot30.backend.base.CategoryStorage;
2.18 import org.netbeans.modules.jackpot30.backend.base.RelStreamHandlerFactory;
2.19
2.20 @@ -62,21 +68,43 @@
2.21 /**
2.22 * @param args the command line arguments
2.23 */
2.24 - public static void main(String... args) throws IOException {
2.25 - if (args.length != 1 && args.length != 2) {
2.26 - System.err.println("Usage: java -jar " + WebMain.class.getProtectionDomain().getCodeSource().getLocation().getPath() + " <cache> [<static-content>]");
2.27 + public static void main(String... origArgs) throws IOException, InterruptedException {
2.28 + boolean freePort = false;
2.29 +
2.30 + List<String> args = new ArrayList<String>(Arrays.asList(origArgs));
2.31 +
2.32 + if (args.size() > 0 && "--freeport".equals(args.get(0))) {
2.33 + freePort = true;
2.34 + args.remove(0);
2.35 + }
2.36 +
2.37 + if (args.size() != 1 && args.size() != 2) {
2.38 + System.err.println("Usage: java -jar " + WebMain.class.getProtectionDomain().getCodeSource().getLocation().getPath() + " [--freeport] <cache> [<static-content>]");
2.39 return ;
2.40 }
2.41
2.42 - CategoryStorage.setCacheRoot(new File(args[0]));
2.43 + if (freePort && args.size() == 2) {
2.44 + System.err.println("Usage: java -jar " + WebMain.class.getProtectionDomain().getCodeSource().getLocation().getPath() + " [--freeport] <cache> [<static-content>]");
2.45 + System.err.println("<static-content> not supported in combination with --freeport option");
2.46 + return ;
2.47 + }
2.48 +
2.49 + CategoryStorage.setCacheRoot(new File(args.get(0)));
2.50
2.51 // org.netbeans.ProxyURLStreamHandlerFactory.register();
2.52 URL.setURLStreamHandlerFactory(new RelStreamHandlerFactory());
2.53 -
2.54 +
2.55 + if (freePort) {
2.56 + final HttpServer f = HttpServerFactory.create("http://127.0.0.1:0/", new PackagesResourceConfig("org.netbeans.modules.jackpot30"));
2.57 + f.start();
2.58 + System.out.println("Running on port: " + f.getAddress().getPort());
2.59 + return;
2.60 + }
2.61 +
2.62 GrizzlyWebServer gws;
2.63
2.64 - if (args.length == 2) {
2.65 - gws = new GrizzlyWebServer(9998, args[1]);
2.66 + if (args.size() == 2) {
2.67 + gws = new GrizzlyWebServer(9998, args.get(1));
2.68 } else {
2.69 gws = new GrizzlyWebServer(9998);
2.70 }