Debian Codegraph @

samples/bookmark/README.html

raw
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-2012 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>
44 <head>
45 <title>Bookmark Example</title>
46 <style type="text/css"><!--
47 .figure { text-align:center;
48 margin: 20px}
49 .cliSample { background-color:lightgray }
50 --></style>
51 </head>
52
53
54 <body>
55 <h1>Bookmark Example</h1>
56 <p>This example demonstrates how to use JPA in the backend. The example is based on bookmark example
57 from the <a href="http://www.oreilly.com/catalog/9780596529260/">RESTful Web Services</a> book,
58 which was inspired by the <a href="http://delicious.com/">http://delicious.com/</a> web service.
59 </p>
60 <p>A bookmark web application is presented that is capable of maintaining users and their bookmarks.
61
62
63 <h2>Contents</h2>
64 <p>The example consists of four web resources implemented by the following:
65 </p><dl>
66 <dt><code>com.sun.jersey.samples.bookmark.resources.UsersResource</code></dt>
67 <dd>
68 The users resource that returns a list of users.
69 </dd>
70 <dt><code>com.sun.jersey.samples.bookmark.resources.UserResource</code></dt>
71 <dd>
72 The user resource that has userid, username, e-mail and password.
73 </dd>
74 <dt><code>com.sun.jersey.samples.bookmark.resources.BookmarksResource</code></dt>
75 <dd>
76 The bookmarks resource that returns a list of bookmarks for actual user resource.
77 </dd>
78 <dt><code>com.sun.jersey.samples.bookmark.resources.BookmarkResource</code></dt>
79 <dd>
80 The bookmark resource that has a bookmark uri and a long and short description.
81 </dd>
82 </dl>
83 <p>The mapping of the URI path space is presented in the following table:</p>
84 <table border="1">
85 <tr>
86 <th>URI path</th>
87 <th>Resource class</th>
88 <th>HTTP methods</th>
89 </tr>
90
91 <tr>
92 <td>/users/</td>
93 <td>UsersResource</td>
94 <td>GET</td>
95 </tr>
96 <tr>
97
98 <tr>
99 <td>/users/{userid}</td>
100 <td>UserResource</td>
101 <td>GET, PUT (used also for creating new users), DELETE</td>
102 </tr>
103
104 <tr>
105 <td>/users/{userid}/bookmarks</td>
106 <td>BookmarksResource</td>
107 <td>GET, POST</td>
108 </tr>
109
110
111 <tr>
112 <td>/users/{userid}/bookmarks/{bmid}</td>
113 <td>BookmarkResource</td>
114 <td>GET, PUT, DELETE</td>
115 </tr>
116
117 </table>
118
119 <h2>Running the Example</h2>
120
121 <p>Bookmark example runs on Glassfish 3.x application servers (<a href="http://glassfish.java.net/">http://glassfish.java.net</a>)
122 and needs a running JavaDB (<a href="http://www.oracle.com/technetwork/java/javadb/overview/index.html">http://www.oracle.com/technetwork/java/javadb/overview/index.html</a>)
123 instance for underlying data (it comes along with GlassFish).
124
125 <p>Presuming, you have installed Glassfish 3.1 <code>AS_HOME</code> variable should point to
126 your glassfish installation directory.
127
128 <h4>Building And Starting The Bookmark Service</h4>
129
130 <p>If <code>.asadminpass</code> file is missing at your home directory, you
131 will need to run the following command to get it created:
132 <pre class="cliSample">
133 $AS_HOME/bin/asadmin start-domain
134 $AS_HOME/bin/asadmin login
135 </pre>
136
137 <p>You then build and run the example by
138 <pre class="cliSample">
139 mvn package
140 $AS_HOME/bin/asadmin start-domain
141 $AS_HOME/bin/asadmin start-database
142 $AS_HOME/bin/asadmin create-jdbc-connection-pool \
143 --datasourceclassname org.apache.derby.jdbc.ClientDataSource \
144 --restype javax.sql.DataSource \
145 --property "portnumber=1527:password=REST:user=REST:serverName=localhost:databaseName=BookmarkDB:connectionAttributes=;create\=true" bookmarkPool
146 $AS_HOME/bin/asadmin create-jdbc-resource --connectionpoolid bookmarkPool jdbc/bookmarkSample
147 $AS_HOME/bin/asadmin deploy target/bookmark.war
148 </pre>
149
150 <p><b>Notice:</b> <span style="color: #f00">On Windows</span>: you might need to replace asadmin with asadmin.bat.
151 Also, because it seems there are some issues with copy-pasting backslashes,
152 you will also need to use the following one-liner instead of the above mentioned complex command:
153 <pre>
154 asadmin create-jdbc-connection-pool --datasourceclassname org.apache.derby.jdbc.ClientDataSource --restype javax.sql.DataSource --property "portnumber=1527:password=REST:user=REST:serverName=localhost:databaseName=BookmarkDB:connectionAttributes=;create\=true" bookmarkPool
155 </pre>
156 and make sure you do not miss the backslash (\) in <code>create\=true</code> part.
157
158
159 <h4>Test Client Running</h4>
160
161 <pre class="cliSample">
162 mvn test -DargLine="-Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory -DenableLogging -Djersey.test.port=8080" -Ptest
163 </pre>
164
165 </p>
166
167 <h2>TODOs</h2>
168 <ul>
169 <li>add tags</li>
170 </ul>
171
172 <h2>Links</h2>
173
174 <a href="http://java.net/projects/bpcatalog/sources/svn/content/trunk/ee5/docs/persistence/webonlyapp.html?raw=true">http://java.net/projects/bpcatalog/sources/svn/content/trunk/ee5/docs/persistence/webonlyapp.html?raw=true</a>
175
176
177 </body>
178 </html>