Debian Codegraph @

samples/simple-atom-server/README.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <!--
3
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
6 Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
7
8 The contents of this file are subject to the terms of either the GNU
9 General Public License Version 2 only ("GPL") or the Common Development
10 and Distribution License("CDDL") (collectively, the "License"). You
11 may not use this file except in compliance with the License. You can
12 obtain a copy of the License at
13 http://glassfish.java.net/public/CDDL+GPL_1_1.html
14 or packager/legal/LICENSE.txt. See the License for the specific
15 language governing permissions and limitations under the License.
16
17 When distributing the software, include this License Header Notice in each
18 file and include the License file at packager/legal/LICENSE.txt.
19
20 GPL Classpath Exception:
21 Oracle designates this particular file as subject to the "Classpath"
22 exception as provided by Oracle in the GPL Version 2 section of the License
23 file that accompanied this code.
24
25 Modifications:
26 If applicable, add the following below the License Header, with the fields
27 enclosed by brackets [] replaced by your own identifying information:
28 "Portions Copyright [year] [name of copyright owner]"
29
30 Contributor(s):
31 If you wish your version of this file to be governed by only the CDDL or
32 only the GPL Version 2, indicate your decision by adding "[Contributor]
33 elects to include this software in this distribution under the [CDDL or GPL
34 Version 2] license." If you don't indicate a single choice of license, a
35 recipient has the option to distribute your version of this file under
36 either the CDDL, the GPL Version 2 or to extend the choice of license to
37 its licensees as provided above. However, if you add GPL Version 2 code
38 and therefore, elected the GPL Version 2 license, then the option applies
39 only if the new code is made subject to such option by the copyright
40 holder.
41
42 -->
43 <html><head><title>Simple Atom Server Example</title></head>
44
45
46 <body>
47 <h1>Simple Atom Server Example</h1>
48 <p>This example demonstrates a simple
49 Atom server that partially conforms to the
50 <a href="http://tools.ietf.org/wg/atompub/">Atom Publishing Format and Protocol</a>.
51 </p>
52 <p>Atom Entries, Atom Media Link Entries, and media are persisted to the
53 file system. The <a href="https://github.com/rometools/rome">ROME</a> Java library provides support for the parsing
54 and serializing of Atom Feed and Entry documents.</p>
55
56 <h2>Contents</h2>
57 <p>The example consists of four web resources implemented by the following:
58 </p><dl>
59 <dt><code>com.sun.jersey.samples.atomserver.resources.ServiceResource</code></dt>
60 <dd>This Java class returns the Service Document describing the Workspace that
61 contains the Atom Collection that creates, reads, updates, and deletes
62 Atom Entries.
63 </dd>
64 <dt><code>com.sun.jersey.samples.atomserver.resources.FeedResource</code></dt>
65 <dd>This Java class provides the Feed Document describing the Atom Entries
66 in the feed. It also provides support to create Atom Entries and
67 Atom Media Link Entries.
68 The resource references the EntryResource and EditEntryResource resources
69 using the Path annotation declared on the FeedResource.getEntryResource and
70 FeedResource.getEditEntryResource methods respectively.
71 </dd>
72 <dt><code>com.sun.jersey.samples.atomserver.resources.EntryResource</code></dt>
73 <dd>This Java class supports the reading of an Atom Entry or Atom Media Link Entry.
74 The reading of the media, associated with a Media Link Entry, is supported by a sub-resource
75 HTTP method.
76 </dd>
77 <dt><code>com.sun.jersey.samples.atomserver.resources.EditEntryResource</code></dt>
78 <dd>This Java class supports the read, update, and delete of an Atom Entry or
79 Atom Media Link Entry, and via a sub-resource HTTP method the read and update
80 of the media.
81 This resource extends EntryResource to inherit the reading support.
82 </dd>
83 </dl>
84 <p>The mapping of the URI path space is presented in the following table:</p>
85 <table border="1">
86 <tr>
87 <th>URI path</th>
88 <th>Resource class</th>
89 <th>HTTP methods</th>
90 </tr>
91 <tr>
92 <td>/service</td>
93 <td>ServiceResource</td>
94 <td>GET</td>
95 </tr>
96 <tr>
97 <td>/collection/</td>
98 <td>FeedResource</td>
99 <td>GET, POST</td>
100 </tr>
101 <tr>
102 <td>/collection/{entry}</td>
103 <td>EntryResource</td>
104 <td>GET</td>
105 </tr>
106 <tr>
107 <td>/collection/{entry}/media</td>
108 <td>EntryResource</td>
109 <td>GET</td>
110 </tr>
111 <tr>
112 <td>/collection/edit/{entry}</td>
113 <td>EditEntryResource</td>
114 <td>PUT, DELETE</td>
115 </tr>
116 <tr>
117 <td>/collection/edit/{entry}/media</td>
118 <td>EditEntryResource</td>
119 <td>PUT</td>
120 </tr>
121 </table>
122
123 <h2>File System Structure of Persisted Atom Feed, Atom Entries, and Media</h2>
124 <p>The Atom Feed/Entries and media are persisted to a file system.
125 The structure of the file system is as follows:
126 </p><dl>
127 <dt><code>collection</code></dt>
128 <dd>The directory where all Atom Entries and media are stored.
129 This directory is created in the current working directory where
130 the Atom Server is run.</dd>
131 <dt><code>collection/feed.xml</code></dt>
132 <dd>The persisted Atom Feed document.</dd>
133 <dt><code>collection/&lt;uuid&gt;/entry.xml</code></dt>
134 <dd>Each Atom Entry document for the Collection is stored under a unique directory
135 (a UUID) from which the Atom Entry document is persisted. The UUID
136 corresponds to the <code>atom:id</code> of the Atom Entry.</dd>
137 <dt><code>collection/&lt;uuid&gt;/media</code></dt>
138 <dd>The media (if present) of an Atom Media Link Entry.</dd>
139 </dl>
140 <p>To remove the Atom Feed document and all the Atom (or Atom Media Link)
141 Entries delete the <code>collection</code> directory.</p>
142
143 <h2>Running the Example</h2>
144 <p>Run the example as follows:</p>
145 <blockquote><pre>
146 mvn clean compile exec:java</pre></blockquote>
147 <p>This deploys the Atom server using
148 <a href="http://grizzly.java.net/">Grizzly</a>
149 </p>
150 <p>A <a href="http://wadl.java.net/#spec">WADL description</a> may be accessed at the URL:</p>
151 <blockquote><code><a href="http://localhost:9998/atom/application.wadl">http://localhost:9998/atom/application.wadl</a></code></blockquote>
152 <p>Following steps are using <a href="http://curl.haxx.se/">cURL</a> command line tool:
153 <p>Get the service document:</p>
154 <blockquote><pre>curl http://127.0.0.1:9998/atom/service</pre></blockquote>
155 <p>This returns the following sevice document:</p>
156 <blockquote><pre>&lt;service xmlns="http://purl.org/atom/app#"
157 xmlns:atom="http://www.w3.org/2005/Atom"&gt;
158 &lt;workspace&gt;
159 &lt;atom:title&gt;Service&lt;/atom:title&gt;
160 &lt;collection href="http://localhost:9998/atom/collection"&gt;
161 &lt;atom:title&gt;Entries&lt;/atom:title&gt;
162 &lt;categories&gt;
163 &lt;atom:category term="storage" scheme="urn:storage" label="storage" /&gt;
164 &lt;/categories&gt;
165 &lt;/collection&gt;
166 &lt;/workspace&gt;
167 &lt;/service&gt;</pre></blockquote>
168 <p>The service document contains one workspace with one collection.</p>
169 <p>Create a media link entry:</p>
170 <blockquote><pre>curl -i -X POST --data "Something is rotten in the state of Denmark" -HContent-type:text/plain http://127.0.0.1:9998/atom/collection</pre></blockquote>
171 <p>Get the Atom Feed document:</p>
172 <blockquote><pre>curl http://127.0.0.1:9998/atom/collection</pre></blockquote>
173 <p>which returns the following:</p>
174 <blockquote><pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
175 &lt;feed xmlns="http://www.w3.org/2005/Atom" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"&gt;
176 &lt;title>Feed&lt;/title&gt;
177 &lt;link rel="self" href="http://127.0.0.1:9998/atom/collection" /&gt;
178 &lt;entry>
179 &lt;title>Media Entry&lt;/title&gt;
180 &lt;link rel="self" href="http://127.0.0.1:9998/atom/collection/bdac4727-cbc3-4c37-ad1e-206672bc48dd" /&gt;
181 &lt;link rel="edit" href="http://127.0.0.1:9998/atom/collection/edit/bdac4727-cbc3-4c37-ad1e-206672bc48dd" /&gt;
182 &lt;link rel="edit-media" href="http://127.0.0.1:9998/atom/collection/edit/bdac4727-cbc3-4c37-ad1e-206672bc48dd/media" /&gt;
183 &lt;id>bdac4727-cbc3-4c37-ad1e-206672bc48dd&lt;/id&gt;
184 &lt;updated>2011-03-23T05:51:28Z&lt;/updated&gt;
185 &lt;content type="TEXT" src="<b>http://127.0.0.1:9998/atom/collection/bdac4727-cbc3-4c37-ad1e-206672bc48dd/media</b>" /&gt;
186 &lt;/entry&gt;
187 &lt;/feed&gt;
188 </pre></blockquote>
189 <p>The Atom Feed document contains one Atom Media Link Entry. The
190 <code>atom:content</code> contains a link to the media. (Note that the UUIDs
191 and hence the URIs will be different than those shown in this example. Substitute the UUID
192 in the example for the one returned rather than copying and
193 pasting these commands directly.)
194 The Atom Entry document, which will be the same as the <code>entry</code>
195 element in the Atom Feed document, can be retrived from the URI of the
196 <code>link</code> element with the <code>self</code> or <code>edit</code> value
197 for the <code>rel</code> attribute. The <code>id</code> element contains the
198 unique ID of the entry, which is a UUID.
199 </p><p>Get the media:</p>
200 <blockquote><pre>curl http://127.0.0.1:9998/atom/collection/bdac4727-cbc3-4c37-ad1e-206672bc48dd/media</pre></blockquote>
201 <p>which returns:</p>
202 <blockquote><pre>Something is rotten in the state of Denmark</pre></blockquote>
203 <p>Updating the media:</p>
204 <blockquote><pre>curl -X PUT --data "Hamlet said: Something is rotten in the state of Denmark" -HContent-type:text/plain http://127.0.0.1:9998/atom/collection/edit/bdac4727-cbc3-4c37-ad1e-206672bc48dd/media</pre></blockquote>
205 <p>The entry now has an updated time when the entry is retrieved:</p>
206 <blockquote><pre>curl http://127.0.0.1:9998/atom/collection/bdac4727-cbc3-4c37-ad1e-206672bc48dd</pre></blockquote>
207 <p>which returns:</p>
208 <blockquote><pre>&lt;entry xmlns="http://www.w3.org/2005/Atom"&gt;
209 &lt;title>Media Entry&lt;/title&gt;
210 &lt;link rel="self" href="http://localhost:9998/atom/collection/bdac4727-cbc3-4c37-ad1e-206672bc48dd" /&gt;
211 &lt;link rel="edit-media" href="http://localhost:9998/atom/collection/edit/bdac4727-cbc3-4c37-ad1e-206672bc48dd/media" /&gt;
212 &lt;link rel="edit" href="http://localhost:9998/atom/collection/edit/bdac4727-cbc3-4c37-ad1e-206672bc48dd/" /&gt;
213 &lt;id>bdac4727-cbc3-4c37-ad1e-206672bc48dd&lt;/id&gt;
214 &lt;updated><b>2011-03-23T06:12:46Z</b>&lt;/updated&gt;
215 &lt;content type="TEXT" src="http://localhost:9998/atom/collection/bdac4727-cbc3-4c37-ad1e-206672bc48dd/media" /&gt;
216 &lt;/entry&gt;</pre></blockquote>
217
218 <p>Delete the Atom Entry:</p>
219 <blockquote><pre>curl -X DELETE http://localhost:9998/atom/collection/edit/bdac4727-cbc3-4c37-ad1e-206672bc48dd</pre></blockquote>
220 <p>The <code>edit</code> link is used to delete the entry. Retrieving
221 the Atom Feed document:</p>
222 <blockquote><pre>curl http://localhost:9998/atom/collection</pre></blockquote>
223 <p>returns a feed with no entries:</p>
224 <blockquote><pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
225 &lt;feed xmlns="http://www.w3.org/2005/Atom" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"&gt;
226 &lt;title>Feed&lt;/title&gt;
227 &lt;link rel="self" href="http://localhost:9998/atom/collection" /&gt;
228 &lt;/feed&gt;</pre></blockquote>
229 </body></html>