This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
bookmark
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved. The contents of this file are subject to the terms of either the GNU General Public License Version 2 only ("GPL") or the Common Development and Distribution License("CDDL") (collectively, the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the License at http://glassfish.java.net/public/CDDL+GPL_1_1.html or packager/legal/LICENSE.txt. See the License for the specific language governing permissions and limitations under the License. When distributing the software, include this License Header Notice in each file and include the License file at packager/legal/LICENSE.txt. GPL Classpath Exception: Oracle designates this particular file as subject to the "Classpath" exception as provided by Oracle in the GPL Version 2 section of the License file that accompanied this code. Modifications: If applicable, add the following below the License Header, with the fields enclosed by brackets [] replaced by your own identifying information: "Portions Copyright [year] [name of copyright owner]" Contributor(s): If you wish your version of this file to be governed by only the CDDL or only the GPL Version 2, indicate your decision by adding "[Contributor] elects to include this software in this distribution under the [CDDL or GPL Version 2] license." If you don't indicate a single choice of license, a recipient has the option to distribute your version of this file under either the CDDL, the GPL Version 2 or to extend the choice of license to its licensees as provided above. However, if you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then the option applies only if the new code is made subject to such option by the copyright holder. --> <html> <head> <title>Bookmark Example</title> <style type="text/css"><!-- .figure { text-align:center; margin: 20px} .cliSample { background-color:lightgray } --></style> </head> <body> <h1>Bookmark Example</h1> <p>This example demonstrates how to use JPA in the backend. The example is based on bookmark example from the <a href="http://www.oreilly.com/catalog/9780596529260/">RESTful Web Services</a> book, which was inspired by the <a href="http://delicious.com/">http://delicious.com/</a> web service. </p> <p>A bookmark web application is presented that is capable of maintaining users and their bookmarks. <h2>Contents</h2> <p>The example consists of four web resources implemented by the following: </p><dl> <dt><code>com.sun.jersey.samples.bookmark.resources.UsersResource</code></dt> <dd> The users resource that returns a list of users. </dd> <dt><code>com.sun.jersey.samples.bookmark.resources.UserResource</code></dt> <dd> The user resource that has userid, username, e-mail and password. </dd> <dt><code>com.sun.jersey.samples.bookmark.resources.BookmarksResource</code></dt> <dd> The bookmarks resource that returns a list of bookmarks for actual user resource. </dd> <dt><code>com.sun.jersey.samples.bookmark.resources.BookmarkResource</code></dt> <dd> The bookmark resource that has a bookmark uri and a long and short description. </dd> </dl> <p>The mapping of the URI path space is presented in the following table:</p> <table border="1"> <tr> <th>URI path</th> <th>Resource class</th> <th>HTTP methods</th> </tr> <tr> <td>/users/</td> <td>UsersResource</td> <td>GET</td> </tr> <tr> <tr> <td>/users/{userid}</td> <td>UserResource</td> <td>GET, PUT (used also for creating new users), DELETE</td> </tr> <tr> <td>/users/{userid}/bookmarks</td> <td>BookmarksResource</td> <td>GET, POST</td> </tr> <tr> <td>/users/{userid}/bookmarks/{bmid}</td> <td>BookmarkResource</td> <td>GET, PUT, DELETE</td> </tr> </table> <h2>Running the Example</h2> <p>Bookmark example runs on Glassfish 3.x application servers (<a href="http://glassfish.java.net/">http://glassfish.java.net</a>) 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>) instance for underlying data (it comes along with GlassFish). <p>Presuming, you have installed Glassfish 3.1 <code>AS_HOME</code> variable should point to your glassfish installation directory. <h4>Building And Starting The Bookmark Service</h4> <p>If <code>.asadminpass</code> file is missing at your home directory, you will need to run the following command to get it created: <pre class="cliSample"> $AS_HOME/bin/asadmin start-domain $AS_HOME/bin/asadmin login </pre> <p>You then build and run the example by <pre class="cliSample"> mvn package $AS_HOME/bin/asadmin start-domain $AS_HOME/bin/asadmin start-database $AS_HOME/bin/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 $AS_HOME/bin/asadmin create-jdbc-resource --connectionpoolid bookmarkPool jdbc/bookmarkSample $AS_HOME/bin/asadmin deploy target/bookmark.war </pre> <p><b>Notice:</b> <span style="color: #f00">On Windows</span>: you might need to replace asadmin with asadmin.bat. Also, because it seems there are some issues with copy-pasting backslashes, you will also need to use the following one-liner instead of the above mentioned complex command: <pre> 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 </pre> and make sure you do not miss the backslash (\) in <code>create\=true</code> part. <h4>Test Client Running</h4> <pre class="cliSample"> mvn test -DargLine="-Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory -DenableLogging -Djersey.test.port=8080" -Ptest </pre> </p> <h2>TODOs</h2> <ul> <li>add tags</li> </ul> <h2>Links</h2> <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> </body> </html>