|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.wicket.request.Request
org.apache.wicket.request.http.WebRequest
org.apache.wicket.mock.MockWebRequest
public class MockWebRequest
Mutable mock WebRequest
.
Field Summary |
---|
Fields inherited from class org.apache.wicket.request.http.WebRequest |
---|
HEADER_AJAX, HEADER_AJAX_BASE_URL, PARAM_AJAX, PARAM_AJAX_BASE_URL |
Constructor Summary | |
---|---|
MockWebRequest(Url url)
Construct. |
Method Summary | |
---|---|
void |
addCookie(javax.servlet.http.Cookie cookie)
|
void |
addDateHeader(String name,
long value)
Adds date header for given name. |
void |
addHeader(String name,
String value)
Adds header for given name. |
MockWebRequest |
cloneWithUrl(Url url)
Returns request with specified URL and same POST parameters as this request. |
Charset |
getCharset()
Gets charset of the request |
Url |
getClientUrl()
Returns the url against which the client, usually the browser, will resolve relative urls in the rendered markup. |
Object |
getContainerRequest()
Provides access to the low-level container request object that implementaion of this Request delegate to. |
List<javax.servlet.http.Cookie> |
getCookies()
|
long |
getDateHeader(String name)
Returns the value of the specified request header as a long value that
represents a Date object. |
String |
getHeader(String name)
Returns the value of the specified request header as a String |
List<String> |
getHeaders(String name)
Returns all the values of the specified request header. |
Locale |
getLocale()
Returns locale for this request. |
MockRequestParameters |
getPostParameters()
|
Url |
getUrl()
Returns the URL for this request. |
void |
removeHeader(String header)
Removes header with specified name. |
void |
setCookies(List<javax.servlet.http.Cookie> cookies)
Sets cookies for current request. |
void |
setDateHeader(String name,
long value)
Sets date header for given name. |
void |
setHeader(String name,
String value)
Sets header for given name. |
void |
setLocale(Locale locale)
Sets request locale. |
void |
setUrl(Url url)
|
String |
toString()
|
Methods inherited from class org.apache.wicket.request.http.WebRequest |
---|
getCookie, getIfModifiedSinceHeader, isAjax |
Methods inherited from class org.apache.wicket.request.Request |
---|
getOriginalUrl, getPrefixToContextPath, getQueryParameters, getRequestParameters |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MockWebRequest(Url url)
url
- Method Detail |
---|
public MockWebRequest cloneWithUrl(Url url)
WebRequest
cloneWithUrl
in class WebRequest
url
- Url instance
public void setUrl(Url url)
public Url getUrl()
Request
getUrl
in class Request
public String toString()
toString
in class Object
public void setCookies(List<javax.servlet.http.Cookie> cookies)
cookies
- public void addCookie(javax.servlet.http.Cookie cookie)
public List<javax.servlet.http.Cookie> getCookies()
getCookies
in class WebRequest
public long getDateHeader(String name)
WebRequest
long
value that
represents a Date
object. Use this method with headers that contain dates, such
as If-Modified-Since
.
getDateHeader
in class WebRequest
public void setDateHeader(String name, long value)
name
- value
- public void addDateHeader(String name, long value)
name
- value
- public String getHeader(String name)
WebRequest
String
getHeader
in class WebRequest
public void setHeader(String name, String value)
name
- value
- public void addHeader(String name, String value)
name
- value
- public void setLocale(Locale locale)
locale
- public Locale getLocale()
Request
getLocale
in class Request
public List<String> getHeaders(String name)
WebRequest
getHeaders
in class WebRequest
public void removeHeader(String header)
header
- public MockRequestParameters getPostParameters()
getPostParameters
in class Request
public Charset getCharset()
Request
getCharset
in class Request
public Url getClientUrl()
Request
Under normal circumstances the client and request (Request.getUrl()
) urls are the same.
Handling an Ajax request, however, is a good example of when they may be different.
Technologies such as XHR are free to request whatever url they wish without
modifying the client url; however, any produced urls will be evaluated by the client
against the client url - not against the request url.
Lets take a simple example:
Suppose we are on a client detail page. This page contains an Ajax link which opens a list of
client's orders. Each order has a link that goes to the order detail page.
The client detail page is located at
/detail/customer/15and the order detail page is located at
/order/22The Ajax link which renders the detail section is located at
/detail/wicket?page 3Lets run through the execution and see what happens when the XHR request is processed:
request 1: /details/customer/15 client url: details/customer/15 (the url in the browser's address bar) request url: details/customer/15 Wicket renders relative Ajax details anchor as ../../wicket/page?3 ../../wicket/page?3 resolved against current client url details/customer/15 yields: request 2: /wicket/page?3 client url: customer/15 (unchanged since XHRs requests dont change it) request url: wicket/ajax/page?3 now Wicket has to render a relative url to /details/order/22. If Wicket renders it against the request url it will be: ../order/22, and later evaluated on the client will result in /customer/order/22 which is incorrect.This is why implementations of
Request
must track the client url, so that relative
urls can be rendered against the same url they will be evaluated against on the client -
which is not always the same as the request url. For example, Wicket's Ajax implementation
always sends the current client url in a header along with the XHR request so that Wicket can
correctly render relative urls against it.
getClientUrl
in class Request
public Object getContainerRequest()
Request
Request
delegate to. This allows users to access features provided by the container
requests but not by generalized Wicket Request
objects.
getContainerRequest
in class Request
null
if none
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |