Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學(xué);靜其心,可悟天下之理;恒其心,可成天下之業(yè)。

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評(píng)論 :: 0 Trackbacks
          近公司需要寫這樣一個(gè)功能。也就是需要一個(gè)esb消息總線。初步的功能是提供webservice的消息管理以后還會(huì)增加很多的功能。。以前本來在soa esb上面的東西就是個(gè)空白。在Google上找了一天最后由我自己覺得用mule2.1.2。讓后就瘋狂的找些好的帖子。希望能夠很快的入門。但發(fā)現(xiàn)不是那么一回事。找到的很多都是1.X的版本。2.1.2 的少得很。經(jīng)過近半周的研究。。終于自己寫了一個(gè)小的test。貼上來給新入門的朋友希望有幫助。深入的研究以后還會(huì)繼續(xù)。
          配置文件:mule_config.xml
          Java代碼 復(fù)制代碼
          1. <?xml?version="1.0"?encoding="UTF-8"?> ??
          2. <mule?xmlns="http://www.mulesource.org/schema/mule/core/2.1"??
          3. ??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
          4. ??????xmlns:spring="http://www.springframework.org/schema/beans"??
          5. ??????xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.1"??
          6. ??????xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.1"??
          7. ??????xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.1"??
          8. ??????xmlns:smtps="http://www.mulesource.org/schema/mule/smtps/2.1"??
          9. ??????xmlns:http="http://www.mulesource.org/schema/mule/http/2.1"??
          10. ??????xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.1"??
          11. ??????xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.1"??
          12. ??????xsi:schemaLocation=" ??
          13. ???????????????http://www.springframework.org/schema/beans?http://www.springframework.org/schema/beans/spring-beans-2.5.xsd ??
          14. ???????????????http://www.mulesource.org/schema/mule/core/2.1?http://www.mulesource.org/schema/mule/core/2.1/mule.xsd ??
          15. ???????????????http://www.mulesource.org/schema/mule/stdio/2.1?http://www.mulesource.org/schema/mule/stdio/2.1/mule-stdio.xsd ??
          16. ???????????????http://www.mulesource.org/schema/mule/vm/2.1?http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd ??
          17. ???????????????http://www.mulesource.org/schema/mule/cxf/2.1?http://www.mulesource.org/schema/mule/cxf/2.1/mule-cxf.xsd ??
          18. ???????????????http://www.mulesource.org/schema/mule/axis/2.1?http://www.mulesource.org/schema/mule/axis/2.1/mule-axis.xsd ??
          19. ???????????????http://www.mulesource.org/schema/mule/smtps/2.1?http://www.mulesource.org/schema/mule/smtps/2.1/mule-smtps.xsd ??
          20. ???????????????http://www.mulesource.org/schema/mule/soap/2.1?http://www.mulesource.org/schema/mule/soap/2.1/mule-soap.xsd ??
          21. ???????????????http://www.mulesource.org/schema/mule/http/2.1?http://www.mulesource.org/schema/mule/http/2.1/mule-http.xsd ??
          22. ???????????????"> ??
          23. ?????<description> ??
          24. ????????eagleMule?demo?which?shows?how?to?publish?web?services?over?CXF. ??
          25. ????</description> ??
          26. ????<model?name="eagleMule"> ??
          27. ?????????<service?name="testMuleService"> ??
          28. ????????????<inbound> ??
          29. ????????????????<axis:inbound-endpoint?address="http://localhost:8899/services/testMuleService"> ??
          30. ????????????????????<soap:http-to-soap-request-transformer?/> ??
          31. ????????????????</axis:inbound-endpoint> ??
          32. ????????????????<cxf:inbound-endpoint?address="http://localhost:8898/services/testMuleService"> ??
          33. ????????????????????<soap:http-to-soap-request-transformer?/> ??
          34. ????????????????</cxf:inbound-endpoint> ??
          35. ????????????</inbound> ??
          36. ????????????<component?class="com.eagle.mule.test.imp.MuleServiceImp"> ??
          37. ????????????</component> ??
          38. ????????</service> ??
          39. ????</model> ??
          40. ????</mule>??

          一個(gè)簡單的 接口 為了先跑同就這樣把。
          MuleService.java
          Java代碼 復(fù)制代碼
          1. ?@WebService??
          2. public?interface?MuleService?{ ??
          3. public?String?testMule(@WebParam(name="str")String?str); ??
          4. }??

          MuleServiceImp.java
          Java代碼 復(fù)制代碼
          1. @WebService(serviceName="eagleMuleService", ??
          2. ??????????endpointInterface="com.eagle.mule.test.MuleService") ??
          3. public?class?MuleServiceImp?implements?MuleService?{ ??
          4. ??
          5. ????public?String?testMule(String?str)?{ ??
          6. ????????System.out.println("----service---"); ??
          7. ????????return?"hello--"+str; ??
          8. ????} ??
          9. }??

          啟動(dòng)服務(wù):
          Java代碼 復(fù)制代碼
          1. public?class?EagleMuleMain?{ ??
          2. ????public?static?void?main(String[]?args)?throws?ConfigurationException,?InitialisationException?{ ??
          3. ????????try?{ ??
          4. ????????????String?configFile?=?"com/eagle/mule/test/mule_config.xml"; ??
          5. ????????????String[]?configFileArr?=?new?String[]?{?configFile?}; ??
          6. ????????????MuleContextFactory?muleContextFactory?=?new?DefaultMuleContextFactory(); ??
          7. ????????????MuleContext?context?=?muleContextFactory ??
          8. ????????????????????.createMuleContext(new?SpringXmlConfigurationBuilder( ??
          9. ????????????????????????????configFileArr)); ??
          10. ????????????context.start(); ??
          11. ????????}?catch?(MuleException?t)?{ ??
          12. ????????????t.printStackTrace(); ??
          13. ????????} ??
          14. ????} ??
          15. }??

          測(cè)試
          Java代碼 復(fù)制代碼
          1. package?com.eagle.mule.test.clint; ??
          2. ??
          3. import?java.io.IOException; ??
          4. import?java.io.InputStream; ??
          5. ??
          6. import?org.apache.commons.io.IOUtils; ??
          7. import?org.mule.api.MuleException; ??
          8. import?org.mule.api.MuleMessage; ??
          9. import?org.mule.module.client.MuleClient; ??
          10. ??
          11. public?class?Client?{ ??
          12. ????public?static?void?main(String[]?args){ ??
          13. ????????MuleClient?client?=?null;? ??
          14. ????????try?{ ??
          15. ????????????client?=?new?MuleClient(); ??
          16. ????????????String?url?=?"axis:http://localhost:8899/services/testMuleService/testMuleService?method=testMule"; ??
          17. ??
          18. ????????????MuleMessage?message?=?client.send(url,?"eagle",?null); ??
          19. ????????????Object?obj?=?message.getPayload(); ??
          20. ????????????System.out.println("--------------obj---------"+obj.getClass().getName()); ??
          21. ????????????if(obj?instanceof?String){ ??
          22. ????????????????System.out.println("---------str--------------"+obj); ??
          23. ????????????} ??
          24. ????????}?catch?(MuleException?e)?{ ??
          25. ????????????//?TODO?Auto-generated?catch?block ??
          26. ????????????e.printStackTrace(); ??
          27. ????????}finally{ ??
          28. ????????????client.dispose(); ??
          29. ????????} ??
          30. ??
          31. ????} ??
          32. } ??
          33. 注意?這里需要把mule?下lib中?endorsed??mule??opt?文件夾中的jar都加進(jìn)去。如果不發(fā)布cxf的服務(wù)?可以不用添加endorsed文件夾中的jar。?
          posted on 2009-09-23 09:05 禮物 閱讀(1084) 評(píng)論(0)  編輯  收藏 所屬分類: ESBESB

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。

          網(wǎng)站導(dǎo)航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 敦煌市| 卢氏县| 南通市| 陇南市| 卢湾区| 柳河县| 田林县| 嘉禾县| 鹿邑县| 彭阳县| 霍林郭勒市| 湘西| 固始县| 龙陵县| 塘沽区| 喀喇沁旗| 咸丰县| 开封县| 三门峡市| 黑河市| 黎城县| 清河县| 元谋县| 宁国市| 新民市| 工布江达县| 蕉岭县| 浙江省| 叙永县| 邻水| 新巴尔虎左旗| 星子县| 大竹县| 山西省| 会昌县| 惠东县| 铜梁县| 安康市| 庐江县| 聊城市| 江川县|