您的位置:首页 > 编程语言 > Java开发

使用java实现Restful webservice(Jersey)

2014-06-24 17:01 531 查看
在Eclipse中使用Jersey和Tomcat构建RESTful WebService及其调用

jersey实现rest实例

RESTful Web Service(一):概述

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 如:
http://host/<appctx>/resources
成员资源,URI 如:
http://host/<appctx>/resources/1234
GET
列出资源集合的所有成员。
检索标识为 1234 的资源的表示形式。
PUT
使用一个集合更新(替换)另一个集合。
更新标记为 1234 的数字资源。
POST
在集合中创建数字资源,其 ID 是自动分配的。
在下面创建一个子资源。
DELETE
删除整个资源集合。
删除标记为 1234 的数字资源。
//////////////////////////////


用于构建 RESTful Web 服务的多层架构



BRuce Sun, Java 架构师, IBM  



2009 年 8 月 03 日


Eric Newcomer谈RESTFul事务与Web Service事务的区别

REST深入浅出-最好的REST入门文档:

  http://www.infoq.com/cn/articles/rest-introduction

解答有关REST的十点疑惑 - 关于上面那文档的补充信息

  http://www.infoq.com/cn/articles/tilkov-rest-doubts

Roy
T. Fielding关于REST的博士学位论文

Roy的REST论文的中文版

让RESTful Web services更实用的10个技巧
@QueryParam和@PathParam比较

  


使用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。

所以找到了下面这篇文章:


一起代码,两分钟,实现 java restful webservice


2.MyEclipse
for Spring 10.0: GWT 2.1 and Spring Scaffolding




-Scaffolding a Google Web Toolkit (GWT) 2.1 and Spring CRUD application in minutes

3.springmvc3
scaffolding



News: Code generation for Spring MVC3, JQuery, JPA2 CRUD Application

相关的几本书籍

RESTful
Web APIs

这本书2013年9月份出版,算比较新,其他的书都是2010年左右出版的。
Publication Date: September 30, 2013


RESTful Web Services
Cookbook: Solutions for Improving Scalability and Simplicity

March 11, 2010


REST in Practice:
Hypermedia and Systems Architecture

September 24, 2010


RESTful Java with Jax-RS
(Animal Guide)

December 4, 2009


Restful
Web Services

测试Restful Webservice的工具

工具1:RESTClient是一个用于测试RESTful Web services的Java客户端


http://code.fosshub.com/WizToolsorg-RESTClient/downloads
另外firefox浏览器也有RestClient的插件(这个用起来很方便)

工具2:Myeclipse RESTful
WebServices Explorer (很遗憾,不支持windows 64位系统)


在myeclipse中,右键工程根目录选择MyEclipse=>Test with RESTful WebServices Explorer 将会打开测试窗口。

浏览中的地址为:http://localhost:8080/restblog/services/application.wadl 首先/services是由servlet拦截。如果在浏览器中浏览该地址,将得到一个xml文件。这个文件叫web service application description language。顾名思义他是一个服务描述文件。

[b]一些应用restful风格的实际案例:[/b]

[b]1.[b]jrest4guice[/b][/b]
https://code.google.com/p/jrest4guice/ 向大家推荐一个REST的Java实现,并附加有例子

code.google.com/p/jrest4guice/

特点:

* 基于GUICE,内置带事务的JPA实现
* 零配置式服务声明
* 服务的自动扫描注册
* 非侵入式,用户不需要实现特定的接口来实现Restful服务
* 支持Post. Get. Put. Delete操作
* 灵活的注入(支持上下文环境request/response以及参数的自动注入)
* 与JAAS的无缝集成
* 支持分布式资源对象

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: