優點:
Ø Ø Restful 風格的 web service 是直接通過 http 協定通信。 是以,可以直接通過浏覽器通路服務方法 相對于 soap 格式的 web service 更快,不愈要聲稱用戶端代碼。
一、釋出:
Ø 導入依賴 jar Ø 定制 RetFul 風格的 web service Ø 将 web service 納入工廠 Ø Web.xml 中配置CXFServlet 1、 定制 RestFul 風格的 web service

2、将web service納入工廠
3、Web.xml中配置CXFServlet
4、在浏覽器輸入網址直接傳回json串:
二、調用:
1、通過 apache 的HttpClient的Fluent發起http請求調用,導入jar, 則在項目中需要調用 RestFul 的 web 服務的位置可以 使用上述檔案中的api,即通過以上支援,已然可以在項目的任意一個位置調用 RestFul的Web-Service 2、調用執行個體:先建立一個測試類,下面是各種方式的例子。
//get
@Test
public void testHTTP() throws ClientProtocolException, IOException{
System.out.println(Request.Get("http://localhost:8989/ws_cxf_spring_rest/rest/wsRest/rest9/query/xxx")
.execute().returnContent().asString());
}
//post
@Test
public void testHTTP2() throws ClientProtocolException, IOException{
System.out.println(Request.Post("http://localhost:8989/ws_cxf_spring_rest/rest/wsRest/rest9/insert")
.body(new StringEntity("{\"user9\":{\"id\":99,\"name\":\"zhj9\"}}"))
.setHeader("content-type", "application/json")
.execute());
}
//put
@Test
public void testHTTP3() throws ClientProtocolException, IOException{
System.out.println(Request.Put("http://localhost:8989/ws_cxf_spring_rest/rest/wsRest/rest9/update")
.body(new StringEntity("{\"id\":88,\"name\":\"zhj88\"}"))
.setHeader("content-type", "application/json")
.execute().returnContent().asString());
}
//delete
@Test
public void testHTTP4() throws ClientProtocolException, IOException{
System.out.println(Request.Delete("http://localhost:8989/ws_cxf_spring_rest/rest/wsRest/rest9/delete/11")
.execute().returnContent().asString());
}