|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mortbay.HTTP.HttpHeader | +--com.mortbay.HTTP.HttpResponse
Handling of a HTTP response. Implements and extends the javax.servlet.http.HttpServletResponse interface. The extensions are for HttpHandler instances that need to modify the response or have better access to the IO.
HttpServer
Field Summary | |
static java.util.Hashtable |
__errorCodeMap
|
static java.lang.String |
Allow
|
static java.lang.String |
Expires
|
static java.lang.String |
Location
|
static java.lang.String |
MIME_Version
|
static java.lang.String |
Server
|
Fields inherited from class com.mortbay.HTTP.HttpHeader |
__COLON,
__CRLF,
__dateReceive,
__dateSend,
__singleValuedMap,
Authorization,
Chunked,
Close,
COLON,
Connection,
ContentLength,
ContentType,
Cookie,
CRLF,
Date,
Expires,
Host,
HTTP_1_0,
HTTP_1_1,
IfModifiedSince,
IfUnmodifiedSince,
LastModified,
Referer,
SetCookie,
SingleValued,
TransferEncoding,
UserAgent,
WwwAuthenticate,
WwwFormUrlEncode |
Fields inherited from interface javax.servlet.http.HttpServletResponse |
SC_ACCEPTED,
SC_BAD_GATEWAY,
SC_BAD_REQUEST,
SC_CONFLICT,
SC_CONTINUE,
SC_CREATED,
SC_FORBIDDEN,
SC_GATEWAY_TIMEOUT,
SC_GONE,
SC_HTTP_VERSION_NOT_SUPPORTED,
SC_INTERNAL_SERVER_ERROR,
SC_LENGTH_REQUIRED,
SC_METHOD_NOT_ALLOWED,
SC_MOVED_PERMANENTLY,
SC_MOVED_TEMPORARILY,
SC_MULTIPLE_CHOICES,
SC_NO_CONTENT,
SC_NON_AUTHORITATIVE_INFORMATION,
SC_NOT_ACCEPTABLE,
SC_NOT_FOUND,
SC_NOT_IMPLEMENTED,
SC_NOT_MODIFIED,
SC_OK,
SC_PARTIAL_CONTENT,
SC_PAYMENT_REQUIRED,
SC_PRECONDITION_FAILED,
SC_PROXY_AUTHENTICATION_REQUIRED,
SC_REQUEST_ENTITY_TOO_LARGE,
SC_REQUEST_TIMEOUT,
SC_REQUEST_URI_TOO_LONG,
SC_RESET_CONTENT,
SC_SEE_OTHER,
SC_SERVICE_UNAVAILABLE,
SC_SWITCHING_PROTOCOLS,
SC_UNAUTHORIZED,
SC_UNSUPPORTED_MEDIA_TYPE,
SC_USE_PROXY |
Constructor Summary | |
HttpResponse(java.io.OutputStream out,
HttpRequest request)
Construct a response |
Method Summary | |
void |
addCookie(javax.servlet.http.Cookie cookie)
Adds the specified cookie to the response. |
void |
addObserver(java.util.Observer o)
Add an observer to the response. |
void |
complete()
Complete the response. |
boolean |
containsHeader(java.lang.String headerKey)
Checks whether the response message header has a field with the specified name. |
void |
deleteObserver(java.util.Observer o)
|
void |
destroy()
Destroy the header. |
java.lang.String |
encodeRedirectUrl(java.lang.String url)
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed,
returns the URL unchanged. |
java.lang.String |
encodeRedirectURL(java.lang.String url)
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 url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. |
java.lang.String |
encodeURL(java.lang.String url)
Encode session ID in URL if required. |
java.lang.String |
getCharacterEncoding()
Returns the character set encoding for the input of this request. |
Cookies |
getCookies()
Deprecated. Use addCookie() |
javax.servlet.ServletOutputStream |
getOutputStream()
Get the OutputStream of the response. |
java.lang.String |
getReason()
|
HttpRequest |
getRequest()
Get the HttpRequest for this response |
java.lang.String |
getResponseLine()
|
java.lang.String |
getStatus()
|
java.lang.String |
getVersion()
|
java.io.PrintWriter |
getWriter()
Returns a PrintWriter object that you
can use to send character text to the client. |
boolean |
headersWritten()
Return true if the headers have already been written for this response |
boolean |
requestHandled()
Return true if the headers have already been written for this response |
void |
sendError(int code)
Sends an error response to the client using the specified status code and no default message. |
void |
sendError(int code,
java.lang.String msg)
Sends an error response to the client using the specified status code and detail message. |
void |
sendRedirect(java.lang.String location)
Sends a redirect response to the client using the specified redirect location URL. |
void |
setChunkByDefault(boolean chunk)
|
void |
setContentLength(int len)
Set the content length of the response |
void |
setContentType(java.lang.String type)
Set the content type of the response |
void |
setStatus(int code)
Sets the status code and a default message for this response. |
void |
setStatus(int code,
java.lang.String msg)
Deprecated. |
void |
setVersion(java.lang.String version)
|
void |
writeHeaders()
If the headers have not already been written, write them. |
void |
writeInputStream(java.io.InputStream stream,
long length)
Copy all data from an input stream to the HttpResponse. |
void |
writeInputStream(java.io.InputStream stream,
long length,
boolean streamIncludesHeaders)
Copy all data from an input stream to the HttpResponse. |
Methods inherited from class com.mortbay.HTTP.HttpHeader |
dump,
getDateHeader,
getHeader,
getHeaderNames,
getIntHeader,
read,
setDateHeader,
setHeader,
setIntHeader,
toString,
write,
write,
write |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final java.lang.String MIME_Version
public static final java.lang.String Server
public static final java.lang.String Expires
public static final java.lang.String Location
public static final java.lang.String Allow
public static final java.util.Hashtable __errorCodeMap
Constructor Detail |
public HttpResponse(java.io.OutputStream out, HttpRequest request)
out
- The output stream that the response will be written to.request
- The HttpRequest that this response is to.Method Detail |
public java.lang.String getVersion()
public void setVersion(java.lang.String version)
public java.lang.String getStatus()
public java.lang.String getReason()
public HttpRequest getRequest()
public java.lang.String getResponseLine()
public void setChunkByDefault(boolean chunk)
public void addObserver(java.util.Observer o)
public void deleteObserver(java.util.Observer o)
public void complete() throws java.io.IOException
public boolean headersWritten()
public boolean requestHandled()
public void writeHeaders() throws java.io.IOException
public void writeInputStream(java.io.InputStream stream, long length) throws java.io.IOException
stream
- the InputStream to readlength
- If greater than 0, this is the number of bytes
to read and writepublic void writeInputStream(java.io.InputStream stream, long length, boolean streamIncludesHeaders) throws java.io.IOException
stream
- the InputStream to readlength
- If greater than 0, this is the number of bytes
to read and writestreamIncludesHeaders
- True when the input stream includes
HTTP headers which replace those set in this HttpResponse.public Cookies getCookies()
public void setContentLength(int len)
len
- an integer specifying the length of the
content being returned to the client; sets
the Content-Length headerpublic void setContentType(java.lang.String type)
type
- a String
specifying the MIME
type of the contentServletResponse.getOutputStream()
,
ServletResponse.getWriter()
public javax.servlet.ServletOutputStream getOutputStream()
ServletOutputStream
for writing binary datagetWriter
method
for the same responseServletResponse.getWriter()
public void setStatus(int code, java.lang.String msg)
code
- the status codemsg
- the status messagepublic void setStatus(int code)
code
- the status codepublic void sendError(int code, java.lang.String msg) throws java.io.IOException
code
- the status codemsg
- the detail messagepublic void sendError(int code) throws java.io.IOException
code
- the status codepublic void sendRedirect(java.lang.String location) throws java.io.IOException
location
- the redirect location URLpublic boolean containsHeader(java.lang.String headerKey)
name
- the header field namepublic void addCookie(javax.servlet.http.Cookie cookie)
cookie
- the Cookie to return to the clientpublic java.lang.String encodeRedirectUrl(java.lang.String url)
sendRedirect
method or, if encoding is not needed,
returns the URL unchanged. The implementation of this method
should include the logic to determine whether the session ID
needs to be encoded in the URL. Because the rules for making
this determination 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 canont be used with browsers which do not support cookies.
url
- the url to be encoded.public java.lang.String encodeUrl(java.lang.String url)
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.
url
- the url to be encoded.public java.lang.String encodeRedirectURL(java.lang.String url)
sendRedirect
method or, if encoding is not needed,
returns the URL unchanged. The implementation of this method
should include the logic to determine whether the session ID
needs to be encoded in the URL. Because the rules for making
this determination 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 canont be used with browsers which do not support cookies.
After this method is called, the response should be considered to be committed and should not be written to.
url
- the url to be encoded.HttpServletResponse.sendRedirect(java.lang.String)
,
HttpServletResponse.encodeUrl(java.lang.String)
public java.lang.String encodeURL(java.lang.String url)
url
- The URL to encodepublic java.lang.String getCharacterEncoding()
public java.io.PrintWriter getWriter()
PrintWriter
object that you
can use to 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 you must call
before you call this method.
If necessary, the MIME type of the response is modified to reflect the character encoding used.
You cannot use this method if you have already
called ServletResponse.getOutputStream()
for this
ServletResponse
object.
PrintWriter
object that
can return text to the clientsetContentType
cannot be
usedgetOutputStream
method has already been called for this
response object; in that case, you can't
use this methodServletResponse.getOutputStream()
,
ServletResponse.setContentType(java.lang.String)
public void destroy()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |