tidy up
diff --git a/REST/org.eclipse.virgo.samples.rest/src/main/java/org/eclipse/virgo/samples/rest/RestController.java b/REST/org.eclipse.virgo.samples.rest/src/main/java/org/eclipse/virgo/samples/rest/RestController.java
index c483506..04262e9 100644
--- a/REST/org.eclipse.virgo.samples.rest/src/main/java/org/eclipse/virgo/samples/rest/RestController.java
+++ b/REST/org.eclipse.virgo.samples.rest/src/main/java/org/eclipse/virgo/samples/rest/RestController.java
@@ -29,16 +29,34 @@
/**
* <p>
* {@link RestController} is a Spring MVC controller class which handles REST requests.
+ * <p/>
+ * GET requests specify a user id, e.g.:
+ *
+ * <pre>
+ * GET /rest/users/roy HTTP/1.1
+ * Accept: application/json
+ * </pre>
+ *
+ * whereas PUT requests specify a user id, a name, and a web site, e.g.:
+ *
+ * <pre>
+ * PUT /rest/users/glyn/Glyn%20Normington/underlap.blogspot.com HTTP/1.1
+ * </pre>
+ *
+ * Note: the web site parameter must not include "http://" since Tomcat rejects the proper encoding of this string.
* </p>
- * Drive this, for example, as follows:
+ * you can use curl to drive this program as follows:
*
* <pre>
* curl -i -H "Accept: application/json" http://localhost:8080/rest/users/roy
+ * curl -i -X PUT http://localhost:8080/rest/users/glyn/Glyn%20Normington/underlap.blogspot.com
+ * curl -i -H "Accept: application/json" http://localhost:8080/rest/users/glyn
* </pre>
*
* The implementation is deliberately primitive. Please consult the following for more information:
* <p/>
* <ul>
+ * <li><a href="http://en.wikipedia.org/wiki/Representational_state_transfer">Representational State Transfer</a> (Wikipedia article)
* <li><a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm">Architectural Styles and the Design of
* Network-based Software Architectures</a> (Roy Fielding's REST dissertation)</li>
* <li><a href="http://static.springsource.org/spring/docs/3.1.0.RELEASE/reference/html/mvc.html">Spring Web MVC
@@ -55,30 +73,10 @@
@Controller
public final class RestController {
- private class Info {
-
- private String name;
-
- private String site;
-
- Info(String name, String site) {
- this.name = name;
- this.site = site;
- }
-
- String getName() {
- return this.name;
- }
-
- String getSite() {
- return this.site;
- }
- }
-
private Map<String, Info> model = Collections.synchronizedMap(new HashMap<String, Info>());
public RestController() {
- this.model.put("roy", new Info("Roy T. Fielding", "http://roy.gbiv.com"));
+ this.model.put("roy", new Info("Roy T. Fielding", "roy.gbiv.com"));
}
@RequestMapping(value = "/users/{userId}", method = RequestMethod.GET, produces = "application/json")
@@ -88,8 +86,7 @@
headers.add("Content-Type", "application/json; charset=utf-8");
Info info = model.get(userId);
if (info != null) {
- return new ResponseEntity<String>("{ \"name\" : \"" + info.getName() + "\", \"site\" : \"" + info.getSite() + "\" }", headers,
- HttpStatus.OK);
+ return new ResponseEntity<String>(info.toJson(), headers, HttpStatus.OK);
} else {
return new ResponseEntity<String>("", headers, HttpStatus.NOT_FOUND);
}
@@ -101,4 +98,21 @@
this.model.put(userId, new Info(name, site));
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
}
+
+ private class Info {
+
+ private String name;
+
+ private String site;
+
+ Info(String name, String site) {
+ this.name = name;
+ this.site = site;
+ }
+
+ String toJson() {
+ return "{ \"name\" : \"" + this.name + "\", \"site\" : \"http://" + this.site + "\" }";
+ }
+ }
}
+