以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Web Services & Semantic Web Services 』  (http://bbs.xml.org.cn/list.asp?boardid=10)
----  [转帖]how to create RESTful services using CXF's HTTP binding  (http://bbs.xml.org.cn/dispbbs.asp?boardid=10&rootid=&id=54678)


--  作者:hongjunli
--  发布时间:10/31/2007 12:50:00 PM

--  [转帖]how to create RESTful services using CXF's HTTP binding
how to create RESTful services using CXF's HTTP binding

本文主要通过一个Demo来向我们展示了如何使用CXF的 HTTP 绑定来创建RESTful 服务

http://www.java2s.com/Code/Java/Web-Services-SOA/ThisdemoshowshowtocreateRESTfulservicesusingCXFsHTTPbinding.htm


This demo shows how to create RESTful services using CXF's HTTP binding.
The server in the demo creates 3 different endpoints: a RESTful XML
endpoint, a RESTful JSON endpoint, and a SOAP endpoint.

[RUNNING THE DEMO]
The demo has a class called com.acme.customer.Main which starts up various
endpoints. To start this server run the command:

$ ant server

Once it is running try going to the following URLs:

http://localhost:8080/xml/customers
http://localhost:8080/json/customers
http://localhost:8080/xml/customers/123
http://localhost:8080/json/customers/123

These will serve out XML and JSON representation of the resources.

There is an HTML page that is served by CXF so you can try using the
JSON service via Javascript. Just go to:

http://localhost:8080/test.html

Included are some example JSON and XML files so you can add or update
customers using wget. Try the following commands and look at the results:

wget --post-file add.json http://localhost:8080/json/customers
wget --post-file add.xml http://localhost:8080/xml/customers
wget --post-file update.xml http://localhost:8080/xml/customers/123

And if you are interested in SOAP you can try the SOAP endpoint:

http://localhost:8080/soap?wsdl

[RUNNING THE CLIENT]
The demo also includes a Client class which accesses data using
HTTP. To run this demo, do:

$ ant client

这个Demo的源代码请大家下载附件(XFire-CXF-restful_http_binding.zip):


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms