|
Page Edited :
WICKET :
Request cycle and request cycle processor
Request cycle and request cycle processor has been edited by Gwyn Evans (Jan 23, 2008). Change summary: Edited to trigger a refresh to the static site now new attatchments available
RequestCycleThe main responsibility of request cycle is instructing request cycle processor which steps of request handling to execute (see diagram of request cycle processor usage). Request cycle goes through several states and depending on the current state it sends different instruction to request cycle processor (see RequestCycle#step()). After sending all instructions request cycle reaches final state which denotes the end of request processing. Besides that request cycle stores list of request targets which are produced by request cycle processor (see RequestCycle#setResponsePage(), RequestCycle#setRequestTarget()). From framework user's point of view, the request cycle has some other useful functionality:
These calls happen in context of request processing; for bigger picture see diagram of request cycle processor usage. Request cycle calls prepare() method before sending any instructions to request cycle processor and detach() after sending all instructions or catching exception. Note that this detach() call initiates all other calls for pages, components and models. New instance of RequestCycle is created on every request by WebApplication class. This is a pseudo code of how request cycle is created and used: class WicketServlet ... public final void doGet(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) { ... // WebApplication instance is already created while initializing servlet/filter final WebRequest request = webApplication.newWebRequest(servletRequest); final WebResponse response = webApplication.newWebResponse(servletResponse); RequestCycle cycle = webApplication.newRequestCycle(request, response); cycle.request(); // <--- request processing starts ... } Note that after creation request() method, which starts request processing, is called on RequestCycle. It's possible to customize creation of request cycle by overriding WebApplication#newRequestCycle().
Note that RequestCycle delegates events processing and response generation to created request target.
There is one instance of request cycle processor per Application. It is lazily created during the first request. Its creation can be customized by overriding WebApplication#newRequestCycleProcessor(). Request cycle processor instance can be obtained using WebApplication#getRequestCycleProcessor() method. Exception handlingWicket uses RuntimeExceptions with WicketRuntimeException, AbortException as superclasses. It means that Wicket classes do not throw checked exceptions and therefore user code that extends Wicket classes cannot do that either. Although it's possible to throw checked exception in component constructor and ultimately throw it in page constructor, this exception will be wrapped by Wicket with WicketRuntimeException (it will happen in one of DefaultPageFactory#newPage() methods). All runtime exceptions thrown during request processing are propagated down to RequestCycle. After catching exception request cycle delegates its handling to AbstractRequestCycleProcessor as it's shown in diagram below. Request cycle processor attempts to find on which page this exception happened and calls AbstractRequestCycleProcessor#onRuntimeException() which by default calls similar method in RequestCycle (see Exception handling in Wicket |
Unsubscribe or edit your notifications preferences
