Jersey: REST-style Web Service development framework in Java specifications

Source: Internet
Author: User
Sun is working to establish standards for RESt-style Web services. The specifications are as follows:
JSRs: Java Specification Requests
JSR 311: JAX-RS: The Java TMAPI for RESTful Web Services
Link: http://jcp.org/en/jsr/detail? Id = 311
At the same time, the reference implementation of this specification, Jersery, is gradually becoming more mature. It is now Version 0.7. For details, refer to https://jersey.dev.java.net /.

From the JAX-RS norms and Jersey development, and WADL definition can see Sun in RESTful Web Service above the effort, can also predict, not on the future, java-compliant REST-style Web services will become the mainstream (at least the mainstream in the Java field), and Yahoo, Amazon, and Google will also be favored by REST-style Web services, it also shows the development and future of RESt-style Web services.

Let's get down to the point and introduce Jersey, a REST-style service development framework.

Jersey is the reference implementation of the JAX-RS and is now Version 0.7, but not the final version because the JAX-RS has not yet reached the final version. But now Jersey is enough to make Java fans coding well. First, Jersey adopts the Annotation mechanism, and all HTTP-related parameter settings adopt Annotation implementation. Therefore, during programming, it seems that we are still targeting POJO, without understanding the pain of distributed or J2EE programming, you only need to know some key Annotation users. Secondly, Jersey is a development platform. We can expand our needs. For example, in message format, although Jersey already provides basic Java data types, JSON, XML, and other types, we can easily extend our own format. Third, services established by Jersey can be deployed easily on the lightweight Server that comes with JDK 6. The process is extremely simple (see the following example ). Fourth, Jersey's services can be easily deployed as servlets and support various J2EE containers. Fifth, Jersey can automatically generate WADL for our services (see http://research.sun.com/techrep/2006/abstract-153.html ). In addition, Jersey has many advantages to find at the cost.

Well, let's take an example first.

The following Students class creates a Students resource, mainly including the student name and age information, using the student name as the URI of the positioning resource, the student details (name and age) are provided ). The Server class assumes the role of the Server and uses the lightweight Server that comes with JDK 6. In fact, you only need two lines of code to create and start the Server, let's take a look at the following code.

Import java. util. HashMap;
Import javax. ws. rs. GET;
Import javax. ws. rs. Path;
Import javax. ws. rs. PathParam;
Import javax. ws. rs. ProduceMime;
Import javax. ws. rs. core. Context;
Import javax. ws. rs. core. HttpHeaders;
Import javax. ws. rs. core. MultivaluedMap;
Import javax. ws. rs. core. UriInfo;
Import com. sun. ws. rest. spi. resource. Singleton;
/**
 *
* @ Author dongtg
 *
*/
@ Singleton
@ Path ("student/{name }")
Public class Students {
 
HashMap <String, Integer> nameage = new HashMap <String, Integer> ();
// String name;
Int age = 20;
 
Public Students ()
 {
Nameage. put ("aaa", 20 );
Nameage. put ("bbb", 30 );
 }

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.