Skip to Content
RESTful Java Web Services, Second Edition
book

RESTful Java Web Services, Second Edition

by Jobinesh Purushothaman
September 2015
Intermediate to advanced
354 pages
8h 27m
English
Packt Publishing
Content preview from RESTful Java Web Services, Second Edition

Exception handling in JAX-RS

Exceptions in Java are a way to tell the client that an abnormal condition has occurred while executing specific statements in the code. In this section, you will see how a REST resource method handles exceptions.

Reporting errors using ResponseBuilder

The javax.ws.rs.core.Response.ResponseBuilder class provides easy-to-use utility methods for creating the javax.ws.rs.core.Response instance by using a builder pattern. The Response instance can hold metadata, such as the HTTP status code, along with the entity body. The REST resource method can return the Response object to report back the status of the REST API call to the caller.

For example, the following resource method returns HTTP 404 Not Found (represented by the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

RESTful Java Web Services - Third Edition

RESTful Java Web Services - Third Edition

Balachandar Bogunuva Mohanram
RESTful Web Services

RESTful Web Services

Leonard Richardson, Sam Ruby

Publisher Resources

ISBN: 9781784399092Supplemental Content