public class HttpResponseImpl extends java.lang.Object implements HttpResponse
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CRLF
a line feed character
|
static java.lang.String |
CSP
a colon and space
|
static java.lang.String |
HTTP_VERSION
the HTTP version
|
static java.lang.String |
server
the server to send data from
|
static java.lang.String |
SP
a space character
|
Modifier | Constructor and Description |
---|---|
protected |
HttpResponseImpl()
creates a new instance of HttpResponseImpl with default values
|
protected |
HttpResponseImpl(int code,
java.lang.String responseString,
java.lang.String contentType)
Creates a new HttpResponseImpl with user provided parameters
|
Modifier and Type | Method and Description |
---|---|
void |
addCookie(Cookie cookie) |
void |
addDateHeader(java.lang.String s,
long l) |
void |
addHeader(java.lang.String s,
java.lang.String s1) |
void |
addIntHeader(java.lang.String s,
int i) |
boolean |
containsHeader(java.lang.String s) |
protected static HttpResponseImpl |
createError(java.lang.String message)
This could be improved at some day in the future
to also include a stack trace of the exceptions
|
protected static HttpResponseImpl |
createError(java.lang.String message,
java.lang.Throwable t)
creates an error with user defined variables
|
protected static HttpResponseImpl |
createForbidden(java.lang.String ip)
Creates a forbidden response to be sent to the browser using IP authentication
|
java.lang.String |
encodeRedirectUrl(java.lang.String s) |
java.lang.String |
encodeRedirectURL(java.lang.String s) |
java.lang.String |
encodeUrl(java.lang.String s) |
java.lang.String |
encodeURL(java.lang.String s) |
void |
flushBuffer()
Flushes the output buffer to the client.
|
int |
getBufferSize() |
java.lang.String |
getCharacterEncoding() |
int |
getCode()
gets the HTTP response code
|
java.lang.String |
getContentType()
gets the content type that will be sent to the browser
|
java.lang.String |
getHeader(java.lang.String name)
Gets a header based on the name passed in
|
java.util.Collection<java.lang.String> |
getHeaderNames() |
java.util.Collection<java.lang.String> |
getHeaders(java.lang.String s) |
java.util.Locale |
getLocale() |
ServletOutputStream |
getOutputStream()
gets the OutputStream to send data to the browser
|
java.lang.String |
getServerName()
gets the name of the server being used
|
int |
getStatus() |
java.io.PrintWriter |
getWriter() |
boolean |
isCommitted() |
void |
reset()
resets the data to be sent to the browser
|
void |
reset(int code,
java.lang.String responseString)
resets the data to be sent to the browser with the response code and response
string
|
void |
resetBuffer() |
void |
sendError(int i) |
void |
sendError(int i,
java.lang.String s) |
void |
sendRedirect(java.lang.String path) |
void |
setBufferSize(int i) |
void |
setCharacterEncoding(java.lang.String s) |
void |
setCode(int code)
sets the HTTP response code to be sent to the browser.
|
void |
setContent(java.net.URLConnection content) |
void |
setContentLength(int i) |
void |
setContentLengthLong(long length) |
void |
setContentType(java.lang.String type)
sets the content type to be sent back to the browser
|
void |
setDateHeader(java.lang.String s,
long l) |
void |
setHeader(java.lang.String name,
java.lang.String value)
sets a header to be sent back to the browser
|
void |
setIntHeader(java.lang.String s,
int i) |
void |
setLocale(java.util.Locale loc) |
protected void |
setRequest(HttpRequestImpl request) |
void |
setResponseString(java.lang.String responseString)
Sets the response string to be sent to the browser
|
void |
setStatus(int i) |
void |
setStatus(int i,
java.lang.String s) |
void |
setStatusMessage(java.lang.String responseString)
Sets the response string to be sent to the browser
|
java.lang.String |
toString()
Creates a string version of the response similar to:
HTTP/1.1 200 OK
|
protected void |
writeMessage(java.io.OutputStream output,
boolean indent)
Takes care of sending the response line, headers and body
HTTP/1.1 200 OK
Server: Netscape-Enterprise/3.6 SP3
Date: Thu, 07 Jun 2001 17:30:42 GMT
Content-Type: text/html
Connection: close
|
public static final java.lang.String HTTP_VERSION
public static final java.lang.String CRLF
public static final java.lang.String SP
public static final java.lang.String CSP
public static java.lang.String server
protected HttpResponseImpl()
protected HttpResponseImpl(int code, java.lang.String responseString, java.lang.String contentType)
code
- the HTTP Response code, see http://www.ietf.org/rfc/rfc2616.txt
for these codesresponseString
- the response string to be sent backcontentType
- the content type to be sent backprotected void setRequest(HttpRequestImpl request)
public void setHeader(java.lang.String name, java.lang.String value)
name
- the name of the headervalue
- the value of the headerpublic void setIntHeader(java.lang.String s, int i)
public void setStatus(int i)
public void setStatus(int i, java.lang.String s)
public void addCookie(Cookie cookie)
public void addDateHeader(java.lang.String s, long l)
public void addHeader(java.lang.String s, java.lang.String s1)
public void addIntHeader(java.lang.String s, int i)
public boolean containsHeader(java.lang.String s)
public java.lang.String encodeURL(java.lang.String s)
public java.lang.String encodeRedirectURL(java.lang.String s)
public java.lang.String encodeUrl(java.lang.String s)
public java.lang.String encodeRedirectUrl(java.lang.String s)
public java.lang.String getHeader(java.lang.String name)
name
- The name of the headerpublic java.util.Collection<java.lang.String> getHeaderNames()
public java.util.Collection<java.lang.String> getHeaders(java.lang.String s)
public int getStatus()
public void sendError(int i) throws java.io.IOException
java.io.IOException
public void sendError(int i, java.lang.String s) throws java.io.IOException
java.io.IOException
public void sendRedirect(java.lang.String path) throws java.io.IOException
java.io.IOException
public void setDateHeader(java.lang.String s, long l)
public ServletOutputStream getOutputStream()
public java.io.PrintWriter getWriter() throws java.io.IOException
java.io.IOException
public boolean isCommitted()
public void flushBuffer() throws java.io.IOException
HttpResponse
flushBuffer
in interface HttpResponse
java.io.IOException
public int getBufferSize()
public java.lang.String getCharacterEncoding()
public void setCode(int code)
code
- the code to be sent to the browserpublic int getCode()
public void setContentType(java.lang.String type)
setContentType
in interface HttpResponse
type
- the type to be sent to the browser (i.e. "text/html")public void setLocale(java.util.Locale loc)
public java.lang.String getContentType()
getContentType
in interface HttpResponse
public java.util.Locale getLocale()
public void setResponseString(java.lang.String responseString)
responseString
- the response stringpublic void reset()
public void resetBuffer()
public void setBufferSize(int i)
public void setCharacterEncoding(java.lang.String s)
public void setContentLength(int i)
public void setContentLengthLong(long length)
public void reset(int code, java.lang.String responseString)
code
- the code to be sent to the browserresponseString
- the response string to be sent to the browserprotected void writeMessage(java.io.OutputStream output, boolean indent) throws java.io.IOException
output
- the output to send the response tojava.io.IOException
- if an exception is thrownpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getServerName()
protected static HttpResponseImpl createError(java.lang.String message)
message
- the error message to be sentprotected static HttpResponseImpl createError(java.lang.String message, java.lang.Throwable t)
message
- the message of the errort
- a Throwable to print a stack trace toprotected static HttpResponseImpl createForbidden(java.lang.String ip)
ip
- the ip that is forbiddenpublic void setContent(java.net.URLConnection content)
content
- The content to set.public void setStatusMessage(java.lang.String responseString)
HttpResponse
setStatusMessage
in interface HttpResponse
responseString
- the response string