小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

cxf工作原理

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

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

  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)用遠程服務(wù)器中HelloWorld接口的getWeather方法 的一個具體實現(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ù)的地址(http://localhost:9000/Hello),客戶端可以根據(jù)提供的地址訪問服務(wù)端相關(guān)服務(wù)的wsdl文件,客戶端可以根據(jù)wsdl文件生成對應(yīng)的客戶端代碼,也就是HelloWorld接口文件,然后客戶端可以像調(diào)用本地接口方法一樣,去調(diào)用遠程方法,客戶端與服務(wù)端之間的交互是通過代理完成的,所以開發(fā)在編程時不需要關(guān)系他們是如何交互的,在代理中,上面的客戶端請求hello.getWeather方法時會向服務(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ù)器端接收報文后,會解析報文,按照報文的信息執(zhí)行相應(yīng)的本地方法,然后將返回值又構(gòu)造一個報文響應(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>

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

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多