| 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><title>Exceptions Example</title></head> |
| 45 |
|
| 46 |
|
| 47 |
<body> |
| 48 |
<h1>Exceptions Example</h1> |
| 49 |
|
| 50 |
<p>This example demonstrates how to throw and map exceptions using ExceptionMapper in Jersey resource classes.</p> |
| 51 |
|
| 52 |
<h2>Contents</h2> |
| 53 |
|
| 54 |
<p>The example consists of just one Jersey resource:</p> |
| 55 |
<dl> |
| 56 |
<dt><code>com.sun.jersey.samples.exceptions.MyResource</code></dt> |
| 57 |
<dd>that produces a simple textual response to an HTTP GET <br/> |
| 58 |
and contains a bunch of sub-resource methods demonstrating <br/> |
| 59 |
various exception processing scenarios</dd> |
| 60 |
</dl> |
| 61 |
<p>The mapping of the URI path space is presented in the following table:</p> |
| 62 |
<table border="1"> |
| 63 |
<tr> |
| 64 |
<th>URI path</th> |
| 65 |
<th>Resource class</th> |
| 66 |
<th>HTTP methods</th> |
| 67 |
</tr> |
| 68 |
|
| 69 |
<tr> |
| 70 |
<td>/myresource</td> |
| 71 |
<td>MyResource</td> |
| 72 |
<td>GET</td> |
| 73 |
</tr> |
| 74 |
<tr> |
| 75 |
<td>/myresource/runtime</td> |
| 76 |
<td>MyResource</td> |
| 77 |
<td>GET</td> |
| 78 |
</tr> |
| 79 |
<tr> |
| 80 |
<td>/myresource/checked/ioexception</td> |
| 81 |
<td>MyResource</td> |
| 82 |
<td>GET</td> |
| 83 |
</tr> |
| 84 |
<tr> |
| 85 |
<td>/myresource/checked/mymappedexception</td> |
| 86 |
<td>MyResource</td> |
| 87 |
<td>GET</td> |
| 88 |
</tr> |
| 89 |
<tr> |
| 90 |
<td>/myresource/checked/mymappedruntimeexception</td> |
| 91 |
<td>MyResource</td> |
| 92 |
<td>GET</td> |
| 93 |
</tr> |
| 94 |
<tr> |
| 95 |
<td>/myresource/checked/mymappedthrowingexception</td> |
| 96 |
<td>MyResource</td> |
| 97 |
<td>GET</td> |
| 98 |
</tr> |
| 99 |
<tr> |
| 100 |
<td>/myresource/webapplicationexception/{status}</td> |
| 101 |
<td>MyResource</td> |
| 102 |
<td>GET</td> |
| 103 |
</tr> |
| 104 |
|
| 105 |
</table> |
| 106 |
|
| 107 |
<h2>Running the Example</h2> |
| 108 |
|
| 109 |
<p>Run the example as follows:</p> |
| 110 |
|
| 111 |
<p> run |
| 112 |
<blockquote><code>mvn clean compile exec:java</code> |
| 113 |
|
| 114 |
<p></blockquote> |
| 115 |
<p>From a web browser, visit:</p> |
| 116 |
<blockquote><code><a href="http://localhost:9998/myresource">http://localhost:9998/myresource</a></code></blockquote> |
| 117 |
<blockquote><code><a href="http://localhost:9998/myresource/runtime?ex=java.lang.NullPointerException">http://localhost:9998/myresource/runtime?ex=java.lang.NullPointerException</a></code> (see stack trace)</blockquote> |
| 118 |
<blockquote><code><a href="http://localhost:9998/myresource/checked/ioexception">http://localhost:9998/myresource/checked/ioexception</a></code> (see stack trace)</blockquote> |
| 119 |
<blockquote><code><a href="http://localhost:9998/myresource/checked/mymappedexception">http://localhost:9998/myresource/checked/mymappedexception</a></code></blockquote> |
| 120 |
<blockquote><code><a href="http://localhost:9998/myresource/checked/mymappedruntimeexception">http://localhost:9998/myresource/checked/mymappedruntimeexception</a></code></blockquote> |
| 121 |
<blockquote><code><a href="http://localhost:9998/myresource/checked/mymappedthrowingexception">http://localhost:9998/myresource/checked/mymappedthrowingexception</a></code> (see stack trace)</blockquote> |
| 122 |
<blockquote><code><a href="http://localhost:9998/myresource/webapplicationexception/505?r=errrrorMsg">http://localhost:9998/myresource/webapplicationexception/505?r=errrrorMsg</a></code> (see stacktrace)</blockquote> |
| 123 |
|
| 124 |
Where suggested see stack trace for details on exception processing. |
| 125 |
</body> |
| 126 |
</html> |