1.1 --- a/webidor/nbactions.xml Wed Jul 29 08:19:35 2009 +0200
1.2 +++ b/webidor/nbactions.xml Wed Jul 29 17:24:20 2009 +0200
1.3 @@ -8,8 +8,33 @@
1.4 </goals>
1.5 <properties>
1.6 <exec.classpathScope>runtime</exec.classpathScope>
1.7 - <exec.args>-classpath %classpath cz.xelfi.quoridor.webidor.Main</exec.args>
1.8 + <exec.args>-classpath %classpath cz.xelfi.quoridor.webidor.resources.Quoridor</exec.args>
1.9 <exec.executable>java</exec.executable>
1.10 </properties>
1.11 </action>
1.12 + <action>
1.13 + <actionName>debug</actionName>
1.14 + <goals>
1.15 + <goal>process-classes</goal>
1.16 + <goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
1.17 + </goals>
1.18 + <properties>
1.19 + <exec.classpathScope>runtime</exec.classpathScope>
1.20 + <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath cz.xelfi.quoridor.webidor.resources.Quoridor</exec.args>
1.21 + <jpda.listen>true</jpda.listen>
1.22 + <exec.executable>java</exec.executable>
1.23 + </properties>
1.24 + </action>
1.25 + <action>
1.26 + <actionName>profile</actionName>
1.27 + <goals>
1.28 + <goal>process-classes</goal>
1.29 + <goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
1.30 + </goals>
1.31 + <properties>
1.32 + <exec.args>${profiler.args} -classpath %classpath cz.xelfi.quoridor.webidor.resources.Quoridor</exec.args>
1.33 + <profiler.action>profile</profiler.action>
1.34 + <exec.executable>${profiler.java}</exec.executable>
1.35 + </properties>
1.36 + </action>
1.37 </actions>
2.1 --- a/webidor/pom.xml Wed Jul 29 08:19:35 2009 +0200
2.2 +++ b/webidor/pom.xml Wed Jul 29 17:24:20 2009 +0200
2.3 @@ -78,7 +78,7 @@
2.4 <groupId>org.codehaus.mojo</groupId>
2.5 <artifactId>exec-maven-plugin</artifactId>
2.6 <configuration>
2.7 - <mainClass>cz.xelfi.quoridor.webidor.Main</mainClass>
2.8 + <mainClass>cz.xelfi.quoridor.webidor.Quoridor</mainClass>
2.9 </configuration>
2.10 </plugin>
2.11 </plugins>
3.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Wed Jul 29 08:19:35 2009 +0200
3.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Wed Jul 29 17:24:20 2009 +0200
3.3 @@ -74,16 +74,41 @@
3.4 }
3.5
3.6 @POST
3.7 - public Game createGame(@QueryParam("white") String user1, @QueryParam("black") String user2) {
3.8 - Game g = new Game(user1, user2);
3.9 + @Produces(MediaType.APPLICATION_JSON)
3.10 + public Game createGame(
3.11 + @QueryParam("white") String white,
3.12 + @QueryParam("black") String black
3.13 + ) {
3.14 + if (white == null) {
3.15 + throw new IllegalArgumentException("Must specify white");
3.16 + }
3.17 + if (black == null) {
3.18 + throw new IllegalArgumentException("Must specify black");
3.19 + }
3.20 + Game g = new Game(white, black);
3.21 games.add(g);
3.22 return g;
3.23 }
3.24
3.25 + @GET
3.26 + @Path("{id}")
3.27 + @Produces(MediaType.TEXT_PLAIN)
3.28 + public String getBoard(@PathParam("id") String id) {
3.29 + Game g = findGame(id);
3.30 + if (g == null) {
3.31 + throw new IllegalArgumentException("Unknown game " + id);
3.32 + }
3.33 + return g.getBoard().toString();
3.34 + }
3.35 +
3.36 @PUT
3.37 @Path("{id}")
3.38 - public Game applyMove(@PathParam("id") String id, @QueryParam("player") String player, @QueryParam("move") String move)
3.39 - throws IllegalPositionException {
3.40 + @Produces(MediaType.APPLICATION_JSON)
3.41 + public Game applyMove(
3.42 + @PathParam("id") String id,
3.43 + @QueryParam("player") String player,
3.44 + @QueryParam("move") String move
3.45 + ) throws IllegalPositionException {
3.46 Game g = findGame(id);
3.47 if (g == null) {
3.48 throw new IllegalArgumentException("Unknown game " + id);
4.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Wed Jul 29 08:19:35 2009 +0200
4.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Wed Jul 29 17:24:20 2009 +0200
4.3 @@ -73,16 +73,21 @@
4.4 final String baseUri = "http://localhost:9998/";
4.5 final Map<String, String> initParams = new HashMap<String, String>();
4.6
4.7 + File home = new File(System.getProperty("user.home"));
4.8 + File quoridor = new File(home, ".quoridor");
4.9 +
4.10 + System.setProperty("quoridor.dir", quoridor.getPath());
4.11 +
4.12 initParams.put("com.sun.jersey.config.property.packages",
4.13 "cz.xelfi.quoridor.webidor.resources");
4.14
4.15 - System.out.println("Starting HttpServer...");
4.16 + System.out.println("Starting Quoridor...");
4.17 ResourceConfig rc = new PackagesResourceConfig("cz.xelfi.quoridor.webidor");
4.18 HttpServer threadSelector = HttpServerFactory.create(baseUri, rc);
4.19 threadSelector.start();
4.20 System.out.println(String.format(
4.21 - "Jersey app started with WADL available at %sapplication.wadl\n" +
4.22 - "Try out %shelloworld\nHit enter to stop it...", baseUri, baseUri));
4.23 + "Quoridor started with WADL available at %sapplication.wadl\n" +
4.24 + "Hit enter to stop it...", baseUri, baseUri));
4.25 System.in.read();
4.26 threadSelector.stop(0);
4.27 System.exit(0);