JimmyJin
走在架构师的大道上,学习的乐趣就在于将知识应用于具体实践中,在实战中实现知识的价值。
posts - 4,comments - 0,trackbacks - 0
这两天学习REST及其java实现框架Restlet.
具象状态传输(Representational state transferREST)是设计基于命名资源而非消息的松耦合应用程序的一种风格。构建 RESTful 应用程序的最困难的部分在于确定要公开哪些资源.个人认为它跟DDD联系的很紧密,特别是REST中的“资源”,我个人理解它就是从领域模型中的模型而来的。
我们先来看一下restlet core api吧:
restlets 

Overview of a Restlet architecture

Here is a diagram illustrating how the API composes componentsconnectorsvirtual host and applicationsApplications are in turncomposed of resources.

tutorial05
用白说来讲就是:Application通过Router 将某个URI与Resource绑定在一定,而一个componet可能含有多个Application,
还有Representation 这个类其实也很重要。Representation entityRestlet中全部的接受和返回对象都Representation类的子类。 
如在WEB APP中经常需要从一个FORM中拿到其Representation(
getWebRepresentation() )或组装成一个Representation 
Form(Representation webForm)
 ,以便客户端与服务器进行交互。我们知道REST是以资源为中心的,一个URI就代表了对这个资源的CURD操作。@Path这个注解提明了
哪个操作是由该资源的那个方法来实现的如:
@POST
@Path("add")
public String addStudent(Representation entity) { 
}
...
@DELETE
@Path("delete/{id}")
public String deleteStudent(@PathParam("id") int id) {
  int status = ResourceHelper.deleteStudent(id);
  return String.valueOf(status);
} 
representation package overriew:
Restlet 对表现层的技术支持也就是通来representation这个类来实现的,representation 
  Restlet并没有你Setvlet API那样有自已的JSP作表现的技术,它是通过将这三种模板技术整合起来而已如
 XSLTFreeMarker and Apache Velocity 
The org.restlet.representation package contains common representation data elements. Here is a hierarchy diagram with the core Representation classes:

Overview  Representation package


representations
当然restlve只是提供了一个入口,碰到要对数据库进行CURD操作时,基具体实现还是由JDBC等技术来实现.

posted on 2012-05-24 12:19 jimmy2009 阅读(365) 评论(0)  编辑  收藏 所属分类: 系统架构

只有注册用户登录后才能发表评论。


网站导航: