Java Reference
In-Depth Information
Customer customer = client . target
( "http://localhost:8080/services/customers/1" )
. request (). get ( Customer . class );
System . out . println ( "Should never get here!" );
}
catch
catch ( NotFoundException e )
{
System . out . println ( "Caught error!" );
String error = e . getResponse (). readEntity ( String . class );
System . out . println ( error );
}
}
When this client code runs, the server will throw a CustomerNotFoundException , which is
converted into a 404 response back to the client. The client code handles the error as dis-
cussed in Exception Handling and throws a javax.ws.rs.NotFoundException , which is
handled in the catch block. The error message is extracted from the HTTP error response and
displayed to the console.
Build and Run the Example Program
Perform the following steps:
1. Open a command prompt or shell terminal and change to the ex07_1 directory of the
workbook example code.
2. Make sure your PATH is set up to include both the JDK and Maven, as described in
Chapter 17 .
3. Perform the build and run the example by typing maven install .
Search WWH ::




Custom Search