Package org.apache.wicket.request.cycle
Class RequestCycle
- java.lang.Object
-
- org.apache.wicket.request.cycle.RequestCycle
-
- All Implemented Interfaces:
IEventSink
,IMetadataContext<Object,RequestCycle>
,org.apache.wicket.request.IRequestCycle
public class RequestCycle extends Object implements org.apache.wicket.request.IRequestCycle, IEventSink, IMetadataContext<Object,RequestCycle>
RequestCycle
consists of two steps:- Resolve request handler
- Execute request handler
IRequestHandler
execution the handler can schedule anotherIRequestHandler
to run after it is done, or replace allIRequestHandler
s on stack with anotherIRequestHandler
.- Author:
- Matej Knopp, igor.vaynberg
- See Also:
scheduleRequestHandlerAfterCurrent(IRequestHandler)
,replaceAllRequestHandlers(IRequestHandler)
-
-
Constructor Summary
Constructors Constructor Description RequestCycle(RequestCycleContext context)
Construct.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
detach()
DetachesRequestCycle
state.<T extends org.apache.wicket.request.IRequestHandler>
Optional<T>find(Class<T> type)
Finds a IRequestHandler which is either the currently executing handler or is scheduled to be executed.static RequestCycle
get()
Returns request cycle associated with current thread.org.apache.wicket.request.IRequestHandler
getActiveRequestHandler()
protected int
getExceptionRetryCount()
RequestCycleListenerCollection
getListeners()
<T> T
getMetaData(MetaDataKey<T> key)
Gets metadata for this request cycle using the given key.org.apache.wicket.request.Response
getOriginalResponse()
Get the original response the request was created with.org.apache.wicket.request.Request
getRequest()
org.apache.wicket.request.IRequestHandler
getRequestHandlerScheduledAfterCurrent()
org.apache.wicket.request.Response
getResponse()
long
getStartTime()
org.apache.wicket.request.UrlRenderer
getUrlRenderer()
ReturnsUrlRenderer
for thisRequestCycle
.protected org.apache.wicket.request.IRequestHandler
handleException(Exception e)
ReturnIRequestHandler
for the given exception.<C extends Page>
org.apache.wicket.request.UrlmapUrlFor(Class<C> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters)
Returns a bookmarkable URL that references a given page class using a given set of page parameters.org.apache.wicket.request.Url
mapUrlFor(org.apache.wicket.request.IRequestHandler handler)
Returns URL for the request handler ornull
if the handler couldn't have been encoded.org.apache.wicket.request.Url
mapUrlFor(ResourceReference reference, org.apache.wicket.request.mapper.parameter.PageParameters params)
Returns aUrl
for the resource referenceprotected org.apache.wicket.request.UrlRenderer
newUrlRenderer()
protected void
onBeginRequest()
Called when the request cycle object is beginning its responsevoid
onDetach()
Called after request processing is complete, usually takes care of detaching stateprotected void
onEndRequest()
Called when the request cycle object has finished its responsevoid
onEvent(IEvent<?> event)
Called when an event is sent to this sinkboolean
processRequest()
Processes the request.boolean
processRequestAndDetach()
Convenience method that processes the request and detaches theRequestCycle
.void
replaceAllRequestHandlers(org.apache.wicket.request.IRequestHandler handler)
protected org.apache.wicket.request.IRequestHandler
resolveRequestHandler()
Resolves current request to aIRequestHandler
.void
scheduleRequestHandlerAfterCurrent(org.apache.wicket.request.IRequestHandler handler)
<T> RequestCycle
setMetaData(MetaDataKey<T> key, T object)
Sets the metadata for this request cycle using the given key.void
setRequest(org.apache.wicket.request.Request request)
INTERNAL This method is for internal Wicket use.org.apache.wicket.request.Response
setResponse(org.apache.wicket.request.Response response)
void
setResponsePage(Class<? extends IRequestablePage> pageClass)
Convenience method for setting next page to be rendered.void
setResponsePage(Class<? extends IRequestablePage> pageClass, RenderPageRequestHandler.RedirectPolicy redirectPolicy)
Convenience method for setting next page to be rendered.void
setResponsePage(Class<? extends IRequestablePage> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters)
Convenience method for setting next page to be rendered.void
setResponsePage(Class<? extends IRequestablePage> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters, RenderPageRequestHandler.RedirectPolicy redirectPolicy)
Convenience method for setting next page to be rendered.void
setResponsePage(IRequestablePage page)
Convenience method for setting next page to be rendered.<C extends Page>
CharSequenceurlFor(Class<C> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters)
Returns a rendered bookmarkable URL that references a given page class using a given set of page parameters.CharSequence
urlFor(org.apache.wicket.request.IRequestHandler handler)
Returns the rendered URL for the request handler ornull
if the handler couldn't have been rendered.CharSequence
urlFor(ResourceReference reference, org.apache.wicket.request.mapper.parameter.PageParameters params)
Returns a renderedUrl
for the resource reference
-
-
-
Constructor Detail
-
RequestCycle
public RequestCycle(RequestCycleContext context)
Construct.- Parameters:
context
-
-
-
Method Detail
-
get
public static RequestCycle get()
Returns request cycle associated with current thread.- Returns:
- request cycle instance or
null
if no request cycle is associated with current thread.
-
newUrlRenderer
protected org.apache.wicket.request.UrlRenderer newUrlRenderer()
- Returns:
- a new url renderer
-
getOriginalResponse
public org.apache.wicket.request.Response getOriginalResponse()
Get the original response the request was created with. Access to the original response may be necessary if the response has been temporarily replaced but the components require methods from original response (i.e. cookie methods of WebResponse, etc).- Returns:
- The original response object.
-
getUrlRenderer
public final org.apache.wicket.request.UrlRenderer getUrlRenderer()
ReturnsUrlRenderer
for thisRequestCycle
.- Specified by:
getUrlRenderer
in interfaceorg.apache.wicket.request.IRequestCycle
- Returns:
- UrlRenderer instance.
-
resolveRequestHandler
protected org.apache.wicket.request.IRequestHandler resolveRequestHandler()
Resolves current request to aIRequestHandler
.- Returns:
- RequestHandler instance
-
getExceptionRetryCount
protected int getExceptionRetryCount()
- Returns:
- How many times will Wicket attempt to render the exception request handler before giving up.
-
processRequestAndDetach
public boolean processRequestAndDetach()
Convenience method that processes the request and detaches theRequestCycle
.- Returns:
true
if the request resolved to a Wicket request,false
otherwise.
-
processRequest
public boolean processRequest()
Processes the request.- Returns:
true
if the request resolved to a Wicket request,false
otherwise.
-
handleException
protected org.apache.wicket.request.IRequestHandler handleException(Exception e)
ReturnIRequestHandler
for the given exception.- Parameters:
e
- exception to handle- Returns:
- RequestHandler instance
- See Also:
IRequestCycleListener.onException(RequestCycle, Exception)
,IExceptionMapper.map(Exception)
-
getRequest
public org.apache.wicket.request.Request getRequest()
- Specified by:
getRequest
in interfaceorg.apache.wicket.request.IRequestCycle
- Returns:
- current request
-
setRequest
public void setRequest(org.apache.wicket.request.Request request)
INTERNAL This method is for internal Wicket use. Do not call it yourself unless you know what you are doing.- Parameters:
request
-
-
setMetaData
public final <T> RequestCycle setMetaData(MetaDataKey<T> key, T object)
Sets the metadata for this request cycle using the given key. If the metadata object is not of the correct type for the metadata key, an IllegalArgumentException will be thrown. For information on creating MetaDataKeys, seeMetaDataKey
.- Specified by:
setMetaData
in interfaceIMetadataContext<Object,RequestCycle>
- Type Parameters:
T
-- Parameters:
key
- The singleton key for the metadataobject
- The metadata object- Throws:
IllegalArgumentException
- See Also:
MetaDataKey
-
getMetaData
public final <T> T getMetaData(MetaDataKey<T> key)
Gets metadata for this request cycle using the given key.- Specified by:
getMetaData
in interfaceIMetadataContext<Object,RequestCycle>
- Type Parameters:
T
- The type of the metadata- Parameters:
key
- The key for the data- Returns:
- The metadata or null if no metadata was found for the given key
- See Also:
MetaDataKey
-
mapUrlFor
public org.apache.wicket.request.Url mapUrlFor(org.apache.wicket.request.IRequestHandler handler)
Returns URL for the request handler ornull
if the handler couldn't have been encoded.Note: The produced URL is relative to the filter path. Application code most probably need URL relative to the currently used page, for this use urlFor(org.apache.wicket.request.IRequestHandler)
- Parameters:
handler
- therequest handler
for which to create a callback url- Returns:
- Url instance or
null
-
mapUrlFor
public org.apache.wicket.request.Url mapUrlFor(ResourceReference reference, org.apache.wicket.request.mapper.parameter.PageParameters params)
Returns aUrl
for the resource referenceNote: The produced URL is relative to the filter path. Application code most probably need URL relative to the currently used page, for this use urlFor(org.apache.wicket.request.resource.ResourceReference, org.apache.wicket.request.mapper.parameter.PageParameters)
- Parameters:
reference
- resource referenceparams
- parameters for the resource ornull
if none- Returns:
Url
for the reference
-
mapUrlFor
public final <C extends Page> org.apache.wicket.request.Url mapUrlFor(Class<C> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters)
Returns a bookmarkable URL that references a given page class using a given set of page parameters. Since the URL which is returned contains all information necessary to instantiate and render the page, it can be stored in a user's browser as a stable bookmark.Note: The produced URL is relative to the filter path. Application code most probably need URL relative to the currently used page, for this use urlFor(Class, org.apache.wicket.request.mapper.parameter.PageParameters)
- Type Parameters:
C
- The type of the page- Parameters:
pageClass
- Class of pageparameters
- Parameters to page ornull
if none- Returns:
- Bookmarkable URL to page
-
urlFor
public final CharSequence urlFor(ResourceReference reference, org.apache.wicket.request.mapper.parameter.PageParameters params)
Returns a renderedUrl
for the resource reference- Parameters:
reference
- resource referenceparams
- parameters for the resource ornull
if none- Returns:
Url
for the reference
-
urlFor
public final <C extends Page> CharSequence urlFor(Class<C> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters)
Returns a rendered bookmarkable URL that references a given page class using a given set of page parameters. Since the URL which is returned contains all information necessary to instantiate and render the page, it can be stored in a user's browser as a stable bookmark.- Type Parameters:
C
-- Parameters:
pageClass
- Class of pageparameters
- Parameters to page ornull
if none- Returns:
- Bookmarkable URL to page
-
urlFor
public CharSequence urlFor(org.apache.wicket.request.IRequestHandler handler)
Returns the rendered URL for the request handler ornull
if the handler couldn't have been rendered.The resulting URL will be relative to current page.
- Parameters:
handler
-- Returns:
- Url String or
null
-
detach
public final void detach()
DetachesRequestCycle
state. Called after request processing is complete
-
onDetach
public void onDetach()
Called after request processing is complete, usually takes care of detaching state
-
setResponsePage
public void setResponsePage(IRequestablePage page)
Convenience method for setting next page to be rendered.- Parameters:
page
-
-
setResponsePage
public void setResponsePage(Class<? extends IRequestablePage> pageClass)
Convenience method for setting next page to be rendered.- Parameters:
pageClass
- The class of the page to render
-
setResponsePage
public void setResponsePage(Class<? extends IRequestablePage> pageClass, RenderPageRequestHandler.RedirectPolicy redirectPolicy)
Convenience method for setting next page to be rendered.- Parameters:
pageClass
- The class of the page to renderredirectPolicy
- The policy to use when deciding whether to redirect or not
-
setResponsePage
public void setResponsePage(Class<? extends IRequestablePage> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters)
Convenience method for setting next page to be rendered.- Parameters:
pageClass
- The class of the page to renderparameters
- The query parameters for the page to be rendered
-
setResponsePage
public void setResponsePage(Class<? extends IRequestablePage> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters, RenderPageRequestHandler.RedirectPolicy redirectPolicy)
Convenience method for setting next page to be rendered.- Parameters:
pageClass
- The class of the page to renderparameters
- The query parameters for the page to be renderedredirectPolicy
- The policy to use when deciding whether to redirect or not
-
getStartTime
public final long getStartTime()
- Returns:
- The start time for this request
-
onEvent
public void onEvent(IEvent<?> event)
Called when an event is sent to this sink- Specified by:
onEvent
in interfaceIEventSink
-
onBeginRequest
protected void onBeginRequest()
Called when the request cycle object is beginning its response
-
onEndRequest
protected void onEndRequest()
Called when the request cycle object has finished its response
-
getListeners
public RequestCycleListenerCollection getListeners()
- Returns:
- listeners
-
getResponse
public org.apache.wicket.request.Response getResponse()
- Specified by:
getResponse
in interfaceorg.apache.wicket.request.IRequestCycle
-
setResponse
public org.apache.wicket.request.Response setResponse(org.apache.wicket.request.Response response)
- Specified by:
setResponse
in interfaceorg.apache.wicket.request.IRequestCycle
-
scheduleRequestHandlerAfterCurrent
public void scheduleRequestHandlerAfterCurrent(org.apache.wicket.request.IRequestHandler handler)
- Specified by:
scheduleRequestHandlerAfterCurrent
in interfaceorg.apache.wicket.request.IRequestCycle
-
getActiveRequestHandler
public org.apache.wicket.request.IRequestHandler getActiveRequestHandler()
- Returns:
- active handler on executor
- See Also:
RequestHandlerExecutor.getActive()
-
getRequestHandlerScheduledAfterCurrent
public org.apache.wicket.request.IRequestHandler getRequestHandlerScheduledAfterCurrent()
- Returns:
- the handler scheduled to be executed after current by the executor
- See Also:
RequestHandlerExecutor.next()
-
replaceAllRequestHandlers
public void replaceAllRequestHandlers(org.apache.wicket.request.IRequestHandler handler)
- Parameters:
handler
-- See Also:
RequestHandlerExecutor.replaceAll(IRequestHandler)
-
find
public <T extends org.apache.wicket.request.IRequestHandler> Optional<T> find(Class<T> type)
Finds a IRequestHandler which is either the currently executing handler or is scheduled to be executed.- Returns:
- the found IRequestHandler or
Optional.empty()
-
-