package org.apache.wicket;
Represents the processing of a request. It is responsible for instructing the
request cycle processor to execute the various steps there are in
the handling of a request (resolving the kind of work that needs to be done, handling of events
and generating a response), and it holds the intended
request target,
which is an abstraction for e.g. the processing of a bookmarkable page.
The abstract urlFor() methods are implemented by subclasses of RequestCycle and return encoded
page URLs. The URL returned depends on the kind of page being linked to. Pages broadly fall into
two categories:
| 1. | A page that does not yet exist in a user Session may be encoded as a URL that references the
not-yet-created page by class name. A set of PageParameters can also be encoded into the URL, and
these parameters will be passed to the page constructor if the page later needs to be
instantiated.
Any page of this type is bookmarkable, and a hint to that effect is given to the user in the URL:
/[Application]?bookmarkablePage=[classname]&[param]=[value] [...]
Bookmarkable pages must either implement a constructor that takes a PageParameters argument or a
default constructor. If a Page has both constructors the constructor with the PageParameters
argument will be used. Links to bookmarkable pages are created by calling the urlFor(Class,
PageParameters) method, where Class is the page class and PageParameters are the parameters to
encode into the URL.
|
| 2. | Stateful pages (that have already been requested by a user) will be present in the user's
Session and can be referenced securely with a session-relative number:
/[Application]?wicket:interface=[pageMapName]:[pageId]: ...
Often, the reason to access an existing session page is due to some kind of "postback" (either a
link click or a form submit) from a page (possibly accessed with the browser's back button or
possibly not). A call to a registered listener is dispatched like so:
/[Application]?wicket:interface=[pageMapName]:[pageId]:[componentPath]:[version]:[interfaceName]
For example:
/[Application]?wicket:interface=:3:signInForm:submit::IFormSubmitListener
|
URLs for stateful pages (those that already exist in the session map) are created by calling the
urlFor(Component, Class) method, where Component is the component being linked to and Class is
the interface on the component to call.
For pages falling into the second category, listener interfaces cannot be invoked unless they
have first been registered via the static registerSecureInterface() method. This method ensures
basic security by restricting the set of interfaces that outsiders can call via GET and POST
requests. Each listener interface has a single method which takes only a RequestCycle parameter.
Currently, the following classes register the following kinds of listener interfaces:
| Class | Interface | Purpose |
|---|
| Form | IFormSubmitListener | Handle form submits |
| Image | IResourceListener | Respond to image resource requests |
| Link | ILinkListener | Respond to link clicks |
| Page | IRedirectListener | Respond to redirects |
The redirectToInterceptPage() and continueToOriginalDestination() methods can be used to
temporarily redirect a user to some page. This is mainly intended for use in signing in users who
have bookmarked a page inside a site that requires the user be authenticated before they can
access the page. When it is discovered that the user is not signed in, the user is redirected to
the sign-in page with redirectToInterceptPage(). When the user has signed in, they are sent on
their way with continueToOriginalDestination(). These methods could also be useful in
"interstitial" advertising or other kinds of "intercepts".
- Author(s):
- Jonathan Locke
- Eelco Hillenius
- Igor Vaynberg (ivaynberg)
Thread-local that holds the current request cycle.
Cleaning up after responding to a request.
Request cycle processing is done.
private static final int DONE = 6;
No processing has been done.
Starting the actual request processing.
Dispatching and handling of events.
private static final int RESPOND = 4;
Gets request cycle for calling thread.
- Returns:
- Request cycle for calling thread
Sets the request cycle for the calling thread. You typically DO NOT NEED to call this method,
as the request cycle is set to current for you in the constructor. However, if you have a
very special need to set it to
something else, you can expose this method.
- Parameters:
cycle
The request cycle to set current
True if the request cycle should automatically clear feedback messages after processing. True
by default.
The current stage of event processing.
The original response the request cycle was created with.
True if request should be redirected to the resulting page instead of just rendering it back
to the user.
private static final long serialVersionUID = 1L;
return super.addAll(arg0, arg1);
Any page parameters. Only set when the request is resolving and the parameters are passed
into a page.
the time that this request cycle object was created.
The processor for this request.
Boolean if the next to be encoded url is targeting a new window (ModalWindow, popup, tab).
This temporary flag is specifically needed for portlet-support as then such a page needs a
special target (Resource) url. After each urlFor call, this flag is reset to false.
Constructor. This instance will be set as the current one for this thread.
- Parameters:
application
The applicationrequest
The requestresponse
The response
Gets the application object.
- Returns:
- Application interface
Gets the new agent info object for this session. This method calls
Session.getClientInfo(), which may or may not cache the client info object and
typically calls
newClientInfo() when no client info object was cached.
- Returns:
- the agent info object based on this request
Get the original response the request was create with. Access may be necessary with the
response has temporarily being replaced but your components requires access to lets say the
cookie methods of a WebResponse.
- Returns:
- The original response object.
Gets the processor for delegated request cycle handling.
- Returns:
- the processor for delegated request cycle handling
Gets whether the page for this request should be redirected.
- Deprecated:
- Use
isRedirect() instead - Returns:
- whether the page for this request should be redirected
Gets the current request target. May be null.
- Returns:
- the current request target, null if none was set yet.
- Returns:
- The start time for this request
Gets whether the page for this request should be redirected.
- Returns:
- whether the page for this request should be redirected
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
Redirects browser to the given page. Don't use this method directly, but use
setResponsePage(org.apache.wicket.Page) instead.
- Parameters:
page
The page to redirect to
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
Responds to a request.
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
Responds to a request to re-render a single component.
NOTE: This method is typically only used for testing purposes.
- Parameters:
component
to be re-rendered
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
Responds to a request with the request target.
- Parameters:
target
request target
Permit clients like testers to examine feedback messages after processing.
- Parameters:
automaticallyClearFeedbackMessages
True to automatically detach request cycle at end of processing
Sets whether the page for this request should be redirected.
- Parameters:
redirect
True if the page for this request cycle should be redirected to rather than
directly rendered.
- Parameters:
request
The request to set.
Sets the request target as the current.
- Parameters:
requestTarget
the request target to set as current
log.debug("replacing request target " + former + " with " + requestTarget); log.debug("setting request target to " + requestTarget); log.debug("rewinding request processing to PROCESS_EVENTS"); Called when a request target is set on the request cycle
Sets response.
- Parameters:
response
The response- Returns:
- the original response
Attempts to return name of current page map
- Returns:
- name of current page map
Convenience method that sets page class as the response. This will generate a redirect to the
page with a bookmarkable url
- Parameters:
pageClass
The page class to render as a response
Sets the page class with optionally the page parameters as the render target of this request.
- Parameters:
pageClass
The page class to render as a responsepageParameters
The page parameters that gets appended to the bookmarkable url,
Sets the page class with optionally the page parameters and page map name as the render
target of this request.
- Parameters:
pageClass
The page class to render as a responsepageParameters
The page parameters that gets appended to the bookmarkable url,pageMapName
The pagemap in which the response page should be created
Sets the page as the render target of this request.
- Parameters:
page
The page to render as a response
- Returns:
- true if the next to be encoded url is targeting a new window (ModalWindow, popup,
tab).
Indicate if the next to be encoded url is targeting a new window (ModalWindow, popup, tab).
This temporary flag is specifically needed for portlet-support as then such a page needs a
special target (Resource) url. After each urlFor call, this flag is reset to false.
Returns an encoded URL that references the given request target and clears the
urlForNewWindowEncoding flag.
- Parameters:
requestTarget
the request target to reference- Returns:
- a URL that references the given request target
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.
- Parameters:
pageClass
Class of pageparameters
Parameters to page- Returns:
- Bookmarkable URL to page
return urlFor(null, pageClass, parameters);
Returns a URL that references a given interface on a given behavior of a component. When the
URL is requested from the server at a later time, the interface on the behavior will be
called. A URL returned by this method will not be stable across sessions and cannot be
bookmarked by a user.
- Parameters:
component
The component to referencebehaviour
The behavior to referencelistener
The listener interface on the component- Returns:
- A URL that encodes a page, component, behavior and interface to call
" was not registered with this component: " + component.toString());
Returns a URL that references a given interface on a component. When the URL is requested
from the server at a later time, the interface will be called. A URL returned by this method
will not be stable across sessions and cannot be bookmarked by a user.
- Parameters:
component
The component to referencelistener
The listener interface on the componentparams
Additional parameters to pass to the page- Returns:
- A URL that encodes a page, component and interface to call
if (pageParameters == null)
pageParameters.add(key, value);
page.getClass(), pageParameters, component, listener);
Url encodes value using UTF-8
- Parameters:
value
value to encode- Returns:
- encoded value
Returns a URL that references a given interface on a component. When the URL is requested
from the server at a later time, the interface will be called. A URL returned by this method
will not be stable across sessions and cannot be bookmarked by a user.
- Parameters:
component
The component to referencelistener
The listener interface on the component- Returns:
- A URL that encodes a page, component and interface to call
return urlFor(component, listener, null);
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.
- Parameters:
pageMap
Pagemap to use. If null is passed the default page map will be usedpageClass
Class of pageparameters
Parameters to page- Returns:
- Bookmarkable URL to page
Returns a URL that references the given request target.
- Parameters:
requestTarget
the request target to reference- Returns:
- a URL that references the given request target
Returns a URL that references the given page. It also
touches the
page in the session so that it is put in the front of the page stack. Use this method only if
you plan to use it the next request.
- Parameters:
page
The page- Returns:
- The url pointing to the provided page
Returns a URL that references a shared resource through the provided resource reference.
- Parameters:
resourceReference
The resource reference where a url must be generated for.- Returns:
- The url for the shared resource
return urlFor(resourceReference, null);
Returns a URL that references a shared resource through the provided resource reference.
- Parameters:
resourceReference
The resource reference where a url must be generated for.parameters
The parameters to pass to the resource.- Returns:
- The url for the shared resource
Checks whether no processing has been done yet and throws an exception when a client tries to
reuse this instance.
"RequestCycles are non-reusable objects. This instance (" + this + THIS METHOD IS WICKET PRIVATE API. DO NOT CALL UNLESS YOU KNOW WHAT YOU ARE DOING. Clean up
the request cycle.
log.error("there was an error cleaning up target " + target + ".", e); log.error("there was an error cleaning up the feedback messages", re); log.error("there was an error detaching the request from the session " + session + log.error("there was an error filtering the response.", re); log.error("Exception occurred during onEndRequest", e); log.error("Exception occurred during onEndRequest of the SessionStore", e); if (requestLogger != null)
log.error("there was an error in the RequestLogger ending.", re); log.error("Exception occurred during threadDetach", re); Prepare the request cycle.
log.error("Exception occurred during onEndRequest of the SessionStore", e); Call the event processing and and respond methods on the request processor and apply
synchronization if needed.
Call the event processing and and respond methods on the request processor and apply
synchronization if needed.
Safe version of
getProcessor() that throws an exception when the processor is null.
- Returns:
- the request processor
- Returns:
- True if a session exists for the calling thread
handle the current step in the request processing.
private final void step()
"unexpected exception when handling another exception: " + e.getMessage(), e);
INTERNAL. This method is not part of public Wicket Api. Do not call it. Returns whether
wicket handled this request or not (i.e. when no request target was found).
- Returns:
- true if wicket handled this request, false otherwise
Loop through the processing steps starting from the current one.
private final void steps()
final int maxSteps = 100;
if (totalSteps >= maxSteps)
" steps, which means it is probably in an infinite loop.");
Releases the current thread local related resources. The threadlocal of this request cycle is
reset. If we are in a 'redirect' state, we do not want to lose our messages as - e.g. when
handling a form - there's a fat chance we are coming back for the rendering of it.
log.error("there was an error detaching the session", re); Possibly set the page parameters. Only set when the request is resolving and the parameters
are passed into a page.
- Parameters:
parameters
the parameters to set
Called when an unrecoverable runtime exception during request cycle handling occurred, which
will result in displaying a user facing error page. Clients can override this method in case
they want to customize logging. NOT called for
page expired
exceptions.
- Parameters:
e
the runtime exception
Creates a new agent info object based on this request. Typically, this method is called once
by the session and the returned object will be cached in the session after that call; we can
expect the client to stay the same for the whole session, and implementations of
newClientInfo() might be relatively expensive.
- Returns:
- the agent info object based on this request
Called when the request cycle object is beginning its response
Called when the request cycle object has finished its response
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, see
MetaDataKey.
Gets metadata for this request cycle using the given key.
- Parameters:
key
The key for the data- Returns:
- The metadata or null if no metadata was found for the given key
- See also:
MetaDataKey