Building RESTful Web Services using jersey and Apache Tomcat

Source: Internet
Author: User
Tags tomcat apache tomcat

Introduction to RESTful Web Services

REST was presented in a doctoral dissertation by Roy Fielding in 2000, and he was one of the chief authors of the HTTP Specification 1.0 and version 1.1.

The most important concept in REST is resource (resources), which is identified with a global ID (usually using a URI). The client application uses the HTTP method (Get/post/put/delete) to manipulate the resource or resource set. RESTful Web services are Web services that are implemented using the HTTP and REST principles. Typically, RESTful Web services should define the following:

The base/root URI of the Web service, such as Http://host/<appcontext>/resources.

Supports MIME-type response data, including Json/xml/atom, and so on.

A collection of operations supported by the service (for example, POST, get, put, or DELETE).

Table 1 shows the resource URIs and HTTP methods used in a typical RESTful Web service.

Table 1. RESTful WEB Services Sample

method/resource Resource collection, URI such as:
http://host/<appctx>/resources
member resources, URI such as:
http://host/ <appctx>/resources/1234
Lists all members of the resource collection.
put
post
delete delete marked as1234 of digital resources.

JSR 311 (jax-rs) and Jersey

The proposal for a JSR 311 or jax-rs (Java API for RESTful Web Services) began in 2007, 1.0 and finalized in October 2008. Currently, JSR 311 version 1.1 is still in the draft phase. The goal of the JSR is to provide a set of APIs to simplify the development of restful WEB services.

Before JAX-RS specifications, there are frameworks such as Restlet and resteasy that can help you implement RESTful Web services, but they are not intuitive. Jersey is a reference implementation of Jax-rs, which contains three main parts.

Core server: By providing standardized annotations and APIs in JSR 311, you can develop RESTful Web services in an intuitive way.

Core client: The Jersey client API helps you communicate easily with REST services.

Integration (integration): Jersey also provides libraries that can easily integrate Spring, Guice, and Apache Abdera.

In the following sections of this article, I've covered all of these components, but I'm more focused on the core servers.

Building RESTful Web Services

I'll start with the "Hello World" application that can be integrated into Tomcat. The application will lead you through the process of setting up the environment and involve the basics of Jersey and Jax-rs.

Then, I'll introduce more complex applications, delve into the nature and characteristics of jax-rs, such as multiple MIME type representations, JAXB support, and so on. I'll extract some code snippets from the sample to introduce the important concepts.

Hello World: The first Jersey Web project

To set up your development environment, you need the following:

Ide:eclipse IDE for JEE (v3.4+) or IBM Rational application Developer 7.5

Java SE5 or later

Web Container: Apache Tomcat 6.0 (Jetty and others can also)

Jersey Library: Jersey 1.0.3 Archive, containing all required libraries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.