Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2013-01-24 08:32:50 -0500
committerGlyn Normington2013-01-24 08:32:50 -0500
commit2ebf7b161ec32984b183a5404db0702ec446bfa9 (patch)
treecca5786b3a667881451b8ff385103f8ecd292c8f
parent54f43bcd97ab7a7f6d7890ca47325ab1b67cbceb (diff)
downloadorg.eclipse.virgo.samples-2ebf7b161ec32984b183a5404db0702ec446bfa9.tar.gz
org.eclipse.virgo.samples-2ebf7b161ec32984b183a5404db0702ec446bfa9.tar.xz
org.eclipse.virgo.samples-2ebf7b161ec32984b183a5404db0702ec446bfa9.zip
Documentation.
-rw-r--r--REST/org.eclipse.virgo.samples.rest/src/main/java/org/eclipse/virgo/samples/rest/RestController.java31
-rw-r--r--REST/org.eclipse.virgo.samples.rest/src/main/webapp/META-INF/MANIFEST.MF19
2 files changed, 39 insertions, 11 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 0292a1f..a0e273e 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
@@ -11,6 +11,9 @@
package org.eclipse.virgo.samples.rest;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -21,6 +24,22 @@ import org.springframework.web.bind.annotation.ResponseBody;
* <p>
* {@link RestController} is a Spring MVC controller class which handles REST requests.
* </p>
+ * Drive this, for example, as follows:
+ *
+ * <pre>
+ * curl -i -H "Accept: application/json" http://localhost:8080/rest/users/roy
+ * </pre>
+ *
+ * The implementation is deliberately primitive. Please consult the following for more information:
+ * <p/>
+ * <ul>
+ * <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
+ * framework<a/></li>
+ * <li><a href="http://static.springsource.org/spring-roo/reference/html/base-json.html">Spring Roo JSON Add-On</a></li>
+ * </ul>
+ * <p/>
*
* <strong>Concurrent Semantics</strong><br />
*
@@ -30,10 +49,16 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public final class RestController {
- @RequestMapping(value = "/users/{userId}", method = RequestMethod.GET)
+ @RequestMapping(value = "/users/{userId}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
- public String getUser(@PathVariable("userId") String userId) {
- return userId;
+ public ResponseEntity<String> getUser(@PathVariable("userId") String userId) {
+ HttpHeaders headers = new HttpHeaders();
+ headers.add("Content-Type", "application/json; charset=utf-8");
+ if ("roy".equals(userId)) {
+ return new ResponseEntity<String>("{ \"name\" : \"Roy T. Fielding\", \"site\" : \"http://roy.gbiv.com/\" }", headers, HttpStatus.OK);
+ } else {
+ return new ResponseEntity<String>("", headers, HttpStatus.NOT_FOUND);
+ }
}
}
diff --git a/REST/org.eclipse.virgo.samples.rest/src/main/webapp/META-INF/MANIFEST.MF b/REST/org.eclipse.virgo.samples.rest/src/main/webapp/META-INF/MANIFEST.MF
index b0d799e..9089be6 100644
--- a/REST/org.eclipse.virgo.samples.rest/src/main/webapp/META-INF/MANIFEST.MF
+++ b/REST/org.eclipse.virgo.samples.rest/src/main/webapp/META-INF/MANIFEST.MF
@@ -11,12 +11,15 @@ Web-ContextPath: rest
Import-Package: org.eclipse.virgo.web.dm;version="[3.0.0,4.0.0)",org.s
pringframework.beans.factory.xml;version="[3.0,4.0)",org.springframew
ork.context.config;version="[3.0,4.0)",org.springframework.context.su
- pport;version="[3.0,4.0)",org.springframework.web.context;version="[3
- .0,4.0)",org.springframework.web.context.support;version="[3.0,4.0)",
- org.springframework.web.servlet;version="[3.0,4.0)",org.springframewo
- rk.web.servlet.config;version="[3.0,4.0)",org.springframework.web.ser
- vlet.handler;version="[3.0,4.0)",org.springframework.web.servlet.mvc;
- version="[3.0,4.0)",org.springframework.web.servlet.mvc.annotation;ve
- rsion="[3.0,4.0)",org.springframework.web.servlet.support;version="[3
- .0,4.0)",org.springframework.web.servlet.view;version="[3.0,4.0)"
+ pport;version="[3.0,4.0)",org.springframework.http;version="[3.0,4.0)
+ ",org.springframework.stereotype;version="[3.0,4.0)",org.springframew
+ ork.util;version="[3.0,4.0)",org.springframework.web.bind.annotation;
+ version="[3.0,4.0)",org.springframework.web.context;version="[3.0,4.0
+ )",org.springframework.web.context.support;version="[3.0,4.0)",org.sp
+ ringframework.web.servlet;version="[3.0,4.0)",org.springframework.web
+ .servlet.config;version="[3.0,4.0)",org.springframework.web.servlet.h
+ andler;version="[3.0,4.0)",org.springframework.web.servlet.mvc;versio
+ n="[3.0,4.0)",org.springframework.web.servlet.mvc.annotation;version=
+ "[3.0,4.0)",org.springframework.web.servlet.support;version="[3.0,4.0
+ )",org.springframework.web.servlet.view;version="[3.0,4.0)"

Back to the top