- 浏览: 545879 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (251)
- UML/RUP/软件工程 (0)
- DDD:领域驱动设计 (1)
- IaaS/Paas/SaaS (1)
- Hadoop/YARN (10)
- PBDP项目 (2)
- OSGi-基础 (7)
- OSGi-Aries (2)
- OSGi-SpringDM (32)
- Oracle/MySQL/SS (8)
- Felix/Equinox/Bnd (14)
- Virgo Server/Gemini (7)
- Weblogic/JBoss/Tomcat (10)
- ActiveMQ (14)
- Camel (1)
- Spring Roo/Eclipse (7)
- Java/JSP/JSF (10)
- Maven (19)
- ESB-Mule (1)
- ESB-ServiceMix (18)
- SOA/SCA/SDO (12)
- WebService/RESTful (17)
- JS/jQuery/ExtJS (4)
- Spring/JPA/MVC (15)
- SpringSecurity (5)
- BPM/jBPM (3)
- Hudson/SVN/CI (0)
- LinuxOS/虚拟化 (25)
- Office/OpenOffice (1)
- 项目管理 (5)
- POI/jFreeChart (1)
最新评论
-
panamera:
请问JMS Transport 发布的webservice 是 ...
CXF 提供的Service Transport-JMS Transpor -
jianyi296:
where is attachment.
CXF WebService Dynamic Client -
hj01kkk:
您好,我用jdbc-user-service为什么每次验证时都 ...
SpringSecurity笔记3-Authenticating Users:Authenticaton Strategy -
wufenglin1231:
你好,我在实现Mapping exceptions to re ...
RESTful 异常处理 -
xchd:
[echo] Project: common
[echo ...
Hive安装配置学习笔记
RESTful 中所有的请求都是由资源来处理的。JAX-RS API实现的资源就是一个Java Class,这个Class被Annotated了
一个或多个Annotations; 使用JAX-RS实现的RESTful Web service是一个root resource class, 这个root resource class
service expose后的访问的入口,该root resource class可以自己处理request,也可以由其sub-resource来处理request;
即RESTfule 中有两种resource type: root resource class,sub-resource
1. Basic JAX-RS annotations
(1) URI template syntax: URI template syntax
(2) Specifying HTTP verbs
- javax.ws.rs.DELETE specifies that the method maps to a DELETE.
- javax.ws.rs.GET specifies that the method maps to a GET.
- javax.ws.rs.POST specifies that the method maps to a POST.
- javax.ws.rs.PUT specifies that the method maps to a PUT.
- javax.ws.rs.HEAD specifies that the method maps to a HEAD.
(3) Root resource classes
- Class被用于Root Class需满足一下条件:
- Class 必须被标注@Path注解;
- Class必须有一个公共的构造函数用于运行期间调用;
- Class中的Method至少有一个被标注HTTP verb或@Path
例如:
package demo.hw.server; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; @Path("/customerservice/") public class CustomerService { public CustomerService() { } @GET public Customer getCustomer(@QueryParam("id") String id){ } @DELETE public Response deleteCustomer(@QueryParam("id") String id){ } @PUT public Response updateCustomer(Customer customer){ } @POST public Response addCustomer(Customer customer){ } @Path("/orders/{orderId}/") public Order getOrder(@PathParam("orderId") String orderId){ } }
(4) Resource Method
- 所有的resource method需满足一下条件:
- 必须是public;
- 必须被标准HTTP Method 注解;
- 不能有多有一个的实体参数。
A. Resource Method的Paramter有两种类型:
entity parameters;
annotated parameters.
例如:
@POST @Path("disaster/monster/giant/{id}") public void addDaikaiju(Kaiju kaiju, @PathParam("id") String id){ }
B. Resource Method的Return values
void;
any Java class for which the application has an entity provider;
a Response object;
a GenericEntity<T> object.
所有的Resource Method返回一个HTTP Status Code给Request, 当返回值是void,null时,HTTP Status Code是
200; 若返回值是除了null之外的其他值时,HTTP Status Code是204.
(5) Sub-Resource
有两种实现方式:
- Sub-Resource method: 对sub-resource直接使用HTTP verb;
- Sub-resource locator:只想一个实现了sub-resource的class.
例如:Sub-resource methods :标注@Path注解和HTTP verb注解,sub-resource method直接响应处理request
中指定的HTTP verb.
@Path("/customerservice/") public class CustomerService { @Path("/orders/{orderId}/") @GET public Order getOrder(@PathParam("orderId") String orderId) { } @Path("/orders/{orderId}/") @PUT public Order updateOrder(@PathParam("orderId") String orderId, Order order) { } @Path("/orders/") @POST public Order newOrder(Order order) { } }
例如:Sub-resource locators:没有HTTP verb注解,也不直接处理request; 而是sub-resource locator返回
一个resource class instance来处理request,同时sub-resource不能有Entity Paramters.
@Path("/customerservice/") public class CustomerService{ @Path("/orders/{orderId}/") public Order processOrder(@PathParam("orderId") String orderId){ } } public class Order{ @GET public Order getOrder(@PathParam("orderId") String orderId){ } @PUT public Order updateOrder(@PathParam("orderId") String orderId,Order order){ } }
(7) Resource selection method
JAX-RS选择resource method 算法被分成三个阶段:
A. Determine the root resource class;
B. Determine the object will handle the request;
C. Select the resource method that will handle the request.
1. Selecting from multiple resource classes
当有多个resource匹配reqauest URI时,resource class优先于sub-resource;当有多个resource class时按照
下面的条件匹配:
(1) Prefer the resource with the most literal characters in its URI template;
(2) Prefer the resource with the most variables in its URI template
(3) Prefer the resource with the most variables containing regular expressions.
2.Selecting from multiple resource methods
按照下面的条件进行匹配:
(1) Prefer resource methods over sub-resources;
(2) Prefer sub-resource methods over sub-resource locaters;
(3) Prefer methods that use the most specific values in the @Consumes annotation and the @Produces
annotation; 例如:@Consumes(text/xml) > @Consumes(text/*) > @Consumes(*/*)
(4) Prefer methods that most closely match the content type of the request body entity; HTTP Content-Type
property.
(5) Prefer methods that most closely match the content type accepted as a response; HTTP Accept property.
3.Customizing the selection process
实现org.apache.cxf.jaxrs.ext.ResourceComparator.
发表评论
-
测试RESTful WebService的客户端工具-Poster
2012-08-24 10:54 1443Poster是一款用于与WebService副去其端进行交互并 ... -
CXF开发End-to-End RESTful WebService
2012-08-23 11:12 1168下面已具体的例子演示开发End-to-End RESTful ... -
CXF 提供的Service Transport-JMS Transpor
2012-08-22 09:33 1423下面以一个例子来展示JMS Transport的功能: 1. ... -
CXF 提供的Service Transport-HTTPS Transpor
2012-08-20 11:22 1102HTTPS是HTTP和安全协议的联合,用于访问敏感的信息。HT ... -
CXF 提供的Service Transport-HTTP Transport
2012-08-20 09:32 1412完整代码参考http://springsfeng.ite ... -
基于Simple Fronted的WebService开发
2012-08-20 08:54 986采用Simple frontend方式开发WebService ... -
Web Service Context示例
2012-08-17 11:28 1354Web service context指Endpoint之间传 ... -
CXF Provider and Dispatch Services
2012-08-17 10:22 1523Provider and Dispatch services用 ... -
CXF WebService Dynamic Client
2012-08-17 09:48 5493即在在运行期间在内存中动态的生成Client(SEI和Data ... -
Contract-First方式开发WebService及WSDL2Java工具
2012-08-16 10:26 1850WSDL文件:参考附件OrderP ... -
CXF 架构
2012-08-15 10:36 1597CXF Architecture 建立在下 ... -
WebService定义及SOAP通信方式
2012-08-14 09:47 1611W3C对WebService的定义: A Web ... -
RESTful 异常处理
2012-07-27 11:42 20261. Using WebApplicaitonExceptio ... -
返回信息给Consumer
2012-07-27 10:17 1659return four types of Java const ... -
传输信息至Resource Classes and Methods
2012-07-27 08:52 1505运行期间,Parameters, fields, and be ... -
RESTful Web Services理论简介
2012-07-26 08:48 1200Representational State Transfer ...
相关推荐
RESTful Web Service 是一个使用 HTTP 和 REST 原理实现的 Web Service。通常,一个 RESTful Web Service 将定义基本资源 URI、它所支持的表示/响应 MIME,以及它所支持的操作。
通常,GET是用于获取或列出一个或多个资源,POST用于创建,PUT用于更新或替换,而DELETE则用于删除资源。 例如,GET http://host/context/employees/12345将获取ID为12345的员工的表示。这个响应表示可以是包含...
Java servlets 常被用来开发 RESTful 应用程序。如何使用 servlet 并没有固定的模式。通常,servlet 会接受请求并自己解析这个 HTTP 请求 URI,以将此请求与一个已知资源相匹配。对于 REST 服务开发,这个简单的 ...
Roy Felding 在他论文 network based software architectures 的 第五章 中首次介绍了这些原则。 这些REST的关键原则与将你的 API 分割成逻辑资源紧密相关。使用HTTP请求控制这些资源,其中,这些方法(GET, POST, ...
用于创建一致且RESTful资源请求JavaScript URL构建器,因此您不必这样做。 安装 npm i @ hikerfeed / restful - resource -- save 用法 RESTful Resource是一个JavaScript URL构建器,用于创建一致的和RESTful资源...
1. REST介绍 REpresentational State Transfer (REST) 是一种架构原则,其中将 web 服务视为资源,可以由其 URL 唯一标识。...POST - 创建资源 GET - 检索资源 PUT – 更新资源 DELETE - 删除资源
P23_同时创建父子资源_创建资源集合_Routine.Api2020_2_8.rar 使用 ASP.NET Core 杨旭 RESTful API ReSharper ApiController
本教程将指导你如何准备一个开发环境,开始使用 Jersey 框架工作,以创建基于 REST 的 Web 服务。 Jersey 框架实现 JAX-RS2.0 API ,这是建立标准规范 REST Web 服务。本教程也将教你如何设置 JDK , Tomcat 和 ...
一个在 Markdown 中构建 RESTful 文档的简单风格指南,灵感来自 。 有很多方法可以为您的 RESTful API 创建文档。 但是,有时您只想将一些简单的内容与您的 git 存储库一起发布。 该项目旨在利用创建一个简单的 ...
ngSrv 文档一个基于restful资源创建Angular.js模块的简单命令行工具安装: $ npm install -g ng-srv用法: $ ng-srv [-OPTIONS] 选项: -h, --help output usage information-V, --version output the version ...
轻松创建 RESTful API 响应 此包使您能够创建 RESTful API 响应,而无需考虑底层 HTTP 层的细节。 您提供数据,包将处理输出格式和状态代码。 在应用程序错误的情况下,也可以创建 RESTful 错误响应。 该包针对与...
P22_创建子资源POST_Routine.Api2020_2_8.rar 使用 ASP.NET Core 杨旭 RESTful API ReSharper ApiController P22 创建子资源POST 杨旭老师 ... ...Get请求信添加的数据的API地址 ...
用于创建 RESTful url 路由、呈现表单和处理给定 Mongoose 模型的创建、读取、更新和删除请求的简单生成器 安装 $ npm install crudify-mongoose RESTful 路由 为提供的 Mongoose 模型生成 RESTful url 路由。 您...
本书将指导用户如何通过REST API来生成基于ZStack企业版的私有...第二章节为特定的私有云场景,主要描述一些现实环境中的私有云部署方案,并描述如何基于ZStack提供的基本资源,通过RESTful API完成私有云场景的创建。
本资源主要用于测试ElasticSearch 的基本Restful API 操作,包括查询ES集群的状态,创建索引,给索引插入数据,删除索引,中文分词等。
spring + cxf + restful + soap 方便初学者很快上手。 注解描述 @Path注解的值是一个相对的URI路径,这个路径指定了该Java类的位置,例如/helloworld。在这个URI中可以包含变量,例如可以获取用户的姓名然后作为参数...
[奥莱理] 使用 .Net 3.5 技术创建 RESTful Web 服务 [奥莱理] RESTful .NET Build and Consume RESTful Web Services with .NET 3.5 (E-Book) ☆ 出版信息:☆ [作者信息] Jon Flanders [出版机构] 奥莱理 ...
RESTful Web Services中文版 1,3,4章 缺第二章和其他章节,源码网无色会在第一时间补齐,敬请关注本页。 本身完整目录: 目录 序.......................................I. --------------------------...
php-restful-mockery 在PHP中创建伪造的(嘲笑的)Restful API服务器以进行测试。安装将所有文件复制到运行目录。 该项目带有示例资源“用户”,可通过以下方式访问: (获取) 这将以JSON返回伪造数据。类图因为...
创建Company资源POST 成功后Status:201 Created time:602ms Date:Fri, 07 Feb 2020 11:30:21 GMT Content-Type:application/json; charset=utf-8 Server:Kestrel Transfer-Encoding:chunked Location:...