使用java实现Restful webservice(Jersey)

在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-in troduction
 
解答有关REST的十点疑惑 - 关于上面那文档的补充信息 
  http://www.infoq.com
/cn/articles/tilkov- rest-doubts 


  

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

  这本书2013年9月份出版,算比较新,其他的书都是2010年左右出版的。
   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。顾名思义他是一个服务描述文件。


一些应用restful风格的实际案例:

1.jrest4guice

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


特点:

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


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值