《Mule ESB Hello实例(四).docx》由会员分享,可在线阅读,更多相关《Mule ESB Hello实例(四).docx(6页珍藏版)》请在优知文库上搜索。
1、MuleESBHello实例(四)这是一个坡简洁的muleesb入门实例,其中用了HoW.endpoint,transfomponent这些组件,这些组件的圮巴也是足荷洁足置.情景:1.在阅读器地址栏输入y/localhost:9090/hello-mule?name=oliver&age=20,iS0Hellooliver,yourageis10.1.在阅读涔地址栏输入y,localhost9090lovmue7ame=olivrSage=20,!il1.oveoliver,yourageis10.配胜文件:(tml)viewPurrK8丫1.2mulewins-*:wulesoft.org
2、/schema/ule/coree3. xlnsxsi三*:/w3.org2lXM1.Schema-instance4. Xfilnsispring=:/sprlngframework.org/schema/beans5. nlns:*:/三ulesoft.orgschema三ule6. Xfllns:/muIesoft.org/scbeamlevn,7sizschea1.oction*aa8. 1/sprigfrarnework.orgschemabeans:/springfrafteuork.orgsche12.13. 14. 15.16. 17. custo18.19. !设性相应内容为
3、Sxt/html格式2.21. propertykey三*Content-Type*value*Mtext/html22. 23. 24. 25.26. 27. 28. 29. transformerref三,DataToPersonTransformer*/3.31. 32. 33. 34. 35.36. 37.38. 39.40. 41. 42. 43. 44. 45. 46. Ctransformcrref-SetHtwlContentType47. 48. ound-endpoint49.58. 59.60. 61.62. Transformer:1. DataToperson将客户端
4、传过来的数据转换成component所纪要Person类型(html)Vkrw6Mcop1. packagecom.mule.transformer;2.3. importorg.mule.api.MuleMessage;4. importorg.mule.api.transfOrnereTransforeierException;5i三portorg.mule.transformer.AbstractMessageTransformer;7. Ifiportcon.mule.domain.Person;8.9. publicclassDataToPersonTransformerextend
5、sAbstractMessageTransforner(10.11. Override12. publicObjecttransforrtMes5age(MuleMessage11essage,StringOUtputEncoding)13. throwsTransfornerExceptlon(14. StringnjrxNmessage.getInboundProperty(MnafieM);15. Stringage-cssage.getInborlProperty(,age);16. if(agenull)17. age三,l;18. )19.20. returnnewPerson(a
6、11e,Integer.parselnt(age);21. 22.23)2.StringToHtmlTransformer将COmPOnent处理后返川的string类型数拉;,封装成html数据jvdSeWPidirKOPypackagecom.mule.transformer;importorg.mule.apt.transforner.TransfonierException;importorg.mule.transformer.AbstractTransfonner;importco.mule.util.HtmlTeflplateUt11;publicclassStringToHtml
7、TransforfierextendsAbstractTransformer(l.Override11. protectedObjectdoTransform(0bject$rc,Stringenc)12. throwsTransforiierException(13. Stringstr(String)src;14.ISereturnHtmlTenp1ateUtil.getSimpleHtml(str);16. )17.18.)Component:WeIcomService返M欢迎内容javSeWpiropypackagecom.muleponent;importcon.mule.domai
8、n.Person;publicclassWelcomService(publicStringsayHello(Personperson)return-Hello,person.getKame(),yourageis*person.getAge();9)l.11.publicStringsay1.ove(Personperson)12. return1.oveyou*person.getNa11e(),yourageisperson.getAge();13. )14.15. )Person类:jvaVWWplincopy2345678packagecom.mule.domain;publiccl
9、assPersonprivateStringna11e;privateitage;publicPerson()l.publicPerson(Stringna11e,intage)11. this.ane三name;12. this.ageage;1314.15. publicStringgetName()16. returnname;17. )18.19. publicvoidsetNa11e(Stringna11e)2.21.22.23.24.25.26.27.28.29.3.this.na11e-name;)publicIntgetAge()returnage;)publicvoidsetAge(Intage)this.ageage;31.)(java)VeeWPlalnCoPV1.HtnlTeffiplateUtilI:具类:用选句封转始定的textpackagecom.mule.util;5publicstaticStringgetSimpleKtml(Stringtext)6.Stringoutput=*h;7.8.output-9.output*三MM;l.output+=,