| 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-2011 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>JsonFromJaxb 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>JsonFromJaxb Example</h1> |
| 56 |
<p>This example demonstrates how to use JSON representation of JAXB based resources. |
| 57 |
<p>A simple web application is presented with two resources: a flight list and a aircraft type list. A client can obtain |
| 58 |
the former list or update it using XML or JSON representation. The second list is read-only and shows how to provide JSON array using List<JAXBBean> objects. |
| 59 |
|
| 60 |
|
| 61 |
<h2>Contents</h2> |
| 62 |
<p>The flight list web resource is implemented by <code>com.sun.jersey.samples.jsonfromjaxb.resources.FlightList</code> class. |
| 63 |
The aircraft type list web resource is implemented by <code>com.sun.jersey.samples.jsonfromjaxb.resources.AircraftTypeList</code> class. |
| 64 |
<p>The mapping of the URI path space is presented in the following table:</p> |
| 65 |
<table border="1"> |
| 66 |
<tr> |
| 67 |
<th>URI path</th> |
| 68 |
<th>Resource class</th> |
| 69 |
<th>HTTP methods</th> |
| 70 |
</tr> |
| 71 |
|
| 72 |
<tr> |
| 73 |
<td>/flights/</td> |
| 74 |
<td>FlightList</td> |
| 75 |
<td>GET, PUT</td> |
| 76 |
</tr> |
| 77 |
|
| 78 |
<tr> |
| 79 |
<td>/aircrafts/</td> |
| 80 |
<td>AircraftTypeList</td> |
| 81 |
<td>GET</td> |
| 82 |
</tr> |
| 83 |
|
| 84 |
</table> |
| 85 |
|
| 86 |
<h2>Running the Example</h2> |
| 87 |
<p>Run the example as follows:</p> |
| 88 |
<blockquote><pre> |
| 89 |
mvn clean compile exec:java</pre></blockquote> |
| 90 |
<p>This deploys the JSON from JAXB example using |
| 91 |
<a href="http://grizzly.java.net/">Grizzly</a> |
| 92 |
</p> |
| 93 |
<p>A <a href="http://wadl.java.net/#spec">WADL description</a> may be accessed at the URL:</p> |
| 94 |
<blockquote><code><a href="http://localhost:9998/jsonfromjaxb/application.wadl">http://localhost:9998/jsonfromjaxb/application.wadl</a></code></blockquote> |
| 95 |
<p>Following steps are using <a href="http://curl.haxx.se/">cURL</a> command line tool: |
| 96 |
<p>Get the list of flights in JSON format:</p> |
| 97 |
<blockquote><pre>curl -HAccept:application/json http://localhost:9998/jsonfromjaxb/flights</pre></blockquote> |
| 98 |
|
| 99 |
<p>Get the list of flights in XML format:</p> |
| 100 |
<blockquote><pre>curl -HAccept:application/xml http://localhost:9998/jsonfromjaxb/flights</pre></blockquote> |
| 101 |
|
| 102 |
<p>Get the list of aircraft types in JSON format:</p> |
| 103 |
<blockquote><pre>curl -HAccept:application/json http://localhost:9998/jsonfromjaxb/aircrafts</pre></blockquote> |
| 104 |
|
| 105 |
<p>You can also see test classes at <code>src/main/test</code> subdirectory |
| 106 |
for detail information how to consume the service using Jersey client API</p> |
| 107 |
</body> |
| 108 |
</html> |