Axis2 Execution Framework.docx
- 文档编号:6194834
- 上传时间:2023-01-04
- 格式:DOCX
- 页数:11
- 大小:82.66KB
Axis2 Execution Framework.docx
《Axis2 Execution Framework.docx》由会员分享,可在线阅读,更多相关《Axis2 Execution Framework.docx(11页珍藏版)》请在冰豆网上搜索。
Axis2ExecutionFramework
Axis2ExecutionFramework
WebserviceshavebecomehighlydemandingandalargenumberofplayershaveenteredtheWebservicearena.Axis2isthelatestsolutionbyApachesolutionstotheWebservicestack,whichaddressessomeofthedrawbacksoftheAxis1.xfamilyandintroducessomenewconceptsintotheWebservicestack.Axis2isahighlyflexible,easilyconfigurable,highlyreliableSOAPprocessingengine.OneofthemainadvantagesgainedfromAxis2isthedynamichandlerchain;althoughthenotionofhandlerchainremainsasinAxis1.x,theunderlyingarchitectureisquitedifferent.
Introduction
Axis2isshapedbytheexperiencefromtheAxis1.xfamilyandtheadvancementsintheWebservicestackduringthelastfewyears.Axis2developerstakeconsciousefforttomakesurethatAxis2performsbetterintermsofspeedandmemorydespitethefactthatnewfeaturesandfunctionalitiesareadded.Amongallthosefeaturesandfunctionalities,thedynamicnatureofthehandlerchain(Executionchain)isconsiderablyimportant.ThearticlepublishedbyWebserviceexpertsinIndianaUniversity(BeytullahYiliz,ShrideepPallickara,andGeofferyFox)onthetopicof "DeploymentProblemsinAxisandSuggestions" hassuggestedthattherequirementofdynamicallyconfigurablehandlerchaininAxisisasfollows:
"InAxis,handlersarecurrentlystaticallyconfigured—theconfigurationbeingmadewhenaserviceisbeingdeployed.Ahandlercannotbeaddedorremovedfromaservice.Currently,Axisarchitectureallowscloningthehandlerchain.Theclonedchaincanreplaceacurrentoneafterrequiredchangesareapplied.Butthisisnotsufficient.Dynamicconfigurationofhandlerchainswillbeveryuseful.Adeploymentmayhavelotsofhandlers,butauser/handlershouldbeabletoselectagroupofhandlersthatamessagewouldneedtogothrough."
InAxis2,thehandlerchainiseasilyconfigurableandhastheabilityofchangingdynamically,thecapabilityachievedthroughso-calledphases,phaserules,andmoduleengagement.
Handlers
IfyouhaveeverusedanyversionofAxis,youshouldbefamiliarwiththeterm"Handler,"theApacheterminologygivenforthe"messageinterceptors"inanymessagingsystem.Interceptorhasitsfactualmeaninginthecontextofmessagingtoo,whichinterceptsthemessagingflowanddoeswhatevertaskitisassignedtodo.Infact,aninterceptoristhesmallestexecutionunitinamessagingsystemsothat,astheinterceptorinAxis,handlerdoesthesamething.
HandlersinAxisarestateless,meaningtheykeeptheirpassexecutionstatesinmemory.AhandlercanbeconsideredasalogicinvokerwiththeinputforthelogicevaluationtakenonlyfromtheMessageContext(MC).HandlerhasbothreadandwritesaccesstoMC.
Note:
MessageContextcanbeseenasapropertybagthatkeepsincomingoroutgoingmessagesandother(maybeboth)requiredparametersandpropertiestocarrythemessagethroughtheexecutionchain.Ontheotherhand,viatheMConecanaccessthewholesystem,suchasglobalparameters,properties,andsoforth.
Mostofthetime(99%ofthetime)handlersonlytouchtheheaderblockpartoftheSOAPmessage,whichwilleitherreadaheader(orheaders),addaheader(s)orremoveaheader(s).Inthereading,ifaheaderistargetedtoahandlerandifitcannotexecuteproperly(messagemightbefaulty)thenitshouldthrowanexception,andnextchaindriver(inAxis2itisengine)wouldtakenecessaryactiondependingontheflow,andphase.
Anyhandlerinachainhasthecapabilitytopausethemessageexecution,meaningthatthehandlercanstopthemessageflowifitcannotcontinue.Reliablemessaging(RM)isagoodexampleortheusecaseforthatscenariothatneedstopausetheflowdependingonsomepre-andpostconditions.InthecaseofRM,itworksonthemessagesequence.Ifaserviceinvocationconsistsofmorethanonemessage,andifthesecondonecomesbeforethefirst,theRMhandlerwillstop(ratherpause)theexecutionofmessageinvocationcorrespondingtothesecondmessageuntilitgetsthefirstmessage.And,whenitgetsthefirstmessage,itwillinvokethat,andthen,after,thatwillinvokethesecondmessage.
Writingasimplehandler
WritingahandlerinAxisisverysimple.TheonlycompulsoryfactoristhatithastoextendfromAbstractHandler.Asimplehandlerisasfollows:
publicclassSimpleHandlerextendsAbstractHandler{
privateStringmessage;
privateQNamename;
publicSimpleHandler(){
this.message="IamSimpleHandler";
}
publicQNamegetName(){
returnname;
}
publicvoidinvoke(MessageContextmsgContext)throwsAxisFault{
//writeinvocationlogichere
}
publicvoidsetName(QNamename){
this.name=name;
}
}
Amongallthemethodsintheaboveimplementation, invoke(msgContext) isthemostimportanttodiscuss.WhenamessageisreceivedtotheAxisengine,itwillcallinvokemethodsofeachhandlerbypassinganargumentasacorrespondingmessagecontext,sothatinsidetheinvokemethodalltheprocessinglogicshouldbeimplemented.Insidetheinvokemethodhandler,theauthorhasfullaccesstotheSOAPmessageandalltherequiredpropertiestoprocessthemessageviathemessagecontext.Inadditiontothat,ifhandlerfindssomepre-conditionandisnotsatisfiedwiththeinvocation,theinvocationcanbepausedasmentionedearlier.ItshouldbenotedthattheAxis2engineprovidesafacilitytostoreandretrievemessagecontext,soahandlercanusethosefeaturestostoreandretrievemessagecontext.
Phase
TheconceptofphaseiscompletelynewterminologytotheWebservicestack;itwasintroducedfortargetingthedynamicorderingofhandlersandtosupportphaserules.Aphasecanbedefinedinvariousways:
∙Itcanbeconsideredalogicalcollectionofhandlers.
∙Itcanbeconsideredaspecifictimeintervalinthemessageexecution.
∙Itcanbeconsideredabucketintowhichonecanputhishandler.
Asdescribedlater,aflowcanbeconsideredasacollectionofphases.EventhoughithasbeenmentionedearlierthattheAxisenginewillcalltheinvokemethodofahandler,itisnottotallycorrect.Infact,theenginereallycallstheinvokemethodofeachphaseinagivenflow;then,phasewillsequentiallyinvokeallthehandlersinit.AlthoughonecanextendtheAbstractHandlerhandlerandcreateanewhandlerbutphase,sothephaseimplementationlogiccannotbechanged.Therefore,eachandeveryphaseinAxisworksinasimplerwayandthedifferenceamongthoseishandlersinsidephases.
Aphaseisdesignedtosupportphaserules.Asdescribedlater,therearerulessuchasphaseFirstandphaseLast,soinahandlertherearereservedslotstoholdbothphasefirstandphaselasthandlers.Therestofthehandlerswillbekeptinadifferentlist.Aphasecan,therefore,begraphicallyrepresentedasfollows:
Phaseinvocationmainlyconsistofthreesteps:
1.Ifthephasefirsthandlerisnotnull,itwillbeinvokedfirst.
2.Thenrestofthehandlers(exceptphaselasthandler)willbeinvoked.
3.Finally,ifthephaselasthandlerisnotnull,itwillbeinvoked.
Note:
Handlersinsideaphasecanbeorderedbyusingphaserules.
TypeofPhases
InAxis2therearetwolevelsofphases:
∙Systempre-definedphase
∙User-definedphase
Systempre-definedphase
Systempre-definedphasesarethephasesthatareinvokedirrespectiveoftheservice,andnoonecanchangetheorderofthesephasesalthoughtheyaredefinedintheAxisconfiguration(calledserver.xmlorclient.xml).Ifsomeonechangestheorderofthesephases,thedeploymentwillnotbeallowedtostartAxis.Thewholepurposeofdefiningtheminaconfigurationfileistotelltheserviceormoduledeveloperthecapabilityofusingthemintheirdevelopment.Thephasesintheirordercorrespondingtoinflowcanberepresentedasfollows:
Allthesephaseshavesomesemanticmeaningaswell.TheTrasnportInphaseconsistsofahandlerthatperformsdependingonthetypeoftransport.Asthenameimplies,thePreDispatchphaseisthephasethatalwaysinvokes(itshandlers)beforethedispatchhastakenplace.HandlerslikeWS-addressingwillalwaysbeinthisphase.TheDispatchphaseisthephasethatdoesthedispatching,simplybyfindingthecorrespondingserviceandtheoperationfortheincomingmessage.Therefore,theDispatchphaseconsistsofdispatchinghandlers.PostDispatchisthephasethatisinvokedafterDispatchisbeeninvoked.
Note:
InAxis2,therearemainlytwodispatchhandlers,calledRequestURIBasedDispatcherandAddressingBasedDispatcher.
User-definedphase
Theremightbeinstanceswhenserviceormoduleauthorsneedtodefineanewphase;thosephasesarecalleduser-definedphases.Ifsomeonewantstoaddahandlerthatshouldbeinvokedafterthedispatchinghastakenplace,inthatcaseitisrequiredtodefineanewphase.Anotherimportantthingisthatphaserulehassomelimitations,asdescribedlaterinthearticle.Acombinationofbothphaserulesandphaseordersleadstobuildamoreflexibleandconfigurablehandlerchain.
Becausetherearefourtypesofflows,foreachflowphaseordersaredefinedinthesystemconfigurationfile;defininganewphasecanbedonebyjustaddinganewphaseelementintotheconfigurationfile.Thosephasescanbereferredbyanyhandler.ThedefaultconfigurationfileprovidedwithAxis2isasfollows;
--Systempredefinedphases-->
--Systempredefinedphases-->
--AfterPostdispatchphasemoduleauthororservice
authorcanaddanyphasehewants-->
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Axis2 Execution Framework