优点:
一、发布:
2、将web service纳入工厂
3、Web.xml中配置CXFServlet
4、在浏览器输入网址直接返回json串:
二、调用:
//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());
}
/**
* 实体的@XmlRootElement为"user9"
* .body(new StringEntity("{\"user9\":{\"id\":88,\"name\":\"zhj88\"}}"))
* 换了provider后
* .body(new StringEntity("{\"id\":88,\"name\":\"zhj88\"}"))
* @throws ClientProtocolException
* @throws IOException
*/
//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());
}