|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.Response org.apache.wicket.protocol.http.WebResponse
public class WebResponse
Implements responses over the HTTP protocol by holding an underlying HttpServletResponse object and providing convenience methods for using that object. Convenience methods include methods which: add a cookie, close the stream, encode a URL, redirect a request to another resource, determine if a redirect has been issued, set the content type, set the locale and, most importantly, write a String to the response output.
Field Summary | |
---|---|
protected boolean |
redirect
True if response is a redirect. |
Constructor Summary | |
---|---|
WebResponse()
Constructor for testing harness. |
|
WebResponse(javax.servlet.http.HttpServletResponse httpServletResponse)
Package private constructor. |
Method Summary | |
---|---|
void |
addCookie(javax.servlet.http.Cookie cookie)
Add a cookie to the web response |
void |
clearCookie(javax.servlet.http.Cookie cookie)
Convenience method for clearing a cookie. |
void |
close()
Closes response output. |
protected void |
configureAjaxRedirect()
Additional header configs for ajax redirects |
void |
disableCaching()
Make this response non-cacheable |
CharSequence |
encodeURL(CharSequence url)
Returns the given url encoded. |
javax.servlet.http.HttpServletResponse |
getHttpServletResponse()
Gets the wrapped http servlet response object. |
OutputStream |
getOutputStream()
|
boolean |
isAjax()
Is the request, which matches this response an ajax request. |
boolean |
isRedirect()
Whether this response is going to redirect the user agent. |
void |
redirect(String url)
CLIENTS SHOULD NEVER CALL THIS METHOD FOR DAY TO DAY USE! |
protected void |
sendRedirect(String url)
Called when Wicket wants to send a redirect to the servlet response. |
void |
setAjax(boolean ajax)
Set that the request which matches this response is an ajax request. |
void |
setAttachmentHeader(String filename)
Convenience method for setting the content-disposition:attachment header. |
void |
setContentLength(long length)
Set the content length on the response, if appropriate in the subclass. |
void |
setContentType(String mimeType)
Set the content type on the response. |
void |
setDateHeader(String header,
long date)
Set a header to the date value in the servlet response stream. |
void |
setHeader(String header,
String value)
Set a header to the string value in the servlet response stream. |
void |
setLastModifiedTime(Time time)
Set the contents last modified time, if appropriate in the subclass. |
void |
setLocale(Locale locale)
Output stream encoding. |
void |
write(AppendingStringBuffer asb)
Writes AppendingStringBuffer to response output. |
void |
write(CharSequence string)
Writes string to response output. |
Methods inherited from class org.apache.wicket.Response |
---|
detectContentType, filter, getCharacterEncoding, println, reset, setCharacterEncoding, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean redirect
Constructor Detail |
---|
public WebResponse()
public WebResponse(javax.servlet.http.HttpServletResponse httpServletResponse)
httpServletResponse
- The servlet response objectMethod Detail |
---|
public void addCookie(javax.servlet.http.Cookie cookie)
cookie
- public void clearCookie(javax.servlet.http.Cookie cookie)
cookie
- The cookie to setaddCookie(Cookie)
public void close()
close
in class Response
public CharSequence encodeURL(CharSequence url)
encodeURL
in class Response
url
- The URL to encode
public final javax.servlet.http.HttpServletResponse getHttpServletResponse()
public OutputStream getOutputStream()
getOutputStream
in class Response
Response.getOutputStream()
public final boolean isRedirect()
isRedirect
in class Response
public void redirect(String url)
Redirects to the given url. Implementations should encode the URL to make sure cookie-less operation is supported in case clients forgot.
redirect
in class Response
url
- The URL to redirect toprotected void sendRedirect(String url) throws IOException
httpServletResponse.sendRedirect(url)
. However, certain servlet
containers do not treat relative URL redirects correctly (i.e. WebSphere). If you are using
one of these containers, you can override this method and convert the relative URL to an
absolute URL before sending the redirect to the servlet container.
Example of how to fix this for your buggy container (in your application):
@Override protected WebResponse newWebResponse(HttpServletResponse servletResponse) { return new WebResponse(servletResponse) { @Override public void sendRedirect(String url) throws IOException { String reqUrl = ((WebRequest)RequestCycle.get().getRequest()).getHttpServletRequest() .getRequestURI(); String absUrl = RequestUtils.toAbsolutePath(reqUrl, url); getHttpServletResponse().sendRedirect(absUrl); } }; }
url
- the URL to redirect to
IOException
protected void configureAjaxRedirect()
public final void setContentType(String mimeType)
setContentType
in class Response
mimeType
- The mime typepublic void setContentLength(long length)
Response
setContentLength
in class Response
length
- The length of the contentResponse.setContentLength(long)
public void setLastModifiedTime(Time time)
Response
setLastModifiedTime
in class Response
time
- The time objectResponse.setLastModifiedTime(org.apache.wicket.util.time.Time)
public final void setLocale(Locale locale)
setLocale
in class Response
locale
- The locale use for mapping the character encodingServletResponse.setLocale(java.util.Locale)
public void write(CharSequence string)
write
in class Response
string
- The string to writepublic void write(AppendingStringBuffer asb)
asb
- The AppendingStringBuffer to write to the streampublic void setDateHeader(String header, long date)
header
- date
- public void setHeader(String header, String value)
header
- value
- public void setAttachmentHeader(String filename)
filename
- file name of the attachmentpublic boolean isAjax()
public void setAjax(boolean ajax)
ajax
- True if the request is an ajax request.public void disableCaching()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |