免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
cxf工作原理

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

  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. }

上面一段是客戶端調用遠程服務器中HelloWorld接口的getWeather方法 的一個具體實現(xiàn)。服務端的代碼如下:

  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. }

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

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

 服務器端接收報文后,會解析報文,按照報文的信息執(zhí)行相應的本地方法,然后將返回值又構造一個報文響應給客戶端,如下:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">	<soap:Body>		<ns1:getWeatherResponse xmlns:ns1="http://fixed.adapter.solar2.erayt.com/">			<return>				<forecast>Cloudy with					showers				</forecast>				<howMuchRain>4.5</howMuchRain>				<rain>true</rain>				<temperature>39.3</temperature>			</return>		</ns1:getWeatherResponse>	</soap:Body></soap:Envelope>
本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
WebService CXF學習(進階篇3):對象傳遞
cxf 實例解讀
JAVA6開發(fā)WebService (三)——幾個概念
CXF + Spring 開發(fā) Webservices
CXF攔截器(Interceptor)的使用(2) - 豆豆網
使用Soap消息調用Web Services
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服