Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2013-01-24 11:32:08 -0500
committerGlyn Normington2013-01-24 11:32:08 -0500
commit2d9a277e1ae3e95dc30370140cf8c2bc4c81177b (patch)
tree9a07ae06e7d5e3ed31b6b1397fc42806a6e42efc
parentfc1108f982fd47e9815f77fdd1686520472f251f (diff)
downloadorg.eclipse.virgo.samples-2d9a277e1ae3e95dc30370140cf8c2bc4c81177b.tar.gz
org.eclipse.virgo.samples-2d9a277e1ae3e95dc30370140cf8c2bc4c81177b.tar.xz
org.eclipse.virgo.samples-2d9a277e1ae3e95dc30370140cf8c2bc4c81177b.zip
add collection GET
-rw-r--r--REST/org.eclipse.virgo.samples.rest/src/main/java/org/eclipse/virgo/samples/rest/RestController.java25
1 files changed, 25 insertions, 0 deletions
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 04262e9..1fd168f 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
@@ -14,6 +14,7 @@ package org.eclipse.virgo.samples.rest;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import javax.servlet.http.HttpServletResponse;
@@ -91,6 +92,14 @@ public final class RestController {
return new ResponseEntity<String>("", headers, HttpStatus.NOT_FOUND);
}
}
+
+ @RequestMapping(value = "/users", method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public ResponseEntity<String> getUsers() {
+ HttpHeaders headers = new HttpHeaders();
+ headers.add("Content-Type", "application/json; charset=utf-8");
+ return new ResponseEntity<String>(toJson(), headers, HttpStatus.OK);
+ }
@RequestMapping(value = "/users/{userId}/{name}/{site}", method = RequestMethod.PUT)
public void putUser(@PathVariable("userId") String userId, @PathVariable("name") String name, @PathVariable("site") String site,
@@ -99,6 +108,22 @@ public final class RestController {
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
}
+ private String toJson() {
+ StringBuffer json = new StringBuffer();
+ boolean first = true;
+ json.append("[");
+ for (String name : this.model.keySet()) {
+ if (first) {
+ first = false;
+ } else {
+ json.append(", ");
+ }
+ json.append("/rest/users/" + name);
+ }
+ json.append("]");
+ return json.toString();
+ }
+
private class Info {
private String name;

Back to the top