<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 閱讀(1842) 評論(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
    全英! 嗨! 具有很高的挑戰性!  回復  更多評論
      
    主站蜘蛛池模板: 久久国产免费一区| 免费一级毛片在线播放不收费| 国产一卡二卡四卡免费| 国产亚洲一区二区三区在线观看| 亚洲最大黄色网址| 1000部免费啪啪十八未年禁止观看| 永久黄网站色视频免费直播| 在线亚洲午夜片AV大片| 99精品国产免费久久久久久下载| 亚洲精品乱码久久久久久按摩 | 亚洲午夜福利精品无码| 337p欧洲亚洲大胆艺术| 四虎一区二区成人免费影院网址| 57pao一国产成视频永久免费| 亚洲情a成黄在线观看| 高清免费久久午夜精品| 中文字幕亚洲激情| 久久久久久成人毛片免费看| 亚洲欧洲日韩综合| 毛片免费视频在线观看| 美女黄频a美女大全免费皮| 亚洲中久无码不卡永久在线观看| 亚洲色成人网站WWW永久四虎 | 亚洲Av永久无码精品三区在线| 久久人午夜亚洲精品无码区| 亚洲国产精品国产自在在线| a级成人毛片免费图片| 亚洲日本视频在线观看| 国产精品视频免费一区二区三区| 亚洲自偷自拍另类图片二区| 天天天欲色欲色WWW免费| www免费黄色网| 亚洲成人免费网址| 18级成人毛片免费观看| 亚洲综合日韩中文字幕v在线| 国产午夜精品理论片免费观看| 亚洲午夜av影院| 国产乱码免费卡1卡二卡3卡| 一区二区三区免费看| 中文国产成人精品久久亚洲精品AⅤ无码精品| 日韩色视频一区二区三区亚洲|