1.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Sat Nov 07 23:26:03 2009 +0100
1.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Mon Jan 11 10:16:57 2010 +0100
1.3 @@ -29,6 +29,7 @@
1.4 import com.sun.jersey.api.container.httpserver.HttpServerFactory;
1.5 import com.sun.jersey.api.core.PackagesResourceConfig;
1.6 import com.sun.jersey.api.core.ResourceConfig;
1.7 +import com.sun.jersey.api.json.JSONWithPadding;
1.8 import com.sun.jersey.spi.resource.Singleton;
1.9 import com.sun.net.httpserver.HttpServer;
1.10 import cz.xelfi.quoridor.webidor.User;
1.11 @@ -45,7 +46,9 @@
1.12 import javax.ws.rs.Path;
1.13 import javax.ws.rs.Produces;
1.14 import javax.ws.rs.QueryParam;
1.15 +import javax.ws.rs.WebApplicationException;
1.16 import javax.ws.rs.core.MediaType;
1.17 +import javax.ws.rs.core.Response.Status;
1.18
1.19 /**
1.20 *
1.21 @@ -67,21 +70,17 @@
1.22 path = new File(prop);
1.23 path.mkdirs();
1.24 loggedIn = new HashMap<UUID, String>();
1.25 + games = new Games(new File(path, "games"), this); // NOI18N
1.26 + users = new Users(new File(path, "users"), this); // NOI18N
1.27 }
1.28
1.29 @Path("games")
1.30 public Games getGames() {
1.31 - if (games == null) {
1.32 - games = new Games(new File(path, "games"), this); // NOI18N
1.33 - }
1.34 return games;
1.35 }
1.36
1.37 @Path("users")
1.38 public Users getUsers() {
1.39 - if (users == null) {
1.40 - users = new Users(new File(path, "users"), this); // NOI18N
1.41 - }
1.42 return users;
1.43 }
1.44
1.45 @@ -128,8 +127,9 @@
1.46
1.47 @Path("login")
1.48 @GET
1.49 - @Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
1.50 - public User loggedInInfo(
1.51 + @Produces({ "application/x-javascript", MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
1.52 + public JSONWithPadding loggedInInfo(
1.53 + @QueryParam("callback") String callback,
1.54 @QueryParam("id") String id
1.55 ) throws IOException {
1.56 String ret = null;
1.57 @@ -140,7 +140,11 @@
1.58 } catch (IllegalArgumentException ex) {
1.59 // OK, happens for invalid ids
1.60 }
1.61 - return ret == null ? null : getUsers().getUserInfo(id, ret);
1.62 + if (ret == null) {
1.63 + throw new WebApplicationException(Status.UNAUTHORIZED);
1.64 + } else {
1.65 + return getUsers().getUserInfo(callback, id, ret);
1.66 + }
1.67 }
1.68
1.69 //