<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 閱讀(1851) 評論(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在线亚洲男人的天堂| 老牛精品亚洲成av人片| 国产成人免费手机在线观看视频| 久久乐国产综合亚洲精品| 国外成人免费高清激情视频| 亚洲熟妇无码一区二区三区 | 中国精品一级毛片免费播放| 亚洲美女在线国产| 一级毛片a女人刺激视频免费| 亚洲精品成人区在线观看| 国产黄在线观看免费观看不卡 | 免费看搞黄视频网站| 亚洲成a人片77777老司机| 97视频免费观看2区| 亚洲男人天堂影院| 性感美女视频在线观看免费精品 | 亚洲无mate20pro麻豆| 成人午夜视频免费| 污污免费在线观看| 国产亚洲精品美女久久久| 100部毛片免费全部播放完整| 亚洲日本久久久午夜精品| 亚洲国产成人久久综合碰| 国产成人免费视频| 亚洲色大成网站www永久男同| 四虎免费久久影院| 国产婷婷成人久久Av免费高清| 亚洲小说区图片区| 国产一区二区三区在线免费| 中国一级全黄的免费观看| 亚洲精品在线不卡| 免费va在线观看| 成人黄网站片免费视频 | 免费国产黄网站在线观看动图 | 学生妹亚洲一区二区| MM131亚洲国产美女久久| 无码乱肉视频免费大全合集| 免费看内射乌克兰女| 亚洲电影免费观看|