|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.buglabs.osgi.http.ServletResponseImpl
public class ServletResponseImpl
Basic HttpServletResponse implementation for Bug Labs HTTP Server.
| Field Summary |
|---|
| Constructor Summary | |
|---|---|
ServletResponseImpl(java.io.OutputStream outputStream,
HttpServletRequest request)
|
|
| Method Summary | |
|---|---|
void |
addCookie(Cookie cookie)
Adds the specified cookie to the response. |
void |
addDateHeader(java.lang.String arg0,
long arg1)
Adds a response header with the given name and date-value. |
void |
addHeader(java.lang.String arg0,
java.lang.String arg1)
Adds a response header with the given name and value. |
void |
addIntHeader(java.lang.String arg0,
int arg1)
Adds a response header with the given name and integer value. |
boolean |
containsHeader(java.lang.String arg0)
Returns a boolean indicating whether the named response header has already been set. |
java.lang.String |
encodeRedirectUrl(java.lang.String arg0)
|
java.lang.String |
encodeRedirectURL(java.lang.String arg0)
Encodes the specified URL for use in the sendRedirect method
or, if encoding is not needed, returns the URL unchanged. |
java.lang.String |
encodeUrl(java.lang.String arg0)
|
java.lang.String |
encodeURL(java.lang.String arg0)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. |
void |
flushBuffer()
Forces any content in the buffer to be written to the client. |
int |
getBufferSize()
Returns the actual buffer size used for the response. |
java.lang.String |
getCharacterEncoding()
Returns the name of the charset used for the MIME body sent in this response. |
java.lang.String |
getContentType()
|
java.util.Locale |
getLocale()
Returns the locale assigned to the response. |
ServletOutputStream |
getOutputStream()
Returns a ServletOutputStream suitable for writing binary data in
the response. |
java.io.PrintWriter |
getWriter()
Returns a PrintWriter object that can send character text to
the client. |
boolean |
isCommitted()
Returns a boolean indicating if the response has been committed. |
void |
reset()
Clears any data that exists in the buffer as well as the status code and headers. |
void |
resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code. |
void |
sendError(int arg0)
Sends an error response to the client using the specified status code and clearing the buffer. |
void |
sendError(int arg0,
java.lang.String arg1)
Sends an error response to the client using the specified status clearing the buffer. |
void |
sendRedirect(java.lang.String arg0)
Sends a temporary redirect response to the client using the specified redirect location URL. |
void |
setBufferSize(int arg0)
Sets the preferred buffer size for the body of the response. |
void |
setCharacterEncoding(java.lang.String charset)
|
void |
setContentLength(int arg0)
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header. |
void |
setContentType(java.lang.String arg0)
Sets the content type of the response being sent to the client. |
void |
setDateHeader(java.lang.String arg0,
long arg1)
Sets a response header with the given name and date-value. |
void |
setHeader(java.lang.String arg0,
java.lang.String arg1)
Sets a response header with the given name and value. |
void |
setIntHeader(java.lang.String arg0,
int arg1)
Sets a response header with the given name and integer value. |
void |
setLocale(java.util.Locale arg0)
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate. |
void |
setStatus(int arg0)
Sets the status code for this response. |
void |
setStatus(int arg0,
java.lang.String arg1)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ServletResponseImpl(java.io.OutputStream outputStream,
HttpServletRequest request)
| Method Detail |
|---|
public void flushBuffer()
throws java.io.IOException
ServletResponse
flushBuffer in interface ServletResponsejava.io.IOExceptionServletResponse.setBufferSize(int),
ServletResponse.getBufferSize(),
ServletResponse.isCommitted(),
ServletResponse.reset()
public ServletOutputStream getOutputStream()
throws java.io.IOException
ServletResponseServletOutputStream suitable for writing binary data in
the response. The servlet container does not encode the binary data.
Calling flush() on the ServletOutputStream commits the response.
Either this method or ServletResponse.getWriter() may be called to write the body,
not both.
getOutputStream in interface ServletResponseServletOutputStream for writing binary data
java.io.IOException - if an input or output exception occurredServletResponse.getWriter()
public java.io.PrintWriter getWriter()
throws java.io.IOException
ServletResponsePrintWriter object that can send character text to
the client. The character encoding used is the one specified in the
charset= property of the ServletResponse.setContentType(java.lang.String) method,
which must be called before calling this method for the charset to
take effect.
If necessary, the MIME type of the response is modified to reflect the character encoding used.
Calling flush() on the PrintWriter commits the response.
Either this method or ServletResponse.getOutputStream() may be called to write the
body, not both.
getWriter in interface ServletResponsePrintWriter object that can return character data
to the client
java.io.UnsupportedEncodingException - if the charset specified in setContentType
cannot be used
java.io.IOException - if an input or output exception occurredServletResponse.getOutputStream(),
ServletResponse.setContentType(java.lang.String)public boolean isCommitted()
ServletResponse
isCommitted in interface ServletResponseServletResponse.setBufferSize(int),
ServletResponse.getBufferSize(),
ServletResponse.flushBuffer(),
ServletResponse.reset()public void addCookie(Cookie cookie)
HttpServletResponse
addCookie in interface HttpServletResponsecookie - the Cookie to return to the client
public void addDateHeader(java.lang.String arg0,
long arg1)
HttpServletResponse
addDateHeader in interface HttpServletResponsearg0 - the name of the header to setHttpServletResponse.setDateHeader(java.lang.String, long)
public void addHeader(java.lang.String arg0,
java.lang.String arg1)
HttpServletResponse
addHeader in interface HttpServletResponsearg0 - the name of the headerarg1 - the additional header valueHttpServletResponse.setHeader(java.lang.String, java.lang.String)
public void addIntHeader(java.lang.String arg0,
int arg1)
HttpServletResponse
addIntHeader in interface HttpServletResponsearg0 - the name of the headerarg1 - the assigned integer valueHttpServletResponse.setIntHeader(java.lang.String, int)public boolean containsHeader(java.lang.String arg0)
HttpServletResponse
containsHeader in interface HttpServletResponsearg0 - the header name
true if the named response header has already been
set; false otherwisepublic java.lang.String encodeRedirectURL(java.lang.String arg0)
HttpServletResponsesendRedirect method
or, if encoding is not needed, returns the URL unchanged. The
implementation of this method includes the logic to determine whether the
session ID needs to be encoded in the URL. Because the rules for making
this determination can differ from those used to decide whether to encode
a normal link, this method is seperate from the encodeURL
method.
All URLs sent to the HttpServletResponse.sendRedirect method
should be run through this method. Otherwise, URL rewriting cannot be
used with browsers which do not support cookies.
encodeRedirectURL in interface HttpServletResponsearg0 - the url to be encoded.
HttpServletResponse.sendRedirect(java.lang.String),
HttpServletResponse.encodeUrl(java.lang.String)public java.lang.String encodeRedirectUrl(java.lang.String arg0)
encodeRedirectUrl in interface HttpServletResponsearg0 - the url to be encoded.
public java.lang.String encodeURL(java.lang.String arg0)
HttpServletResponseFor robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
encodeURL in interface HttpServletResponsearg0 - the url to be encoded.
public java.lang.String encodeUrl(java.lang.String arg0)
encodeUrl in interface HttpServletResponsearg0 - the url to be encoded.
public void sendError(int arg0)
throws java.io.IOException
HttpServletResponseIf the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
sendError in interface HttpServletResponsearg0 - the error status code
java.io.IOException - If an input or output exception occurs
public void sendError(int arg0,
java.lang.String arg1)
throws java.io.IOException
HttpServletResponseIf the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
sendError in interface HttpServletResponsearg0 - the error status codearg1 - the descriptive message
java.io.IOException - If an input or output exception occurs
public void sendRedirect(java.lang.String arg0)
throws java.io.IOException
HttpServletResponseIf the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
sendRedirect in interface HttpServletResponsearg0 - the redirect location URL
java.io.IOException - If an input or output exception occurs
public void setDateHeader(java.lang.String arg0,
long arg1)
HttpServletResponsecontainsHeader method can be used to test for the presence
of a header before setting its value.
setDateHeader in interface HttpServletResponsearg0 - the name of the header to setHttpServletResponse.containsHeader(java.lang.String),
HttpServletResponse.addDateHeader(java.lang.String, long)
public void setHeader(java.lang.String arg0,
java.lang.String arg1)
HttpServletResponsecontainsHeader method can be used to test for the presence
of a header before setting its value.
setHeader in interface HttpServletResponsearg0 - the name of the headerarg1 - the header valueHttpServletResponse.containsHeader(java.lang.String),
HttpServletResponse.addHeader(java.lang.String, java.lang.String)
public void setIntHeader(java.lang.String arg0,
int arg1)
HttpServletResponsecontainsHeader method can be used to test for the
presence of a header before setting its value.
setIntHeader in interface HttpServletResponsearg0 - the name of the headerarg1 - the assigned integer valueHttpServletResponse.containsHeader(java.lang.String),
HttpServletResponse.addIntHeader(java.lang.String, int)public void setStatus(int arg0)
HttpServletResponsesendError method should be used instead.
The container clears the buffer and sets the Location header, preserving cookies and other headers.
setStatus in interface HttpServletResponsearg0 - the status codeHttpServletResponse.sendError(int, java.lang.String)
public void setStatus(int arg0,
java.lang.String arg1)
setStatus in interface HttpServletResponsearg0 - the status codearg1 - the status messagepublic int getBufferSize()
ServletResponse
getBufferSize in interface ServletResponseServletResponse.setBufferSize(int),
ServletResponse.flushBuffer(),
ServletResponse.isCommitted(),
ServletResponse.reset()public java.lang.String getCharacterEncoding()
ServletResponse
If no charset has been assigned, it is implicitly set to
ISO-8859-1 (Latin-1).
See RFC 2047 (http://ds.internic.net/rfc/rfc2045.txt) for more information about character encoding and MIME.
getCharacterEncoding in interface ServletResponseString specifying the name of the charset, for
example, ISO-8859-1public java.util.Locale getLocale()
ServletResponse
getLocale in interface ServletResponseServletResponse.setLocale(java.util.Locale)public void reset()
ServletResponseIllegalStateException.
reset in interface ServletResponseServletResponse.setBufferSize(int),
ServletResponse.getBufferSize(),
ServletResponse.flushBuffer(),
ServletResponse.isCommitted()public void resetBuffer()
ServletResponseIllegalStateException.
resetBuffer in interface ServletResponseServletResponse.setBufferSize(int),
ServletResponse.getBufferSize(),
ServletResponse.isCommitted(),
ServletResponse.reset()public void setBufferSize(int arg0)
ServletResponsegetBufferSize.
A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.
This method must be called before any response body content is written;
if content has been written, this method throws an
IllegalStateException.
setBufferSize in interface ServletResponsearg0 - the preferred buffer sizeServletResponse.getBufferSize(),
ServletResponse.flushBuffer(),
ServletResponse.isCommitted(),
ServletResponse.reset()public void setContentLength(int arg0)
ServletResponse
setContentLength in interface ServletResponsearg0 - an integer specifying the length of the content being returned
to the client; sets the Content-Length headerpublic void setContentType(java.lang.String arg0)
ServletResponsetext/html; charset=ISO-8859-4.
If obtaining a PrintWriter, this method should be called
first.
setContentType in interface ServletResponsearg0 - a String specifying the MIME type of the contentServletResponse.getOutputStream(),
ServletResponse.getWriter()public void setLocale(java.util.Locale arg0)
ServletResponseServletResponse.getWriter(). By default, the response locale is
the default locale for the server.
setLocale in interface ServletResponsearg0 - the locale of the responseServletResponse.getLocale()public java.lang.String getContentType()
public void setCharacterEncoding(java.lang.String charset)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||