Cetia4 1.1文档 -1.2 Rest 框架

来源:互联网 发布:linux 自动解压war包 编辑:程序博客网 时间:2024/06/11 04:08

 

1.2 Rest 框架

正如Rest参考文档前几节所说的,http url概念是Rest框架架构形式的核心。而且,Rest把它的处理过程组织成资源,并且每个资源都被映射到一个特别的Url

Urls是全局的每个组织在他的域内维护自己的url集合。这样rest提供了一个统一的寻址模式,但是这种看起来微不足道的机制却简化了在传统的Web服务应用场景中的很多复杂性。

另外,J2EEjava servlet应用api运行在一个web容器的一个模块中,每一个web模块配置一个唯一的上下文路径,这样容器可以根据http url的第一部分转发请求从一个模块到另一个模块。

 

因此,如果一个http客户端发送一个请求到web容器,web容器根据url的第一部分确定请求转发到哪一个web模块。一旦web模块确定,就可以确定哪一个资源(例如:servletjsp,文件等)被请求。这些在官方的servlet api 规范中有更详尽的解释,但是清楚的知道对于jspservlet如何工作是很重要的。

 

 

因为Rest的架构组织主要基于url的层次结构,所以知道java servlet apiurl

映射很重要。下面的url介绍了在rest 层次下的不同资源:

 

http://example.com/forum/topics - that represents the topics in a forum

application

http://example.com/forum/topics/234 - that represents a single topic in a  forum application

http://example.com/forum/topics/234/comments - that represents

comments on a singletopic ( in the same forum application )

http://example.com/forum/topics/234/comments/34 - that represents a

single comment of a giventopic

 

根据javaservlet api 的原则,上面的部分url可以被映射为资源 若下图所示:

 

 

这意味着在cetia4框架中,所有给定的某层的请求将被映射到一个servlet,尽管通过rest来看,不同的url表示不同的资源。再者,每个url可以通过不同的http方法:getpostputdelete访问;而且,不同的请求字符串和不同的请求参数将导致不同的行为。

本指南的很大部分明确解释了框架如何简单和方便的管理这些机制,从简单的到更详尽的。

 

<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:ArialMT;panose-1:0 0 0 0 0 0 0 0 0 0;mso-font-alt:方正舒体;mso-font-charset:134;mso-generic-font-family:auto;mso-font-format:other;mso-font-pitch:auto;mso-font-signature:1 135135232 16 0 262144 0;}@font-face{font-family:"/@ArialMT";panose-1:0 0 0 0 0 0 0 0 0 0;mso-font-charset:134;mso-generic-font-family:auto;mso-font-format:other;mso-font-pitch:auto;mso-font-signature:1 135135232 16 0 262144 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->

访问一个像这样的http://example.com/forum/users会发生什么呢?在这种情况下,必须有一个servletforum应用下,并且这个servlet必须映射到/users/*路径。这一点很简单,但是很重要,必须记住。

原创粉丝点击