Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2013-01-24 10:23:07 -0500
committerGlyn Normington2013-01-24 10:23:07 -0500
commit3d6dd13667ccf8db163392bc06a410fe9984ce06 (patch)
treef585e94d79e932210b99a795895ab8a32f19a9af
parent2ebf7b161ec32984b183a5404db0702ec446bfa9 (diff)
downloadorg.eclipse.virgo.samples-3d6dd13667ccf8db163392bc06a410fe9984ce06.tar.gz
org.eclipse.virgo.samples-3d6dd13667ccf8db163392bc06a410fe9984ce06.tar.xz
org.eclipse.virgo.samples-3d6dd13667ccf8db163392bc06a410fe9984ce06.zip
allow updates
-rw-r--r--REST/org.eclipse.virgo.samples.rest/src/main/java/org/eclipse/virgo/samples/rest/RestController.java46
-rw-r--r--REST/org.eclipse.virgo.samples.rest/src/main/webapp/META-INF/MANIFEST.MF29
2 files changed, 58 insertions, 17 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 a0e273e..c483506 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,12 @@
package org.eclipse.virgo.samples.rest;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -49,16 +55,50 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public final class RestController {
- @RequestMapping(value = "/users/{userId}", method = RequestMethod.GET, produces="application/json")
+ 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"));
+ }
+
+ @RequestMapping(value = "/users/{userId}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
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);
+ Info info = model.get(userId);
+ if (info != null) {
+ return new ResponseEntity<String>("{ \"name\" : \"" + info.getName() + "\", \"site\" : \"" + info.getSite() + "\" }", headers,
+ HttpStatus.OK);
} else {
return new ResponseEntity<String>("", headers, HttpStatus.NOT_FOUND);
}
}
+ @RequestMapping(value = "/users/{userId}/{name}/{site}", method = RequestMethod.PUT)
+ public void putUser(@PathVariable("userId") String userId, @PathVariable("name") String name, @PathVariable("site") String site,
+ HttpServletResponse httpServletResponse) {
+ this.model.put(userId, new Info(name, site));
+ httpServletResponse.setStatus(HttpServletResponse.SC_OK);
+ }
}
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 9089be6..07b865e 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
@@ -8,18 +8,19 @@ Bundle-Name: REST Sample Web Bundle
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.virgo.samples.rest
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.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)"
+Import-Package: javax.servlet.http;version="[2.1.0, 3.0.0)",org.eclips
+ e.virgo.web.dm;version="[3.0.0,4.0.0)",org.springframework.beans.fact
+ ory.xml;version="[3.0,4.0)",org.springframework.context.config;versio
+ n="[3.0,4.0)",org.springframework.context.support;version="[3.0,4.0)"
+ ,org.springframework.http;version="[3.0,4.0)",org.springframework.ste
+ reotype;version="[3.0,4.0)",org.springframework.util;version="[3.0,4.
+ 0)",org.springframework.web.bind.annotation;version="[3.0,4.0)",org.s
+ pringframework.web.context;version="[3.0,4.0)",org.springframework.we
+ b.context.support;version="[3.0,4.0)",org.springframework.web.servlet
+ ;version="[3.0,4.0)",org.springframework.web.servlet.config;version="
+ [3.0,4.0)",org.springframework.web.servlet.handler;version="[3.0,4.0)
+ ",org.springframework.web.servlet.mvc;version="[3.0,4.0)",org.springf
+ ramework.web.servlet.mvc.annotation;version="[3.0,4.0)",org.springfra
+ mework.web.servlet.support;version="[3.0,4.0)",org.springframework.we
+ b.servlet.view;version="[3.0,4.0)"

Back to the top