锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲一级黄色,最近97中文超碰在线,精品不卡一区二区三区http://www.aygfsteel.com/justinchen/category/35770.htmlzh-cnWed, 05 Nov 2008 17:23:24 GMTWed, 05 Nov 2008 17:23:24 GMT60Create Restful Web Service With CXF 2.1.X/CXF 2.2, Part 1: create a service in Tomcat (Contine) - Create client codehttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238909.htmlJustin ChenJustin ChenWed, 05 Nov 2008 14:48:00 GMThttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238909.htmlhttp://www.aygfsteel.com/justinchen/comments/238909.htmlhttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238909.html#Feedback1http://www.aygfsteel.com/justinchen/comments/commentRss/238909.htmlhttp://www.aygfsteel.com/justinchen/services/trackbacks/238909.html

The previous message only explains how to create service, this message will describe how to create client and invoke server side. Actually, JSR-311 only defined the server API, so, each vendor will have different ideas on client. But one common way is to use Apache Http Common Client lib. Please see following examples.

1. GET a customer

// Sent HTTP GET request to query customer info

System.out.println(
"Sent HTTP GET request to query customer info");

URL url 
= new URL("http://localhost:8080/vendor_search/services/customerservice/customers/123");

InputStream in 
= url.openStream();

System.out.println(getStringFromInputStream(in)); 
//NOTE, return an input stream, you need convert xml to Java Object by yourself
2. Use PUT to update a customer


System.out.println("Sent HTTP PUT request to update customer info");

Client client 
= new Client();

String inputFile 
= client.getClass().getResource("update_customer.txt").getFile();

File input 
= new File(inputFile);

PutMethod put 
= new PutMethod("http://localhost:8080/vendor_search/services/customerservice/customers");

RequestEntity entity 
= new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");

put.setRequestEntity(entity);

HttpClient httpclient 
= new HttpClient();



try {

int result = httpclient.executeMethod(put);

System.out.println(
"Response status code: " + result);

System.out.println(
"Response body: ");

System.out.println(put.getResponseBodyAsString());

finally {

// Release current connection to the connection pool once you are

// done

put.releaseConnection();

}
3. Use POST to add a customer

System.out.println(
"Sent HTTP POST request to add customer");

inputFile 
= client.getClass().getResource("add_customer.txt").getFile();

input 
= new File(inputFile);

PostMethod post 
= new PostMethod("http://localhost:8080/vendor_search/services/customerservice/customers");

post.addRequestHeader(
"Accept" , "text/xml");

entity 
= new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");

post.setRequestEntity(entity);

httpclient 
= new HttpClient();



try {

int result = httpclient.executeMethod(post);

System.out.println(
"Response status code: " + result);

System.out.println(
"Response body: ");

System.out.println(post.getResponseBodyAsString());

finally {

// Release current connection to the connection pool once you are

// done

post.releaseConnection();

}

So, for this way provided by Apach Common Http Client, the user still need think about the convention from XML to POJO. It is not so convenience. We will provide a utility class to simply this process.



]]>
Create Restful Web Service With CXF 2.1.X/CXF 2.2, Part 1: Create a service in Tomcathttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238868.htmlJustin ChenJustin ChenWed, 05 Nov 2008 10:24:00 GMThttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238868.htmlhttp://www.aygfsteel.com/justinchen/comments/238868.htmlhttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238868.html#Feedback0http://www.aygfsteel.com/justinchen/comments/commentRss/238868.htmlhttp://www.aygfsteel.com/justinchen/services/trackbacks/238868.html闃呰鍏ㄦ枃

]]>
Creating Restful Web Service instead of SOAP web servicehttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238760.htmlJustin ChenJustin ChenWed, 05 Nov 2008 02:43:00 GMThttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238760.htmlhttp://www.aygfsteel.com/justinchen/comments/238760.htmlhttp://www.aygfsteel.com/justinchen/archive/2008/11/05/238760.html#Feedback1http://www.aygfsteel.com/justinchen/comments/commentRss/238760.htmlhttp://www.aygfsteel.com/justinchen/services/trackbacks/238760.html闃呰鍏ㄦ枃

]]>
主站蜘蛛池模板: 江津市| 巴东县| 澄城县| 蕉岭县| 肇东市| 胶州市| 凤翔县| 丽江市| 大埔县| 荔浦县| 洛阳市| 青州市| 义乌市| 华池县| 大埔县| 新平| 兴安县| 河东区| 永城市| 嵩明县| 闸北区| 蒲城县| 平邑县| 甘孜县| 宿迁市| 吴忠市| 凤台县| 石泉县| 临江市| 青神县| 富平县| 玛沁县| 克拉玛依市| 文登市| 象州县| 光山县| 舟山市| 抚顺市| 武乡县| 甘谷县| 蓝山县|