| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 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 |
<html><head><title>Simple Console Example</title></head> |
| 44 |
|
| 45 |
|
| 46 |
<body> |
| 47 |
<h1>Simple Console Example</h1> |
| 48 |
<p>This example demonstrates how to develop RESTful web services with the |
| 49 |
embedded Grizzly server.</p> |
| 50 |
|
| 51 |
<h2>Contents</h2> |
| 52 |
<p>The example consists of three Java classes and one HTML file:</p> |
| 53 |
<dl> |
| 54 |
<dt><code>com.sun.ws.rest.sample.console.Main</code></dt> |
| 55 |
<dd>Contains the main function which starts and stops the HTTP server.</dd> |
| 56 |
<dt><code>com.sun.jersey.samples.console.resource.Colours</code></dt> |
| 57 |
<dd>A resource class that can produce two different representations of a |
| 58 |
list of colors. The list can be filtered by a client-supplied query |
| 59 |
parameter. |
| 60 |
The resource references the Form resource using the |
| 61 |
Path annotation declared on the Colours.getColours method. |
| 62 |
</dd> |
| 63 |
<dt><code>com.sun.jersey.samples.console.resource.Form</code></dt> |
| 64 |
<dd>A resource class that produces a form in response to an HTTP GET, |
| 65 |
processes the content of the form when submitted, and produces a |
| 66 |
table of the submitted values in respose to the form being posted.</dd> |
| 67 |
<dt><code>form.html</code></dt> |
| 68 |
<dd>A static HTML file that is returned by the Form resource.</dd> |
| 69 |
</dl> |
| 70 |
<p>The mapping of the URI path space is presented in the following table:</p> |
| 71 |
<table border="1"> |
| 72 |
<tr> |
| 73 |
<th>URI path</th> |
| 74 |
<th>Resource class</th> |
| 75 |
<th>HTTP methods</th> |
| 76 |
</tr> |
| 77 |
<tr> |
| 78 |
<td>/form</td> |
| 79 |
<td>Form</td> |
| 80 |
<td>GET, POST</td> |
| 81 |
</tr> |
| 82 |
<tr> |
| 83 |
<td>/form/colours</td> |
| 84 |
<td>Colours</td> |
| 85 |
<td>GET</td> |
| 86 |
</tr> |
| 87 |
</table> |
| 88 |
|
| 89 |
<h2>Running the Example</h2> |
| 90 |
<p>Run the example as follows:</p> |
| 91 |
<blockquote><pre> |
| 92 |
mvn clean compile exec:java</pre></blockquote> |
| 93 |
|
| 94 |
<p>From a web browser, visit:</p> |
| 95 |
<blockquote><code><a href="http://127.0.0.1:9998/resources/form">http://127.0.0.1:9998/resources/form</a></code></blockquote> |
| 96 |
<p>Fill in the form and submit it. Note that the pull-down list of colors |
| 97 |
is populated dynamically. Enter part of a color name in the hint box |
| 98 |
to see a filtered list of colors containing the hint.</p> |
| 99 |
<p>You can see the complete list of colors at:</p> |
| 100 |
<blockquote><code><a href="http://127.0.0.1:9998/resources/form/colours">http://127.0.0.1:9998/resources/form/colours</a></code></blockquote> |
| 101 |
<p>Or see only those colors containing the letter 'r':</p> |
| 102 |
|
| 103 |
<blockquote><code><a href="http://127.0.0.1:9998/resources/form/colours?match=r">http://127.0.0.1:9998/resources/form/colours?match=r</a></code></blockquote> |
| 104 |
<p>A <a href="http://wadl.java.net/#spec">WADL description</a> may be accessed at the URL:</p> |
| 105 |
<blockquote><code><a href="http://127.0.0.1:9998/resources/application.wadl">http://127.0.0.1:9998/resources/application.wadl</a></code></blockquote> |
| 106 |
|
| 107 |
</body></html> |