<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

    搜索

    •  

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    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 閱讀(1851) 評(píng)論(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
    全英! 嗨! 具有很高的挑戰(zhàn)性!  回復(fù)  更多評(píng)論
      
    主站蜘蛛池模板: 亚洲欧洲av综合色无码| 亚洲AV日韩AV永久无码色欲 | 久久aⅴ免费观看| 亚洲冬月枫中文字幕在线看| 国产真实伦在线视频免费观看| 九九热久久免费视频| 亚洲国产精品免费在线观看| 深夜国产福利99亚洲视频| 日韩中文字幕免费视频| 亚洲精品人成网线在线播放va | 老司机亚洲精品影院| 蜜臀91精品国产免费观看| 在线观看片免费人成视频无码| 一区二区亚洲精品精华液 | 日本亚洲色大成网站www久久| 久久久青草青青国产亚洲免观 | 亚洲综合免费视频| 欧洲乱码伦视频免费国产| 亚洲国产精品乱码在线观看97| 亚洲精品国产精品乱码不卞| 三年片在线观看免费大全 | 在线视频网址免费播放| 亚洲午夜成人精品无码色欲| 亚洲VA中文字幕无码毛片| 免费国产在线观看老王影院| 无码国产精品一区二区免费式直播| 一级黄色毛片免费看| 亚洲欧美日韩久久精品| 亚洲午夜精品久久久久久人妖| 亚洲精品无码激情AV| 女性无套免费网站在线看| 18禁美女黄网站色大片免费观看 | 三年片在线观看免费观看大全动漫| 国产AV无码专区亚洲AV琪琪| 亚洲伊人久久大香线焦| 亚洲亚洲人成综合网络| mm1313亚洲精品无码又大又粗 | 亚洲午夜av影院| 国产成人啪精品视频免费网| 成人黄色免费网址| 久久久久久夜精品精品免费啦|