Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ea62c69dffcdc27947f5e5f70fae581f72ae6b22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Spring REST sample project
==========================

This sample is a simple REST service implemented as an OSGi standard Web Application
Bundle and using Spring MVC with annotations. For more information, refer to:

org.eclipse.virgo.samples.rest/src/main/java/org/eclipse/virgo/samples/rest/RestController.java

It was tested with Virgo Server for Apache Tomcat 3.6.0.RELEASE on Java 6.

You can build and deploy it from the command line or in Eclipse.


Building and Deploying from the Command Line
============================================

Pre-req's: Java 6 or later and Ant 1.8.x or later (tested with 1.8.2).

Build the sample by changing directory to org.eclipse.virgo.samples.rest and
issuing the command:

$ ant clean jar

If the build is successful, copy:

target/artifacts/org.eclipse.virgo.samples.rest.jar

to Virgo's pickup directory and start the server. You should see the following
messages:

... <DE0004I> Starting bundle 'org.eclipse.virgo.samples.rest' version '1.0.0'. 
... <WE0000I> Starting web bundle 'org.eclipse.virgo.samples.rest' version '1.0.0' with context path '/rest'. 
... <WE0001I> Started web bundle 'org.eclipse.virgo.samples.rest' version '1.0.0' with context path '/rest'. 
... <DE0005I> Started bundle 'org.eclipse.virgo.samples.rest' version '1.0.0'.


Building and Deploying from Eclipse
===================================

Pre-req's: Java 6 or later and Eclipse Java EE Juno or later (tested with Juno SR1)

Install the Virgo IDE tooling as described here:

http://wiki.eclipse.org/Virgo/Tooling#Installation

Import the project org.eclipse.virgo.samples.rest into Eclipse. Define a Virgo
server for Virgo Server for Apache Tomcat 3.6.0.RELEASE or later. For help, refer
to the Virgo Tooling Guide at:

http://www.eclipse.org/virgo/documentation/

Start the server. Drag and drop the project org.eclipse.virgo.samples.rest onto
the server. You should see the following messages on the console:

... <DE0004I> Starting bundle 'org.eclipse.virgo.samples.rest' version '1.0.0'. 
... <WE0000I> Starting web bundle 'org.eclipse.virgo.samples.rest' version '1.0.0' with context path '/rest'. 
... <WE0001I> Started web bundle 'org.eclipse.virgo.samples.rest' version '1.0.0' with context path '/rest'. 
... <DE0005I> Started bundle 'org.eclipse.virgo.samples.rest' version '1.0.0'.


Using the Spring REST Sample
============================

From a new terminal, you can now drive the sample using curl, e.g.:

$ curl -i -H "Accept: application/json" http://localhost:8080/rest/users/roy
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=utf-8
Content-Length: 79
Date: Fri, 25 Jan 2013 11:22:59 GMT

{ "name" : "Roy T. Fielding", "invention" : "Representational State Transfer" }

$ curl -i -X PUT http://localhost:8080/rest/users/rod/Rod%20Johnson/Spring%20Framework
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Length: 0
Date: Fri, 25 Jan 2013 11:24:35 GMT

$ curl -i -H "Accept: application/json" http://localhost:8080/rest/users/rod
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=utf-8
Content-Length: 60
Date: Fri, 25 Jan 2013 11:25:11 GMT

{ "name" : "Rod Johnson", "invention" : "Spring Framework" }

$ curl -i -H "Accept: application/json" http://localhost:8080/rest/users
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=utf-8
Content-Length: 34
Date: Fri, 25 Jan 2013 11:25:37 GMT

[/rest/users/rod, /rest/users/roy]

Back to the top