# HG changeset patch # User Jaroslav Tulach # Date 1248881060 -7200 # Node ID 373f537e01533f8c1eb3ca9ef40f14e9ba506599 # Parent 782d925cb5a1a74891462e3640ad394657ae36b0 It is possible to play the game from command line with curl diff -r 782d925cb5a1 -r 373f537e0153 webidor/nbactions.xml --- a/webidor/nbactions.xml Wed Jul 29 08:19:35 2009 +0200 +++ b/webidor/nbactions.xml Wed Jul 29 17:24:20 2009 +0200 @@ -8,8 +8,33 @@ runtime - -classpath %classpath cz.xelfi.quoridor.webidor.Main + -classpath %classpath cz.xelfi.quoridor.webidor.resources.Quoridor java + + debug + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.1.1:exec + + + runtime + -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath cz.xelfi.quoridor.webidor.resources.Quoridor + true + java + + + + profile + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.1.1:exec + + + ${profiler.args} -classpath %classpath cz.xelfi.quoridor.webidor.resources.Quoridor + profile + ${profiler.java} + + diff -r 782d925cb5a1 -r 373f537e0153 webidor/pom.xml --- a/webidor/pom.xml Wed Jul 29 08:19:35 2009 +0200 +++ b/webidor/pom.xml Wed Jul 29 17:24:20 2009 +0200 @@ -78,7 +78,7 @@ org.codehaus.mojo exec-maven-plugin - cz.xelfi.quoridor.webidor.Main + cz.xelfi.quoridor.webidor.Quoridor diff -r 782d925cb5a1 -r 373f537e0153 webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Wed Jul 29 08:19:35 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Wed Jul 29 17:24:20 2009 +0200 @@ -74,16 +74,41 @@ } @POST - public Game createGame(@QueryParam("white") String user1, @QueryParam("black") String user2) { - Game g = new Game(user1, user2); + @Produces(MediaType.APPLICATION_JSON) + public Game createGame( + @QueryParam("white") String white, + @QueryParam("black") String black + ) { + if (white == null) { + throw new IllegalArgumentException("Must specify white"); + } + if (black == null) { + throw new IllegalArgumentException("Must specify black"); + } + Game g = new Game(white, black); games.add(g); return g; } + @GET + @Path("{id}") + @Produces(MediaType.TEXT_PLAIN) + public String getBoard(@PathParam("id") String id) { + Game g = findGame(id); + if (g == null) { + throw new IllegalArgumentException("Unknown game " + id); + } + return g.getBoard().toString(); + } + @PUT @Path("{id}") - public Game applyMove(@PathParam("id") String id, @QueryParam("player") String player, @QueryParam("move") String move) - throws IllegalPositionException { + @Produces(MediaType.APPLICATION_JSON) + public Game applyMove( + @PathParam("id") String id, + @QueryParam("player") String player, + @QueryParam("move") String move + ) throws IllegalPositionException { Game g = findGame(id); if (g == null) { throw new IllegalArgumentException("Unknown game " + id); diff -r 782d925cb5a1 -r 373f537e0153 webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Wed Jul 29 08:19:35 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Wed Jul 29 17:24:20 2009 +0200 @@ -73,16 +73,21 @@ final String baseUri = "http://localhost:9998/"; final Map initParams = new HashMap(); + File home = new File(System.getProperty("user.home")); + File quoridor = new File(home, ".quoridor"); + + System.setProperty("quoridor.dir", quoridor.getPath()); + initParams.put("com.sun.jersey.config.property.packages", "cz.xelfi.quoridor.webidor.resources"); - System.out.println("Starting HttpServer..."); + System.out.println("Starting Quoridor..."); ResourceConfig rc = new PackagesResourceConfig("cz.xelfi.quoridor.webidor"); HttpServer threadSelector = HttpServerFactory.create(baseUri, rc); threadSelector.start(); System.out.println(String.format( - "Jersey app started with WADL available at %sapplication.wadl\n" + - "Try out %shelloworld\nHit enter to stop it...", baseUri, baseUri)); + "Quoridor started with WADL available at %sapplication.wadl\n" + + "Hit enter to stop it...", baseUri, baseUri)); System.in.read(); threadSelector.stop(0); System.exit(0);