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

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

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

    溫馨提示:您的每一次轉載,體現了我寫此文的意義!!!煩請您在轉載時注明出處http://m.tkk7.com/sxyx2008/謝謝合作!!!

    雪山飛鵠

    溫馨提示:您的每一次轉載,體現了我寫此文的意義!!!煩請您在轉載時注明出處http://m.tkk7.com/sxyx2008/謝謝合作!!!

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
            最近由于項目需要,一直在學習OSGI,在學習OSGI的這段時間內,不斷的接觸到apache的一些優秀的開源項目,比如說Felix、CXF等。Felix是Apache對OSGI R4規范的一個輕量級實現。你使用eclipse創建的plugin(插件)工程都是可以正常運行在Felix中的。前提是你創建bundle的時候選擇標準選項這一欄。好了本篇文章主要是用來介紹CXF的,關于Felix就不再深入討論了,有興趣的可以自行去研究下。
            關于CXF,不做過多的解釋。官方的解釋已經夠清楚了。相信大家之前在Java環境下創建webservice程序大多數選擇的是xfire這個框架吧。后來好多專家不再推薦這個東東。都建議使用CXF。在未接觸到CXF之前,本人一向喜歡用xfire這個框架來創建自己的webservice。還了,廢話不多說,先來看個HelloWorld的程序,教大家快速上手。
            首先去Apache網站下載CXF所需要的jar,我本人下載是apache-cxf-2.2.10.zip這個包。這里為了方便期間創建一個java工程。?。縥ava工程,這有點不可思議了,不是要創建webservice嗎?怎么是java工程?呵呵,這里就是CXF的神奇之處!
            添加必須的jar到你的classpath路徑下。
            cxf-2.2.10.jar 核心jar
            jetty-6.1.21.jar 用來啟動jetty服務器
            jetty-util-6.1.21.jar jetty輔助工具
            wsdl4j-1.6.2.jar wsdl支持工具
            XmlSchema-1.4.5.jar 
            這就是CXF的最小配置,以上jar包缺一不可
            創建一個接口
    package com.cxf.service;

    public interface HelloWorldCxfService {
        
        String sayHello(String username);
    }
            創建該接口的實現類
    package com.cxf.service;

    public class HelloWorldCxfServiceImpl implements HelloWorldCxfService {

        
    public String sayHello(String username) {
            
    return "Hello,"+username;
        }
    }
            發布webservice
    package com.cxf.server;

    import org.apache.cxf.frontend.ServerFactoryBean;

    import com.cxf.service.HelloWorldCxfService;
    import com.cxf.service.HelloWorldCxfServiceImpl;

    public class Server {
        
        
    public static void main(String[] args){
            HelloWorldCxfServiceImpl worldCxfServiceImpl
    =new HelloWorldCxfServiceImpl();
            ServerFactoryBean factoryBean
    =new ServerFactoryBean();
            factoryBean.setAddress(
    "http://localhost:8080/hello");
            factoryBean.setServiceClass(HelloWorldCxfService.
    class);
            factoryBean.setServiceBean(worldCxfServiceImpl);
            factoryBean.create();
        }
    }
            運行Server,注意不要關閉,在控制臺會打印如下信息:
    2010-9-10 9:44:16 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
    信息: Creating Service {http://service.cxf.com/}HelloWorldCxfService from class com.cxf.service.HelloWorldCxfService
    2010-9-10 9:44:16 org.apache.cxf.endpoint.ServerImpl initDestination
    信息: Setting the server's publish address to be http://localhost:8080/hello
    2010-09-10 09:44:16.296::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
    2010-09-10 09:44:16.296::INFO:  jetty-6.1.21
    2010-09-10 09:44:16.390::INFO:  Started SelectChannelConnector@localhost:8080
            客戶端調用
    package com.cxf.server;

    import org.apache.cxf.frontend.ClientProxyFactoryBean;

    import com.cxf.service.HelloWorldCxfService;

    public class Client {
        
        
    public static void main(String[] args) {
            ClientProxyFactoryBean factoryBean
    =new ClientProxyFactoryBean();
            factoryBean.setAddress(
    "http://localhost:8080/hello");
            factoryBean.setServiceClass(HelloWorldCxfService.
    class);
            HelloWorldCxfService worldCxfService
    =(HelloWorldCxfService) factoryBean.create();
            System.out.println(worldCxfService.sayHello(
    "張三"));
        }
    }
            運行Client代碼,控制臺打印如下信息:
    2010-9-10 9:46:58 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
    信息: Creating Service {http://service.cxf.com/}HelloWorldCxfService from class com.cxf.service.HelloWorldCxfService
    Hello,張三
            到此,我們的webservice,已經成功調用了。大家是不是迫不及待的想看下wsdl文件是啥樣的呢?
    在瀏覽器中輸入http://localhost:8080/hello?wsdl,即可看到wsdl文件了。其中http://localhost:8080/hello部分為代碼里指定的Address。
            wsdl文件信息:
      <?xml version="1.0" ?> 
    <wsdl:definitions name="HelloWorldCxfService" targetNamespace="http://service.cxf.com/" xmlns:ns1="http://schemas.xmlsoap.org/wsdl/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.cxf.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:types>
    <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://service.cxf.com/" xmlns:tns="http://service.cxf.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      
    <xsd:element name="sayHello" type="tns:sayHello" /> 
    <xsd:complexType name="sayHello">
    <xsd:sequence>
      
    <xsd:element minOccurs="0" name="arg0" type="xsd:string" /> 
      
    </xsd:sequence>
      
    </xsd:complexType>
      
    <xsd:element name="sayHelloResponse" type="tns:sayHelloResponse" /> 
    <xsd:complexType name="sayHelloResponse">
    <xsd:sequence>
      
    <xsd:element minOccurs="0" name="return" type="xsd:string" /> 
      
    </xsd:sequence>
      
    </xsd:complexType>
      
    </xsd:schema>
      
    </wsdl:types>
    <wsdl:message name="sayHelloResponse">
      
    <wsdl:part element="tns:sayHelloResponse" name="parameters" /> 
      
    </wsdl:message>
    <wsdl:message name="sayHello">
      
    <wsdl:part element="tns:sayHello" name="parameters" /> 
      
    </wsdl:message>
    <wsdl:portType name="HelloWorldCxfServicePortType">
    <wsdl:operation name="sayHello">
      
    <wsdl:input message="tns:sayHello" name="sayHello" /> 
      
    <wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse" /> 
      
    </wsdl:operation>
      
    </wsdl:portType>
    <wsdl:binding name="HelloWorldCxfServiceSoapBinding" type="tns:HelloWorldCxfServicePortType">
      
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="sayHello">
      
    <soap:operation soapAction="" style="document" /> 
    <wsdl:input name="sayHello">
      
    <soap:body use="literal" /> 
      
    </wsdl:input>
    <wsdl:output name="sayHelloResponse">
      
    <soap:body use="literal" /> 
      
    </wsdl:output>
      
    </wsdl:operation>
      
    </wsdl:binding>
    <wsdl:service name="HelloWorldCxfService">
    <wsdl:port binding="tns:HelloWorldCxfServiceSoapBinding" name="HelloWorldCxfServicePort">
      
    <soap:address location="http://localhost:8080/hello" /> 
      
    </wsdl:port>
      
    </wsdl:service>
      
    </wsdl:definitions>
                    
    posted on 2010-09-10 09:51 雪山飛鵠 閱讀(5962) 評論(7)  編輯  收藏 所屬分類: webservice

    Feedback

    # re: Apache之CXF HelloWorld入門[未登錄] 2010-09-10 10:00 yang
    這不類似 xml-rpc 了么???  回復  更多評論
      

    # re: Apache之CXF HelloWorld入門 2010-09-10 12:57 cxh8318
    能否告知如何實現jar包的最小配置?是一個一個試嗎?  回復  更多評論
      

    # re: Apache之CXF HelloWorld入門 2010-09-10 13:47 @joe
    這是基于c/s的  回復  更多評論
      

    # re: Apache之CXF HelloWorld入門 2010-09-10 14:10 java小爬蟲
    沒任何技術含量,是cxf在線文檔的摘抄罷了...  回復  更多評論
      

    # re: Apache之CXF HelloWorld入門 2010-09-10 14:16 雪山飛鵠
    @java小爬蟲
    本人才學疏淺,剛開始接觸CXF。我已明確說了是CXF入門。再者,本人寫這篇博文的時候并未參考過CXF的在線文檔。  回復  更多評論
      

    # re: Apache之CXF HelloWorld入門 2010-09-10 14:21 雪山飛鵠
    @cxh8318
    關于jar包的最小配置,我一般是嘗試的。我一直不建議,將框架下的所有jar添加到工程中,這樣一來體積明顯較大,而且很容易出現jar包沖突。我一般是這么做的,先只添加核心jar,然后運行它。在運行過程中根據控制臺的異常信息,去添加對應所需的jar。這樣即快又方便,還能加深印象。即使時間再長,也不會忘記它依賴那些jar。  回復  更多評論
      

    # re: Apache之CXF HelloWorld入門 2012-12-05 16:22 jungle
    有用有用,那個說“沒任何技術含量,是cxf在線文檔的摘抄”自己不分享還在那里叫叫叫,自私的要命。

    我可以運行成功。如果樓主有WEB方面的helloworld發我一份吧。要有JAR包哦~61917380@qq.com  回復  更多評論
      

    主站蜘蛛池模板: 搜日本一区二区三区免费高清视频 | 男人免费视频一区二区在线观看| 免费一级毛片正在播放| 成人片黄网站色大片免费观看cn| 亚洲福利一区二区三区| 免费特级黄毛片在线成人观看| 久久av免费天堂小草播放| 亚洲国产成人久久77| 亚洲av无码专区在线观看素人| 无码人妻一区二区三区免费看 | 亚洲精品免费视频| 蜜桃传媒一区二区亚洲AV| 亚洲av中文无码乱人伦在线r▽ | 爱情岛论坛网亚洲品质自拍| 99精品视频在线观看免费播放| 亚洲AV永久无码精品网站在线观看 | 暖暖日本免费在线视频| 国产真人无码作爱视频免费| 亚洲日本中文字幕天天更新| 亚洲乱码中文字幕综合 | 亚洲AⅤ无码一区二区三区在线| 日韩内射激情视频在线播放免费 | 两个人看的www免费视频中文| 久久精品国产亚洲av麻豆蜜芽| 亚洲熟妇无码八AV在线播放| 四虎免费大片aⅴ入口| 91精品免费不卡在线观看| 人与动性xxxxx免费| 亚洲国产精品美女久久久久| 亚洲国产精品一区二区久久| 亚洲国产激情一区二区三区| 成年免费大片黄在线观看岛国| 久久国产乱子精品免费女| 免费VA在线观看无码| 亚洲一卡2卡3卡4卡5卡6卡| 久久精品国产亚洲AV大全| 亚洲乱码中文字幕综合| 亚洲人成无码久久电影网站| 天天干在线免费视频| 亚洲电影在线免费观看| 国产精品白浆在线观看免费|