使用JSR311规范快速的构建REST应用

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    使用JSR311规范快速的构建REST应用 - Presentation Transcript

    1. 使用JSR311(JAX-RS)规范快速的构建REST应用
      TonyDeng
      http://friendfeed.com/tonydeng
      http://twitter.com/wolfdeng
      http://delicious.com/wolf.deng
      http://wolfchina.blogbus.com
    2. 分享内容
      JSR311(JAX-RS)规范介绍
      常用的JAX-RSAPI介绍
      JAX-RS框架介绍
      ROA(面向资源架构)
      如何使用JAX-RS框架快速的构建REST应用
      代码演示
    3. JSR311(JAX-RS)项目介绍
      JSR311 正式称呼 JAX-RS:Java API for RESTful Web Services
      JSR311是Sun在2007年2月发布的一个基于annotation的API
      JSR311项目地址https://jsr311.dev.java.net/
      版本:
      jsr311-1.0(稳定版)已经通过了JCP的投票同意
      jsr311-1.1(草稿版)
    4. JAX-RS的特性
      提供annotation的API规范
      提出WADL(Web Application Description Language)规范来描述REST应用
      https://wadl.dev.java.net
      JSR-311 提供一组注释,相关类和接口都可以用来将Java 对象作为 Web 资源展示。该规范假定 HTTP 是底层网络协议。
      它使用注释提供 URI 和相应资源类之间的清晰映射,以及 HTTP 方法与 Java 对象方法之间的映射。
      API 支持广泛的 HTTP 实体内容类型,包括 HTML、XML、JSON、GIF、JPG 等。
      它还将提供所需的插件功能,以允许使用标准方法通过应用程序添加其他类型。
    5. 常用的JAX-RSAPI介绍
      @Context
      Resource的上下文内容,比如URI,HttpRequest
      @Provider
      扩展自己的MediaType支持
      @path
      定义Resource的URI
      @GET
      httpgetmethod
      @POST
      httppostmethod
      @PUT
      http put method
      @DELETE
      http deletemethod
      @Produces
      定义Resource返回的MediaType
      @Consumes
      定义Resource接受的MediaType
      @PathParam
      定义URI中的变量
      @FormParam
      定义form表单中的变量
    6. JAX-RS框架介绍
    7. 实现JAX-RS规范的框架
      Restlet
      应该是最早的REST框架,在JAX-RS之前就已经有了。
      http://www.restlet.org/
      Jersey
      Sun提供的实现参考
      https://jersey.dev.java.net/
      RESTEasy
      Jboss的项目
      http://www.jboss.org/resteasy/
      CXF
      Apache的一级项目
      由Xfire项目和Celtix项目(一个开源的ESB项目)合并后演变过来
      http://cxf.apache.org
    8. Restlet介绍
      项目地址
      http://www.restlet.org
      http://www.noelios.com/
      Restlet可以说是最早的REST框架,JAX-RS规范出来之前,它就已经存在了。
      Restlet是在Servlet的之上发展的这套框架
      http://www.restlet.org/about/introduction
      Restlet并不是完全按照JAX-RS规范来实现
      Restlet有自己的一套API
      稳定版本1.1.5,jax-rs 1.0的实现
      最新版本2.0-m4,jax-rs 1.0的实现
      特性:
      http://www.restlet.org/about/features
      Native REST support
      Available editions
      Complete Web Server
      Available Connectors
      Available Representations
      Flexible configuration
      Security
      Scalability
      Upcoming features
    9. Jersey介绍
      项目地址:
      https://jersey.dev.java.net
      Jersey是Sun提供的实现参考。由JAX-RS项目的成员来实现。
      从某种意义上说,最符合JAX-RS规范
      Jersey项目名称的来由:由于Jersey项目的主管非常喜欢自行车运动,而且当时正是环法自行车赛期间,所以起了这个名称。同时也透露出对Jersey这个项目的期望。
      稳定版本为1.0.3,jax-rs1.0的实现
      最新版本1.1.2-ea,jax-rs1.1的实现
      特性:
      提供Client,Service/Grizzly,WADL&JSON
      Test Framework
      Spring integration
      Guice integration
      MIME multipart
      Client & Apache HTTP Client
      Atom & Apache Abdera Simple HTTP server
      Oautch support
    10. RESTEasy介绍
      项目地址:
      http://www.jboss.org/resteasy/
      RESTEasy是有JBOSS提供的实现。
      顾名思义,这个项目的初衷就是如何更好的让使用者很方便容易的创建REST应用
      最新稳定版本为1.1.GA,jax-rs 1.0的实现
      特性:
      Fully certified JAX-RS implementation
      Portable to any app-server/Tomcat that runs on JDK 5 or higher
      Embeddedable server implementation for junit testing
      Client framework that leverages JAX-RS annotations so that you can write HTTP clients easily (JAX-RS only defines server bindings)
      Client "Browser" cache. Supports HTTP 1.1 caching semantics including cache revalidation
      Server in-memory cache. Local response cache. Automatically handles ETag generation and cache revalidation
      Rich set of providers for: XML, JSON, YAML, Fastinfoset, Multipart, XOP, Atom, etc.
      JAXB marshalling into XML, JSON, Jackson, Fastinfoset, and Atom as well as wrappers for maps, arrays, lists, and sets of JAXB Objects.
      GZIP content-encoding. Automatic GZIP compression/decompression suppport in client and server frameworks
      Asynchronous HTTP (Comet) abstractions for JBoss Web, Tomcat 6, and Servlet 3.0
      Asynchronous Job Service.
      Rich interceptor model.
      EJB, Seam, Guice, Spring, and Spring MVC integration
    11. CXF介绍
      项目地址:
      http://cxf.apache.org
      Apache的一级项目
      • 由Xfire项目和Celtix项目(一个开源的ESB项目)合并后演变过来
      更加偏向SOA
      稳定版本:2.2.3,jax-rs 1.0的实现。
      最新版本:2.3-SNAPSHOT,jax-rs 1.0的实现
      支持标准:
      JAX-WS, JSR-181, SAAJ, JAX-RS
      SOAP 1.1, 1.2, WS-I BasicProfile, WS-Security, WS-Addressing, WS-RM, WS-Policy
      WSDL 1.1
      MTOM
    12. ROA 面向资源的架构
    13. ROA(面向资源架构)
      世间万物皆为资源
      REST对信息的核心抽象就是资源
      资源并不是具体的存储对象,它是对事物概念上的一个抽象
      Resource是有层次的
      Resource的定义是一门大学问
      面向资源的建模
      DDD(Domain-Driven Design),面向对象建模,ER建模
    14. 如何规划ResourceURI
      使用URITemplate来描述ResourceURI的定义
      http://bitworking.org/projects/URI-Templates/spec/draft-gregorio-uritemplate-03.html
    15. URI对比
      家族话题
      /familyBBS?method=GET&json={“familyId”:193,”bbsId”:412}
      /family/193/topic/412
      • 家族投票
      /familyVote?method=GET&json={“familyId”:193,”bbsId”:412}
      /family/193/topic/412/vote
    16. 例子:社区家族URI规划
      家族
      /familys
      /familys/@self/{uid}/{page},{pageSize}
      /familys/@friends/{uid}/{page},{pageSize}
      家族分类
      /familys/type
      家族标签
      /familys/tags
      /familys/tags/@hot/{num}
      家族重名
      /familys/names/@userd/{fname}
      单个家族信息
      /family/{fid}
      家族图标
      /family/{fid}/icon
      家族设置
      /family/{fid}/setting
      家族成员
      /family/{fid}/members
      /family/{fid}/members/@manager
      家族转让
      /family/{fid}/transfer
    17. 例子:社区家族URI规划
      家族话题
      /family/{fid}/topics
      /family/{fid}/topics/{page},{pageSize}
      /family/{fid}/topics/@elite /{page},{pageSize}
      /family/{fid}/topics/@vote /{page},{pageSize}
      家族话题
      /family/{fid}/topic/{tid}
      /family/{fid}/topic/{tid}/vote
      /family/{fid}/topic/{tid}/vote/members
      /family/{fid}/topic/{tid}/ {page},{pageSize}
      /family/{fid}/topic/{tid}/reply
      /family/{fid}/topic/{tid}/reply/{rid}
    18. 如何使用JAX-RS框架快速的构建REST应用
    19. 选用框架
      Build Tools
      Maven 2.2.0
      Jersey
      jsr311 1.0
      jersey-server 1.0.3
      jersey-json 1.0.3
      jersey-spring 1.0.3
      JAXB
      jaxb-api 2.1
      Sun jaxb-impl 2.1.6
      Spring
      spring 2.5.6
    20. 代码演示
    21. 谢谢

    + Tony DengTony Deng, 2 weeks ago

    custom

    34 views, 0 favs, 1 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 34
      • 31 on SlideShare
      • 3 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 0
    Most viewed embeds
    • 3 views on http://wolfchina.blogbus.com

    more

    All embeds
    • 3 views on http://wolfchina.blogbus.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?