在Eclipse中使用Jersey和Tomcat构建RESTful WebService及其调用
RESTful Web Service(二):使用eclipse创建restful webservice 工程
RESTful Web Service(三):使用ajax创建客户端
Video:REST-Ful API Design for Spring Developer
http://www.myeclipseide.com/module-htmlpages-display-pid-7.html
Designing and Implementing RESTful Web Services with Spring
源代码:https://github.com/spring-guides/tut-rest
JAX-RS
Java API for xml-Restful Webservice
webservice resource class
Lifecycle:
- Pre-request(JAX-RS default)
- Singleton (ensures only one instance of this class is created by Jersey per web-application)
Consumes and Produces用于设置默认的mime数据类型,该resource类可以接受和产生这些类型。主要分为以下7种mime类型:
text/plain;
text/html;
application/xml;
application/json;
application/xml+application/json;
application/x-www-form-urlencoded;application/atom+xml;
Resource class method
8种param type:
Entity
Context
MatrixParam
QueryParam
PathParam
FormParam
CookieParam
HeaderParam
测试rs resource类
访问 主机端口+项目名+拦截的路径+application.wadl就可以了。
http://localhost:8080/restTest/rest/application.wadl
也可以使用myeclipse的REST Web Services Explorer(只能在32位windows下面使用!)
还有一种url测试工具是Firefox的Poster,Firefox也有一个插件,但是使用起来没有myeclipse那个好用。
表一. RESTful Web 服务示例
方法/资源 | 资源集合, URI 如: | 成员资源,URI 如: |
GET | 列出资源集合的所有成员。 | 检索标识为 1234 的资源的表示形式。 |
PUT | 使用一个集合更新(替换)另一个集合。 | 更新标记为 1234 的数字资源。 |
POST | 在集合中创建数字资源,其 ID 是自动分配的。 | 在下面创建一个子资源。 |
DELETE | 删除整个资源集合。 | 删除标记为 1234 的数字资源。 |
//
用于构建 RESTful Web 服务的多层架构
2009 年 8 月 03 日
Eric Newcomer谈RESTFul事务与Web Service事务的区别
使用MyEclipse快速开发的几篇好文章(myeclipse官方被墙)
1.僵还是老的la,看myeclipse的spring mvc3 scaffolding 完胜sts
官网连接
MyEclipse for Spring 10.0: Spring 3.0 MVC Scaffolding
Scaffolding a Spring 3.0 MVC CRUD application in minutes
这个里面有个restful的option,但是选了以后根本不能作为restful webservice。
所以找到了下面这篇文章:
-Scaffolding a Google Web Toolkit (GWT) 2.1 and Spring CRUD application in minutes
News: Code generation for Spring MVC3, JQuery, JPA2 CRUD Application
相关的几本书籍
RESTful Web APIs
RESTful Web Services Cookbook: Solutions for Improving Scalability and Simplicity
March 11, 2010
REST in Practice: Hypermedia and Systems Architecture
RESTful Java with Jax-RS (Animal Guide)
December 4, 2009Restful Web Services
工具1:RESTClient是一个用于测试RESTful Web services的Java客户端
工具2:Myeclipse RESTful WebServices Explorer (很遗憾,不支持windows 64位系统)
http://code.fosshub.com/WizToolsorg-RESTClient/downloads
另外firefox浏览器也有RestClient的插件(这个用起来很方便)
在myeclipse中,右键工程根目录选择MyEclipse=>Test with RESTful WebServices Explorer 将会打开测试窗口。
浏览中的地址为:http://localhost:8080/restblog/services/application.wadl 首先/services是由servlet拦截。如果在浏览器中浏览该地址,将得到一个xml文件。这个文件叫web service application description language。顾名思义他是一个服务描述文件。
一些应用restful风格的实际案例:
1.jrest4guice
https://code.google.com/p/jrest4guice/向大家推荐一个REST的Java实现,并附加有例子
特点:
* 基于GUICE,内置带事务的JPA实现* 零配置式服务声明* 服务的自动扫描注册* 非侵入式,用户不需要实现特定的接口来实现Restful服务* 支持Post. Get. Put. Delete操作* 灵活的注入(支持上下文环境request/response以及参数的自动注入)* 与JAAS的无缝集成* 支持分布式资源对象