![]()
RESTful Java Web Services
Table of Contents
RESTful Java Web Services
Credits
About the Author
About the Reviewers
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. RESTful Architectures
What is REST?
Resources
Representation
URI
Uniform interfaces through HTTP requests
GET/RETRIEVE
POST/CREATE
PUT/UPDATE
DELETE/DELETE
Web services and the big picture
Summary
2. Accessing RESTful Services — Part 1
Getting the tools
RESTful clients
Java command-line application
Jakarta Commons HTTP Client
Java desktop application
JSP application
Servlet application
Summary
3. Accessing RESTful Services — Part 2
Getting the tools
Semantic search mashup
Application architecture
Web application definition
User interface layer
Parsing JSON structures
Servlet layer
SemanticHacker parser Servlet
Google search Servlet
Twitter search Servlet
Yahoo search Servlet
Yahoo image search Servlet
Compiling and running the application
Summary
4. RESTful Web Services Design
Designing a RESTful web service
Requirements of sample web service
Resource identification
Representation definition
XML representations
Users
Messages
JSON representations
Users
Messages
URI definition
Executing logic with RESTful URIs
Using URIs to request representation types
Summary
5. Jersey: JAX-RS
Getting the tools
JAX-RS
Jersey the JAX-RS 1.1 reference implementation
Annotations
Jersey resource
URIs
@Path
HTTP methods
@GET
@POST
@PUT
@DELETE
Relative paths in methods
URI variables
@PathParam
Input and output formats
@Consumes
@Produces
Parameters
@FormParam
Web service architecture
Persistence layer
RESTful web service implementation with Jersey
Application deployment
URI and resources
/users
HTTP GET
XML representation
JSON representation
HTTP POST
/users/{username}
HTTP GET
XML representation
JSON representation
HTTP PUT
HTTP DELETE
/messages
HTTP GET
XML representation
JSON representation
HTTP POST
/messages/{messageID}
HTTP GET
XML representation
JSON representation
HTTP DELETE
/messages/users/{username}
HTTP GET
XML representation
JSON representation
/messages/search/{search_item}
HTTP GET
XML representation
JSON representation
Using this RESTful web service
Summary
6. The Restlet Framework
Getting the tools
Restlet
Restlet 1.1
Restlet application and URI mappings
Handling HTTP requests
HTTP GET and content negotiation (HTTP Accept header)
Content negotiation and the HTTP Accept header
HTTP POST
HTTP PUT
HTTP DELETE
Implementation using Restlet 1.1
Restlet application and URI mappings
URIs and resources
/users
HTTP GET
HTTP POST
/users/{username}
HTTP GET
HTTP PUT
HTTP DELETE
/messages
/messages/{messageID}
/messages/users/{username}
/messages/search/{search_item}
Restlet 2.0
Restlet application and URI mappings
Annotations
@Get and content negotiation (HTTP Accept header)
@Post
@Put
@Delete
Implementation using Restlet 2.0
Restlet application and URI mappings
URIs and resources
/users
HTTP GET
XML representation
JSON representation
HTTP POST
/users/{username}
HTTP GET
XML representation
JSON representation
HTTP PUT
HTTP DELETE
/messages
/messages/{messageID}
/messages/users/{username}
HTTP GET
/messages/search/{search_item}
HTTP GET
Summary
7. RESTEasy: JAX-RS
Getting the tools
RESTEasy — a JAX-RS implementation
Web service architecture
RESTful web service implementation with RESTEasy
Application deployment
URI and resources
/users
/users/{username}
/messages
/messages/{messageID}
/messages/users/{username}
/messages/search/{search_item}
Summary
8. Struts 2 and the REST Plugin
Getting the tools
Struts 2
REST plugin
URI mappings
HTTP request handlers
Web service architecture
RESTful web service implementation with Struts 2
Application deployment
URIs and resources
/users and /users/{username}
HTTP GET /users
HTTP GET /users/{username}
HTTP POST /users
HTTP PUT /users/{username}
HTTP DELETE /users/{username}
/messages and /messages/{messageID}
/usermessages/{username}
/searchmessages/{search_item}
Summary
9. Restlet Clients and Servers
Getting the tools
Restlet standalone applications
Restlet clients
HTTP GET requests
HTTP POST requests
HTTP PUT requests
HTTP DELETE requests
Restlet servers
Summary
10. Security and Performance
Security
Securing web services
Custom token authentication
HTTP basic authentication
Clients and basic authentication
Servers and basic authentication
Single username and password
Tomcat realms
OAuth — accessing web services on behalf of users
Performance
High availability
Scalability
On-demand infrastructures
Performance recommendations
Summary
Index
![]()
RESTful Java Web Services
Copyright © 2009 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2009
Production Reference: 1051109
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK
ISBN 978-1-847196-46-0
www.packtpub.com
![]()
Author
Jose Sandoval
Reviewers
Atanas Roussev
Richard Wallace
Acquisition Editor
Sarah Cullington
Development Editor
Dhiraj Chandiramani
Technical Editor
Ishita Dhabalia
Copy Editor
Sanchari Mukherjee
Indexer
Rekha Nair
Editorial Team Leader
Gagandeep Singh
Project Team Leader
Lata Basantani
Project Coordinator
Srimoyee Ghoshal
Proofreader
Lynda Silwoski
Graphics
Nilesh R. Mohite
Production Coordinator
Dolly Dasilva
Cover Work
Dolly Dasilva
![]()
Jose Sandoval is a software developer based in Canada. He has played and worked with web technologies since the Mosaic web browser days. For the last 12 years he's worked or consulted for various financial institutions and software companies in North America, concentrating on large-scale Java web applications. He holds a Bachelor...