乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      cxf工作原理

       一本正經(jīng)地胡鬧 2019-08-21

      最近使用了一下cxf,簡(jiǎn)單的查看了部分源代碼,給我的感覺(jué)它就是一個(gè)可以大大簡(jiǎn)化我們客戶端編寫(xiě)遠(yuǎn)程方法調(diào)用的一個(gè)工具框架,只需要簡(jiǎn)單的幾行代碼就可以解決這種復(fù)雜的問(wèn)題,下面就舉個(gè)例子:

      1. package com.yonge.cxf;
      2. import java.util.Date;
      3. import org.apache.cxf.frontend.ClientProxyFactoryBean;
      4. import org.apache.cxf.transport.jms.spec.JMSSpecConstants;
      5. import com.erayt.solar2.adapter.config.Weather;
      6. import com.erayt.solar2.adapter.fixed.HelloWorld;
      7. public class CXFClientTest {
      8. public static void main(String[] args) {
      9. ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
      10. factory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);
      11. factory.setAddress("http://localhost:9000/Hello");
      12. HelloWorld hello = factory.create(HelloWorld.class);
      13. Weather weather1 = hello.getWeather(new Date());
      14. System.out.println("forecast:" + weather1.getForecast());
      15. }
      16. }

      上面一段是客戶端調(diào)用遠(yuǎn)程服務(wù)器中HelloWorld接口的getWeather方法 的一個(gè)具體實(shí)現(xiàn)。服務(wù)端的代碼如下:

      1. package com.erayt.solar2.adapter.driver;
      2. import org.apache.cxf.frontend.ServerFactoryBean;
      3. import com.erayt.solar2.adapter.config.HelloWorldImpl;
      4. import com.erayt.solar2.adapter.fixed.HelloWorld;
      5. public class CXFServer {
      6. protected CXFServer() throws Exception {
      7. HelloWorld helloworldImpl = new HelloWorldImpl();
      8. ServerFactoryBean svrFactory = new ServerFactoryBean();
      9. svrFactory.setServiceClass(HelloWorld.class);
      10. svrFactory.setAddress("http://localhost:9000/Hello");
      11. svrFactory.setServiceBean(helloworldImpl);
      12. svrFactory.create();
      13. }
      14. public static void main(String args[]) throws Exception {
      15. new CXFServer();
      16. System.out.println("Server ready...");
      17. Thread.sleep(50 * 60 * 1000);
      18. System.out.println("Server exiting");
      19. System.exit(0);
      20. }
      21. }

       服務(wù)端將接口以服務(wù)的形式發(fā)布后,必須提供客戶端訪問(wèn)服務(wù)的地址(http://localhost:9000/Hello),客戶端可以根據(jù)提供的地址訪問(wèn)服務(wù)端相關(guān)服務(wù)的wsdl文件,客戶端可以根據(jù)wsdl文件生成對(duì)應(yīng)的客戶端代碼,也就是HelloWorld接口文件,然后客戶端可以像調(diào)用本地接口方法一樣,去調(diào)用遠(yuǎn)程方法,客戶端與服務(wù)端之間的交互是通過(guò)代理完成的,所以開(kāi)發(fā)在編程時(shí)不需要關(guān)系他們是如何交互的,在代理中,上面的客戶端請(qǐng)求hello.getWeather方法時(shí)會(huì)向服務(wù)端發(fā)送如下的消息:

      <soap:Envelope xmlns:soap="http://schemas./soap/envelope/">
      	<soap:Body>
      		<ns1:getWeather xmlns:ns1="http://fixed.adapter.solar2./">
      			<arg0>2013-06-22T18:56:43.808+08:00</arg0>
      		</ns1:getWeather>
      	</soap:Body>
      </soap:Envelope>

       服務(wù)器端接收?qǐng)?bào)文后,會(huì)解析報(bào)文,按照?qǐng)?bào)文的信息執(zhí)行相應(yīng)的本地方法,然后將返回值又構(gòu)造一個(gè)報(bào)文響應(yīng)給客戶端,如下:

      <soap:Envelope xmlns:soap="http://schemas./soap/envelope/">
      	<soap:Body>
      		<ns1:getWeatherResponse xmlns:ns1="http://fixed.adapter.solar2./">
      			<return>
      				<forecast>Cloudy with
      					showers
      				</forecast>
      				<howMuchRain>4.5</howMuchRain>
      				<rain>true</rain>
      				<temperature>39.3</temperature>
      			</return>
      		</ns1:getWeatherResponse>
      	</soap:Body>
      </soap:Envelope>

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多