RESTFUL Service : based on Jersey
2013-08-19 20:24
267 查看
REST, Representational State Transfer, is a powerful, lightweight architecture that allows you to work with data in a comprehensive manner via HTTP. Yet, as powerful as REST is, getting it to work with your code can be a bit of a chore without some help. When it comes to coding in Java, Jersey provides the help that you need. Jersey is an open source project that simplifies the work required to adapt your Java code to REST.
In order to get started, it is helpful to have a basic understanding of the following technologies:
Maven: to define a project's dependencies,build the project and run unit tests;
Spring: to do runtime property injection;
AJAX : to make a XMLHttpRequest back to a web server;
JSON: to encapsulate information into a client-side JavaScript object.
The Jersey annotations:
Integrate with Spring:
In order to get started, it is helpful to have a basic understanding of the following technologies:
Maven: to define a project's dependencies,build the project and run unit tests;
Spring: to do runtime property injection;
AJAX : to make a XMLHttpRequest back to a web server;
JSON: to encapsulate information into a client-side JavaScript object.
The Jersey annotations:
Annot ation | Description |
---|---|
@Path | The @Path annotation's value is a relative URI path indicating where the Java class will be hosted, for example, /helloworld. You can also embed variables in the URIs to make a URI path template. For example, you could ask for the name of a user, and pass it to the application as a variable in the URI, like this, /helloworld/{username}. |
@GET | The @GET annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP GET requests. The behavior of a resource is determined by the HTTP method to which the resource is responding. |
@POST | The @POST annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP POST requests. The behavior of a resource is determined by the HTTP method to which the resource is responding |
@PUT | The @PUT annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP PUT requests. The behavior of a resource is determined by the HTTP method to which the resource is responding. |
@DELETE | The @DELETE annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP DELETE requests. The behavior of a resource is determined by the HTTP method to which the resource is responding. |
@HEAD | The @HEAD annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP HEAD requests. The behavior of a resource is determined by the HTTP method to which the resource is responding. |
@PathParam | The @PathParam annotation is a type of parameter that you can extract for use in your resource class. URI path parameters are extracted from the request URI, and the parameter names correspond to the URI path template variable names specified in the @Path class-level annotation. |
@QueryParam | The @QueryParam annotation is a type of parameter that you can extract for use in your resource class. Query parameters are extracted from the request URI query parameters. |
@Consumes | The @Consumes annotation is used to specify the MIME media types of representations a resource can consume that were sent by the client. |
@Produces | The @Produces annotation is used to specify the MIME media types of representations a resource can produce and send back to the client, for example, "text/plain". |
@Provider | The @Provider annotation is used for anything that is of interest to the JAX-RS runtime, such as MessageBodyReader and MessageBodyWriter. For HTTP requests, the MessageBodyReader is used to map an HTTP request entity body to method parameters. On the response side, a return value is mapped to an HTTP response entity body using a MessageBodyWriter. If the application needs to supply additional metadata, such as HTTP headers or a different status code, a method can return a Response that wraps the entity, and which can be built using Response.ResponseBuilder. |
<servlet> <servlet-name>REST</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.wonderfan.rest</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>REST</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>
相关文章推荐
- RESTFUL Service : based on Jersey
- Jersey 2 和 Spring 4 构建 RESTful web service
- Developing crm service based on apache cxf
- [论文笔记] A service creation environment based on end to end composition of Web services (WWW, 2005)
- Jersey – RESTful service
- Jersey(1.19.1) - Deploying a RESTful Web Service
- [论文笔记](东北大学)QoS-Driven Self-Healing Web Service Composition Based on Performance Prediction(JCST2009)
- Jersey 2.17 + Tomcat + Maven 构建restful service 实例
- My other android app : based on location based service app
- 基于RESTful Web Service 的Jersey框架与Spring完美整合
- Restful based service 的跨域调用
- RestFul WCF JSON Service with client and on Mozilla Firefox –REST Client
- 基于Jersey框架搭建Restful Java Web Service的基本步骤
- Notice of programming XML Service for Cisco IP Phone which based on Java kernel
- Jersey 2.17 + Tomcat + Maven 构建restful service 实例
- Web编程学习四: 使用Jersey来创建RESTful WebService
- Jersey Restful WebService 接收 JSON 数组 对象
- 【转载】RestFul WCF JSON Service with client and on Mozilla Firefox –REST Client
- cURL POST command line on WINDOWS RESTful service
- Cross-Domain on Jersey RESTful Web Services