基於REST與Web架構的構想

心靈小公寓發表於2016-12-01
之前學過基於SOAP的WebSerivce,最近在研究REST,不得不看Fielding的那篇博士論文《Architectural Styles and the Design of Network-based Software Architectures》,在轉入正文之前,發現他對架構是什麼的總結也很不錯:

Software architecture research investigates methods for determining how best to partition a system, how components identify and communicate with each other, how information is communicated, how elements of a system can evolve independently, and how all of the above can be described using formal and informal notations.

 

在學習一個新名詞之前,我習慣將它與我之前熟悉的名詞進行一個比較,如果這個名詞不是一個全新的事物的話。雖然這樣定位可能不一定那麼準確,因為任何新名詞的出現都是基於其特有的某些功能,但是這樣能夠幫助我快速地對新名詞建立起基本的概念,在學習的時候不至於迷失掉。

 

因為對SOA有一定了解,那對於REST,我也來對應一下。從小的範圍講,我可以把

REST與SOAP對應起來,

JSON和XML對應起來,

SOA和ROA(Resource Oriented Architecture)對應起來。

當然,從廣義地講,REST也被看做一種架構風格。

REST (Representational State Transfer) is an architectural style that is seen as an alternative to SOAP-based web services

 

深入淺出REST:http://www.infoq.com/cn/articles/rest-introduction裡列出了REST的關鍵原則:

  • 為所有“事物”定義ID
  • 將所有事物連結在一起
  • 使用標準方法
  • 資源多重表述
  • 無狀態通訊

 

當然,很多時候不會有一個權威的解釋,有很多爭論,需要自己去理解。還有一個思路就是看看圍繞這個新名詞的開源專案都有哪些,每個的定位和競爭專案,這樣也能反過來幫助理解這個概念。

 

RESTEasy:http://www.jboss.org/resteasy

RESTEasy is a JBoss project that provides various frameworks to help you build RESTful Web Services and RESTful Java applications. It is a fully certified and portable implementation of the JAX-RS specification. JAX-RS is a new JCP specification that provides a Java API for RESTful Web Services over the HTTP protocol.

 

Restlethttp://www.restlet.org/

Restlet is a comprehensive yet lightweight RESTful web framework for Java that lets you embrace the architecture style of the Web (REST) and benefit from its simplicity and scalability. By leveraging our innovative framework, you can start blending your web services, web sites and web clients into uniform web applications!

 

Jerseyhttp://jersey.java.net/

Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services. But, it is also more than the Reference Implementation. Jersey provides an API so that developers may extend Jersey to suit their needs. The governance policy is the same as the one used in the GlassFish project. We also use the same two licenses - CDDL 1.1 and GPL 2 with CPE - so, you can pick which one suites your needs better.

 

RESTEasy、Restlet和Jersey可以和CXF對比起來看。

 

Jettison: 讀寫JSON的工具集,用在CXF和XStream內 http://jettison.codehaus.org/

Jettison is a collection of Java APIs (like STaX and DOM) which read and write JSON. This allows nearly transparent enablement of JSON based web services in services frameworks like CXF or XML serialization frameworks like XStream.

 

 

如何具體使用REST?

在infoq上有篇文章“Simple JAVA and .NET SOA interoperability(”http://www.infoq.com/articles/REST-INTEROP)介紹瞭如何使用REST的風格來實現Java和.Net的整合,而且擴充套件性比較好。注意,這裡使用的是REST的風格,而不是真正的RESTful,只是將請求以REST風格的方式包裝,然後放在SOAP和message上來使用。之所以在這裡引用,因為裡面談到了用.net/java來實現client/server時可選的工具集,可以借鑑一下。

 

因為Web Service更多地是用來解決異構平臺的整合問題,所以任何一種標準技術得到廣泛的支援很重要,因為Microsoft是SOAP/ws-*陣營的堅定支持者,所以看看微軟是否支援REST也很重要。

The new WCF Web Programming Model supports REST Design

http://www.infoq.com/news/2007/05/wcf-web-programming-model

 

Camel與Restlet的整合:http://camel.apache.org/restlet.html

相關文章