<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 41  文章 - 29  trackbacks - 0
    <2008年11月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    23242526272829
    30123456

    常用鏈接

    留言簿(5)

    隨筆分類(28)

    隨筆檔案(23)

    收藏夾(6)

    Inside JVM

    Java

    java performance

    Solr

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    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.

    posted on 2008-11-05 22:48 Justin Chen 閱讀(1841) 評論(0)  編輯  收藏 所屬分類: Rest

    FeedBack:
    # re: Create Restful Web Service With CXF 2.1.X/CXF 2.2, Part 1: create a service in Tomcat (Contine) - Create client code 2008-11-05 22:53 小Xiong
    全英! 嗨! 具有很高的挑戰性!  回復  更多評論
      
    主站蜘蛛池模板: 另类专区另类专区亚洲| 色噜噜AV亚洲色一区二区| 在线a级毛片免费视频| 亚洲免费在线观看视频| 精品无码AV无码免费专区| 性无码免费一区二区三区在线| 中文字幕乱码系列免费| 国产性生大片免费观看性| 国产午夜免费高清久久影院| 国产午夜无码精品免费看动漫| 无码午夜成人1000部免费视频| 99精品在线免费观看| 我们的2018在线观看免费高清 | 亚洲精品不卡视频| 亚洲欧洲国产精品久久| 亚洲AV无码久久久久网站蜜桃 | 亚洲精品国产字幕久久不卡| 日本亚洲视频在线| 亚洲福利一区二区| 亚洲天然素人无码专区| 污视频网站在线观看免费| jizz免费在线影视观看网站| 中文精品人人永久免费| 最好看最新的中文字幕免费| 久久精品免费全国观看国产| 免费看www视频| 国产亚洲精品自在线观看| 亚洲AV无码AV男人的天堂| 91嫩草亚洲精品| 精品久久久久久久久亚洲偷窥女厕| 国产大陆亚洲精品国产| 99久久99这里只有免费的精品| 日韩精品无码免费一区二区三区| 手机在线看永久av片免费| 国产乱子伦精品免费女| 国产亚洲成AV人片在线观黄桃| 精品亚洲国产成AV人片传媒| 亚洲第一街区偷拍街拍| 中文字幕在线免费观看视频| 18pao国产成视频永久免费| 日本免费福利视频|