Java Reference
In-Depth Information
The last thing we have to do is modify our
Application
class to register the
Excep-
tionMapper
:
src/main/java/com/restfully/shop/services/ShoppingApplication.java
public
public class
class
ShoppingApplication
ShoppingApplication
extends
extends
Application
{
private
private
Set
<
Object
>
singletons
=
new
new
HashSet
<
Object
>();
private
private
Set
<
Class
<?>>
classes
=
new
new
HashSet
<
Class
<?>>();
public
public
ShoppingApplication
()
{
singletons
.
add
(
new
new
CustomerResource
());
classes
.
add
(
CustomerNotFoundExceptionMapper
.
class
);
}
@Override
public
public
Set
<
Class
<?>>
getClasses
()
{
return
return
classes
;
}
@Override
public
public
Set
<
Object
>
getSingletons
()
{
return
return
singletons
;
}
}
The Client Code
The client code for this example is very simple. We make a GET request to a customer re-
source that doesn't exist:
src/test/java/com/restfully/shop/test/CustomerResourceTest.java
package
package
com
.
restfully
.
shop
.
test
;
import
import
javax.ws.rs.NotFoundException
javax.ws.rs.NotFoundException
;
...
@Test
public
public
void
void
testCustomerResource
()
throws
throws
Exception
{
try
try
{