




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
0外文翻译外文原文ArchitectStrutsapplicationsforWebservicesWhenyoureconvertinganenterpriseappforusewithWebservices,thesimplestwaytodoitistoassociateasingleoperationwithasingleenterpriseservice.Butthatsnotnecessarilythebestidea.Inthisarticle,JeromeJosephrajshowsyouhowtobuildWebservicesapplicationsbasedonthetriedandtrueModel-View-Controller(MVC)designpattern.Tothatend,hesadaptedStruts,apopularopen-sourceMVCframework,foruseintheWebservicesarena.Byexaminingthesampleapplicationoutlinedhere,youllseehowyoucanuseStrutsandWebservicestogether.Theever-evolvingJavaprogramminglanguageandSunsJ2EEspecificationhaveenabledsoftwaredevelopersofvariousdisciplinestocreatedistributedcomputingapplicationsthatwerepreviouslypossibleonlywithrelativelyproprietarytools.Thus,whilesomedevelopmentteamsmaychoosetoimplementnewsystemsintheJavaplatform,otherswillcreate,enhance,andmaintainapplicationsusingotherskillsandthenintegratethemintoanexistingheterogeneousdistributedapplication.Thissituationgivesrisetoaninteroperabilitychallenge.Howcananewapplicationinteractwithanoldone?Theanswer:Webservices.Webservicesarethenewholygrailofprogramming.Theymakeitpossibletoshareandcoordinatedispersed,heterogeneouscomputingresources.Inthisarticle,youlllearnoneroutetothisgoal.Youllseehowtoarchitectanapplicationbasedontheopen-sourceStrutsframeworkthatcanintegratewithWebservices.YoushouldhavesomebackgroundinJ2EEandWebservicesbeforeyoubegin;IllbrieflyintroducetheStrutsframeworkandtheModel-View-Controller(MVC)patternhere。TheMVCpattern:Separatingdevelopmentroles1TheMVCdesignpatternclearlydemarcatestherolesofprogrammersanddesigners.Inotherwords,ituntanglesdatafrombusinesslogic.Thispatternallowsdesignerstoconcentrateonthedisplayportionofanapplicationanddeveloperstoconcentrateondevelopingthecomponentsrequiredtodrivetheapplicationsfunctions.ThereareseveralvariationstotheMVCpattern,buttheyareallbasedonthesameunderpinningstructure:anapplicationsdatamodels(theModel),presentationcode(theView),andprogramcontrollogic(theController)shouldexistasdistinctbutintercommunicatingcomponents.TheModelcomponentrepresentsandprocessesapplicationdata.TheViewistheuserinterface;itreflectstheModeldataandpresentsittotheuser.TheControllermapsactionsperformedontheView(forexample,pressingaSubmitbutton)tooperationsontheModel(forexample,retrievinguserdetails).AftertheModelisupdated,theViewisrefreshedandtheusercanperformmoreactions.TheMVCpatternclarifiescodeandfacilitatescodereuse;inaddition,inmanyprojectstheViewisfrequentlyupdated,andtheMVCpatterninsulatestheModelandControlleragainstthosechanges.Struts:AsolidMVC-basedframeworkStrutsisanopen-sourceframeworkforbuildingWebapplicationsbasedontheMVCpattern.StrutsencouragesapplicationarchitecturesbasedontheMVCpatternandprovidesservicescommontomostWebapplications.InaStrutsapplication,youcanarchitecttheModellayersothatthebusinessanddataretrievallogicareeasytoreuse.ThislayerisresponsibleforrunningtheapplicationsbusinesslogicandgettingtherelevantdataStrutsencouragesapplicationarchitecturesbasedontheModel-View-Controllerdesignparadigm.StrutsprovidesitsownControllercomponent(theActionControllerclasses)andintegrateswithothertechnologiestoprovidetheModelandtheView.FortheModel(Modelclasses),Strutscaninteractwithanystandarddataaccesstechnology,includingEnterpriseJavaBeanstechnology,JDBC,andtheObject-RelationalBridge.FortheView(ActionFormclasses),StrutsworkswellwiththeJavaServerPages(JSP)environmentandotherpresentationsystems.Asimple-andinelegant-Webservicesarchitecture2ThesimplestwaytobuildWebservicesistoassociateasingleoperationwithasingleenterpriseservice.Inthisdesign,servicesthatperformbusinesslogicandservicesthatperformdataretrievalareintermingled.SuchaWebservicesarchitectureiseasytodevelopfromexistingbusinesscomponents.However,ithasanumberofweaknesses:thereisnosinglesign-onpointfortheuser,thecouplingbetweentheproviderandsubscriberisntverytight,andbusinesslogicisnotreused.Inshort,thisisntaverygoodarchitectureforacoherentsolution.ItsabetterideatobaseaWebservicessolutionontheMVCpattern.Inthecomingsections,youllseehowyoucanuseStrutstodojustthat.IllexpandtheexistingStrutsframeworkwiththeWSManagerlayer,whichexposestheModelservicemethodswithWebservices.WebserviceswithStrutsapplicationsYoucanaugmentawell-architectedStrutsapplicationtosupportWebservicesinfuturedevelopment.Asnoted,theStrutsframeworkclearlydemarcatesaView,aController,andaModel.TheModelcontainsallthebusinesslogicnecessarytoretrievedatafromapersistentdatastore.YoucanbuildasimpleWebservicelayer-callittheWSManagerlayer-sothattheModelcaneitherprovideorsubscribetoaWebservice.StrutsControllerTheControllerportionoftheMVCarchitectureisfocusedonreceivingrequestsfromtheclient(typicallyauserrunningaWebbrowser),decidingwhatbusinesslogicfunctionshouldbeperformedinresponsetothoserequests,andthendelegatingresponsibilityforproducingthenextphaseoftheuserinterfacetoanappropriateViewcomponent.InStruts,theprimarycomponentofthecontrollerisaservletofclassActionServlet.TheActionServletisresponsibleformappingURIrequeststospecificactionsthroughanXMLfile.ThisfilecontainsalistofrequestURIsandtellstheActionServlethowitshoulddispatcheachofthem.StrutsViewYouwouldbuildtheViewportionofaStruts-basedapplicationusingJSPtechnology.JSPpagescancontainstaticHTMLplusdynamiccontentthatchanges3basedontheinterpretation(atpagerequesttime)ofspecialactiontags.TheJSPenvironmentincludesasetofstandardactiontags.Inaddition,thereisastandardfacilitythatdeveloperscanusetodefinetheirowntags,whichareorganizedintocustomtaglibraries.TheStrutsframeworkincludesanextensivecustomtaglibrarythatfacilitatesuserinterfacesthatarefullyinternationalizedandinteractgracefullywithActionFormbeans.TheViewlayeristhinandsuppliesnobusinesslogic.TheStrutsViewinteractswiththeStrutsControllerthroughActionForm.StrutsActionFormActionFormsarenothingbutJavaclassesextendingtheStruts-providedActionFormclasses,whichhaveaccessorandmutatormethods.ThesemethodsarecalledeitherbyJSPpagesorbyActionclassestopopulateorretrievedata.ModelservicesTheModelserviceisimplementedasasetofJavaclasses.EachModelservicecomponentwillofferasetofservices,andthecomponentscollectivelyofferasetofcommonservicesaswell.TheActionControllerandWSManagerclassespassdatabackandforthaspredefinedDataAccessObjects.Inthecourseofprocessing,theActionControllerortheWSManagercancalltherequiredmethodsintherelevantModelservicecomponents.ThesecomponentspasstherequireddataintheformofDataAccessObjectstotheModelservice,andtheModelserviceperformsanynecessarybusinesslogicprocessingandretrievesanynecessarydatafromthepersistentdatastore.DatapersistencelayerThedatapersistencelayercomprisesallthepersistentdatastores.Forexample,itmightencompassarelationaldatabase,flatfiles,orevenXMLdocuments.Iveincludedasimpleexamplethatimplementsthearchitecturediscussedhere.Allthesamplecodeisincludedinazipfile.Theexampleillustratesasimplenewsportal.Thenewscontentisdeliveredfromadatasource(herecalledDataSource)toaJSPpage,andthenewscontentisalsopublishedasaWebservice.TheportalalsoretrievesthelateststockquotesfromaStockQuoteWebserviceanddisplaysitinthesameJSPpage.4ThezipfilecontainsallofthesourcecodeandtheSQLscriptsforDataSource.ItalsocontainsStrutsActionandActionFormclasses,aModelserviceclass,aJSPpagetodisplaytheresults,andsourcecodeforbothapublisherandasubscriber.ItalsocontainstheWSDLfileandtheclientsourcecodetoaccessthepublishedNewsContentWebservice.WhentheJSPpageisloaded,itcallstheActionclass,whichactsasaControllerintheMVCdesignpattern.TheActionclasscallsthegetNews()methodintheModelserviceclassbypassingapredefinedDataAccessObject.ThegetNews()methodimplementsallthenecessarybusinessanddataretrievallogic.Oncetherelevantdataisretrievedfromthedatasource,theModelservicepopulatestheDataAccessObjectandsendsitbacktotheActionclass.ConclusionInthisarticle,yousawhowtointegratetheStrutsframeworkwithWebservices.YoualsolearnedhowtouseStrutscomponentstoprovideandsubscribetoaWebservice.Thesimpleapplicationcodethataccompaniesthisarticlewillhelpyouunderstandindepthhowallofthisworks.Usingthearchitectureoutlinedhere,youcandevelopenterpriseapplicationsthatarerobust,easytomaintain,andeasilyintegratedwithanylegacyapplications.IhopethatyouwillbereadytostartexploringmoreaboutStrutsandWebservicesandseehowthisarchitecturecanbeusefultoyouinyourownprojects.5中文翻译为Web服务构建Struts应用程序当您要将企业应用程序转变成与Web服务一起使用时,最简单的途径就是将单个操作与单个的企业服务结合在一块。但这并不是最好的方法。在本文中,JeromeJosephraj将向您展示如何构架基于分层的、正确的模型视图控制器(MVC)设计模式的Web服务应用程序。为此,他修改了Struts(一种流行的开放源码MVC框架),以使其适用于Web服务领域。通过研究此处所概述的样本应用程序,您将知道如何才能将Struts与Web服务联合起来使用。不断发展的Java编程语言和Sun公司的J2EE规范使得遵守各类准则的软件开发者们能够创建出分布式计算应用程序,这些应用程序在以前只能通过相关专门工具才可实现。这样,当某些开发团体要选择在Java平台中实现新系统时,其他团体就会通过另外的技术来创建、提高并维护应用程序,然后将它们集成到已有的各类分布式应用程序中去。这种情形就引起了互操作性的竞争。新应用程序与旧应用程序如何交互呢?答案就是:Web服务。Web服务是程序设计新的圣杯。它们能够共享并协调分散的各类计算资源。在本文中,您将了解实现此目的的一种方法。您将看到如何在与Web服务相结合的开放源码Struts框加的基础上来构建应用程序。在开始之前您必须了解一些J2EE与Web服务的相关知识。这里,我将简要地介绍下Struts架构与模型视图控制器(MVC)。MVC模式:分离开发角色MVC设计模式很清楚的划定了程序员与设计者的角色界限。换句话说,从商业逻辑上拆解了数据。这种模式是让设计者集中于设计应用程序的显示部分,而开发者则集中于开发驱动应用程序功能所需的组件。MVC模式有好几种变异,不过它们都是基于相同的基础结构:应用程序的数据模型(Model),显示层代码(View),以及程序控制逻辑(Controller)是存在其中的独立但能相互间通信的组件。模型组件描述并处理应用程序数据。视图指的是用户界面;它反映的是模型数据并把它递交给用户。控制器是将视图上的行为(例如,按下Submit按钮)映射到模型上的操作(例如,检索用户详细信息)。模型更新后,视图也被更新,用户就能够完成更多行为。MVC模式使代码易懂而且使代码更容易重用;另外,在很多工程中视图经常要被更新,MVC模式将模型和控制器与这些所做的更改独立开来。Struts:基于MVC的坚固框架Struts是MVC模式基础上构建Web应用程序的一种开放源码框加。Struts鼓励在MVC模式上构建应用程序而且提供大多数Web应用程序所共有的服务。在Struts应用程序中,您可以构建模型层,这样业务逻辑与数据检索逻辑重用就很容易了。这层负责运行应用程序的业务逻辑,获取相关数据。Struts鼓励在模型视图控制器设计范例基础上构建应用程序。Struts提供自己的控制器组件(ActionController类)并与其他技术相结合来提供模型与视图。对于模型(Model类),Struts能与任何标准的数据访问技术相结6合,包括EJB、JDBC以及Object-RelationalBridge。对于视图(ActionForm类),Struts在JSP环境以及其他基于表示逻辑的系统中运行的很好。简单粗糙的Web服务体系结构构建Web服务最简单的途径就是将单个操作与单个企业服务结合起来。在这种设计方法中,实现业务逻辑的服务与实现数据检索的服务是混合在一起的。这样的一种Web服务可以很容易从已有的业务组件中开发出来。然而,它有很多的缺点:对用户没有提供统一认证,提供者与订阅者耦合不紧,业务逻辑没有重用。简而言之,对于一个连贯的解决方案来说这并不是一个非常好的体系结构。在MVC模式基础上来实现Web服务解决方案会更好点。在后续部分,您将看到如何使用Struts来做到这一点。我将通过WSManager层来详述现有的Struts架构,这一层展示了采用Web服务的模型服务方法。采用Struts应用程序的Web服务在以后的开发工作中您可以扩大构建得比较好的Struts应用程序来支持Web服务。前面讲过,Struts架构清晰地区分开了视图、控制器以及模型。模型包含所有必须的业务逻辑,从存储数据仓库中检索数据。您可以构建一个简单的Web服务层称为WSManager层这样的模型可以提供Web服务也可以订购Web服务。下面的部分要讨论的是这种体系结构中不同组件的详细信息,特别要密切注意WSManager层,因为它是此体系结构中真正新加的部分。Struts控制器MVC体系结构的控制器部分主要集中于接收客户端的请求(一般为运行Web浏览器的用户),决定执行哪一种业务逻辑功能来响应请求,然后负责生成下一个用户界面连接到合适的视图组件上去。在Struts中,控制器的主要组件就是ActionServlet类的一个小服务程序。ActionServlet负责通过XML文档将URI请求映射到特定的行为。这个文档包含了URI请求列表而且还告知ActionServlet它应该如何分配每个请求。Struts视图您要通过使用JSP技术来构建基于Struts应用程序的视图部分。JSP页包含有静态HTML加上动态内容,这些内容是基于对特别行为标签说明(在页面要求时)的。JSP环境包括一套标准的行为标签。另外,在自定义标签库中组织了一套标准的工具,开发者们可以使用这些工具来定义他们自己的标签。Struts框架包含有扩展的自定义标签库,这个库能帮助用户界面国际化更为全面并能非
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工业设计与制造中的机器学习辅助设计
- 工业设计与新型建材的融合实践
- 工作中的跨文化沟通与合作
- 工业风与现代室内设计的融合
- 工业风教育空间设计创新案例
- 工业风格办公室装修设计案例剖析
- 工作环境改善与员工工作效率的关联性研究
- 工程塑料在机械中的应用研究
- 工厂厂区绿化策略
- 工厂节能减排的实践与经验分享
- 2023-2024学年海南省海口市四年级(下)期末数学试卷
- 南通市如东县医疗卫生单位招聘事业编制工作人员笔试真题2024
- 历史●甘肃卷丨2024年甘肃省普通高中学业水平等级性考试高考历史真题试卷及答案
- 2025麒麟卷 地理(一)
- T/GDWJ 011-20225G+院前急救服务应用平台技术规范
- 公务员会计岗位考试题及答案
- 安徽教编美术试题及答案
- 国家开放大学国开电大《幼儿园课程基础》形考任务1~4答案
- 2024-2025湘科版小学科学四年级下册期末考试卷附参考答案
- 2024北京朝阳区四年级(下)期末语文试题及答案
- 劳务报酬扣税计算器(excel自带公式版)
评论
0/150
提交评论