stapler HTTP请求处理引擎开源项目

我要开发同款
匿名用户2018年12月27日
136阅读

技术信息

开源地址
https://github.com/stapler/stapler
授权协议
BSD

作品详情

Staplerisalibrarythat"staples"yourapplicatioobjectstoURLs,makigiteasiertowritewebapplicatios.ThecoreideaofStapleristoautomaticallyassigURLsforyourobjects,creatigaituitiveURLhierarchy.

Normally,mostofyourJSPadservletgoeslikethis;first,youuseparametersadextrapathifotolocatetheobjecttoworkwith,theusesomemoreparametersadsuchtoperformsomeoperatiosagaistit(orperhapsrederHTML).Staplertakescareofthisfirstportiobydispatchigrequeststothatobjectyou'llbeworkigwith.

Supposeyouarebuildigawebapplicatiolikethesystemofjava.et,whereyougotprojects,mailiglists,documetsadfilessectio,adetc.ThefollowigfigureshowshowStaplerworks.

Thelefthalfshowsyourcode.OOPletsyoumodelthosecoceptsstraight-forwardlyitoclassesthatrefertoeachother.Throughreflectio,StaplerassigsURLstoyourapplicatioobjects.TherootofyourapplicatioobjectgetstherootURL /.Theobjectyoucaaccesswith root.getProject("stapler") wouldbeassigedtotheURL /project/stapler.Ithisway,yourobjectmodeldirectlytursitotheURLhierarchy,aspartiallyshowipurplearrows.

JSPsadservlets

MostofthetimesJSPsareusedtoshowaobjectiyourapplicatio.StaplerallowsyoutoassociateJSPstoyourapplicatioclasses,asshowigreecirclesitheabovefigure.StaplerweavesthoseJSPsitotheURLhierarchy,adwhetheygetrequested,Staplersetsuptheevirometsuchthattheycaaccessthecorrespodigapplicatioobjectveryeasily,bythe"it"variable(like${it.ame}).

Similarly,ofteyouwattorusomeJavacodewheacertaiURLisrequested,asshowiredcirclesitheabovefigure.Forexample,whe /project/stapler/delete isrequested,you'dliketodeletetheprojectadredirecttheuserto /.WithStapler,thisisaseasyasdefiigamethodoyourapplicatioobjects.Staplerivokesthemethodotherightobject.

ProblemsThatStaplerSolves

Servlet(adtechologieslikeJSP/JSFthatbuildsotopofit)caolybidrequestURLsitoyourstaticresources,JSPs,ad/orservletsiaverylimitedway.Youcaevetellthatfromthejava.etsystem.Forexample,theURLtoviewthearchiveofamailiglistis /servlets/SummarizeList?listName=aouce,theURLtosearchthearchiveif /servlets/SearchList?listName=aouce,adtheURLtomaageitis /servlets/MailigListEdit?list=aouce.

Thishassomeproblems.

RelativeURLsareuseless

Ordiaryservlet/JSPprevetsyoufromusigtheURLhierarchytoorgaizeyourapplicatio.Ithejava.etsystem,ifyouwattogeeratealikfromthearchivetothesearchpage,youhavetoputthewholeURLicludigalltheparameters.You'llbewritigsomethiglike /servlets/SearchList?list=${listName}.Asyourapplicatiogetsmorecomplicated,theumberofparameterswillicrease,makigyourapplicatioharderadhardertomaitai.

StaplerallowsyoutouseURLslike list/aouce/summarize, list/aouce/search,ad list/aouce/edit.Thusalikfromthesummarypagetothesearchissimply search.

Alotofboiler-platecode

Mostofthetimes,thefirstthigyourJSPsadservletseedtodoistolocatetheobjectthatyou'llbeworkigwith.Thisistedious.Eveworse,iteedstoberepeatedimayplaces.

Staplertakescareofthisforyou.WheyourJSPisivoked,youcaaccessthetargetobjectbythevariable"it".Orwheyouractiomethod(theequivaletoftheservlet)isivoked,itisivokedothetargetobject.Thiscutsdowalotofborigboiler-platecodeiyourapplicatio.

RecursiveStructure

Servletsca'thadlerecursivedirectorystructureverywell.Itheabovefigure,Ihaverecursive Folder classthathastwoJSPseach.TheolywaytomakethisworkiservletistoassiguiqueIDstoeachfolderaddefiethoseJSPsatthetop-level.TheactualURLswillbeverydifferetfromtheaturaltreestructure.

StaplermapsthisveryaturallytoURLs.

功能介绍

Stapler is a library that "staples" your application objects to URLs, making it easier to write w...

示例图片

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论