|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.http.FilterResponse
public class FilterResponse
The FilterResponse
object is used so that the original
Response
object can be wrapped in a filtering proxy
object. This allows a ProtocolHandler
to interact with
the Response
object in a concurrent environment. This
is also useful if any special behavior is need when a HTTP header
with special significance is added.
The above is an example of how the
public void handle(Request req, Response resp) {
handler.handle(req, new ZipResponse(resp));
}
FilterResponse
can
be used to provide extra functionality to a Response
in a transparent manner. Such an implementation could apply a
Content-Encoding header and compress the response for performance
over a slow network. Filtering can be applied with the use of
layered ProtocolHandler
objects, an example of such
layering is the simple.http.serve.DomainHandler
.
Field Summary | |
---|---|
protected Response |
resp
This is the object that is being wrapped. |
Constructor Summary | |
---|---|
FilterResponse(Response resp)
Constructor for FilterResponse allows the original
Response object to be wrapped so that adjustments
to the behavior of a Response object handed to a
specialized ProtocolHandler can be done simply. |
Method Summary | |
---|---|
void |
add(java.lang.String name,
int value)
This can be used to add a HTTP message header to this object. |
void |
add(java.lang.String name,
java.lang.String value)
This can be used to add a HTTP message header to this object. |
void |
addDate(java.lang.String name,
long date)
This is used as a convenience method for adding a header that needs to be parsed into a HTTP-date string. |
void |
clear()
This is used to clear all HTTP message headers from the message header. |
void |
commit()
This is used to write the headers that where given to the Response . |
boolean |
contains(java.lang.String name)
This is used to see if there is a HTTP message header with the given name in this container. |
boolean |
contains(java.lang.String name,
java.lang.String value)
This is used to see if there is a HTTP message header with the given name in this container, if it exists this will check to see if the provided value exists. |
java.lang.Object |
getAttribute(java.lang.String name)
This is used as a shortcut for acquiring attributes for the response. |
Attributes |
getAttributes()
This can be used to retrieve certain attributes about this Response . |
int |
getCode()
This represents the status code of the HTTP response. |
long |
getDate(int off)
This can be used to get the value of the HTTP message header at the specified index. |
long |
getDate(java.lang.String name)
This can be used to get the date of the first message header that has the specified name. |
java.net.InetAddress |
getInetAddress()
This can be used to get the I.P address for the browser that the Response goes to. |
int |
getMajor()
This can be used to get the major number from a HTTP version. |
int |
getMinor()
This can be used to get the minor number from a HTTP version. |
java.lang.String |
getName(int off)
This is used to get the name value of the HTTP message header at the specified index. |
java.io.OutputStream |
getOutputStream()
Used to write a message body with the Response . |
java.io.OutputStream |
getOutputStream(int size)
Used to write a message body with the Response . |
java.io.PrintStream |
getPrintStream()
This method is provided for convenience so that the HTTP content can be written using the print methods provided by
the PrintStream . |
java.io.PrintStream |
getPrintStream(int size)
This method is provided for convenience so that the HTTP content can be written using the print methods provided by
the PrintStream . |
java.lang.String |
getText()
This can be used to retrieve the text of a HTTP status line. |
java.lang.String |
getValue(int off)
This is used to get the date value of the HTTP message header at the specified index. |
java.lang.String |
getValue(java.lang.String name)
This can be used to get the value of the first message header that has the specified name. |
java.lang.String[] |
getValues(java.lang.String name)
This can be used to get the values of HTTP message headers that have the specified name. |
int |
headerCount()
This can be used to determine how many HTTP message headers this object contains. |
int |
indexOf(java.lang.String name)
This can be used to find the first occurrence of the specified HTTP message header. |
int |
indexOf(java.lang.String name,
int from)
This can be used to find the first occurrence of the specified HTTP message header from a given index. |
boolean |
isCommitted()
This can be used to determine whether the Response
has been committed. |
void |
remove(int off)
This can be used to remove the HTTP message header at the specified index. |
void |
removeAll(java.lang.String name)
This can be used to remove all HTTP message headers with the specified name. |
void |
reset()
The reset method is used to reset the output
from an issued OutputStream . |
void |
set(java.lang.String name,
int value)
This can be used to set a HTTP message header to this object. |
void |
set(java.lang.String name,
java.lang.String value)
This can be used to set a HTTP message header to this object. |
void |
setCode(int code)
This method allows the status for the response to be changed. |
void |
setContentLength(int length)
This should be used when the size of the message body is known. |
void |
setDate(java.lang.String name,
long date)
This is used as a convenience method for setting a header that needs to be parsed into a HTTP-date string. |
void |
setMajor(int major)
This can be used to specify the major version. |
void |
setMinor(int minor)
This can be used to specify the minor version. |
void |
setText(java.lang.String text)
This is used to set the text of the HTTP status line. |
java.lang.String |
toString()
This constructs the HTTP message header according to the format of RFC 2616. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Response resp
Constructor Detail |
---|
public FilterResponse(Response resp)
FilterResponse
allows the original
Response
object to be wrapped so that adjustments
to the behavior of a Response
object handed to a
specialized ProtocolHandler
can be done simply.
resp
- the Response
object being wrappedMethod Detail |
---|
public int getCode()
getCode
in interface StatusLine
public void setCode(int code)
setCode
in interface StatusLine
code
- the new status code for the HTTP responsepublic java.lang.String getText()
getText
in interface StatusLine
public void setText(java.lang.String text)
setText
in interface StatusLine
text
- the descriptive text message of the statuspublic int getMajor()
getMajor
in interface StatusLine
public void setMajor(int major)
setMajor
in interface StatusLine
major
- this is the major number desiredpublic int getMinor()
getMinor
in interface StatusLine
public void setMinor(int minor)
setMinor
in interface StatusLine
minor
- this is the minor number desiredpublic int headerCount()
headerCount
represents
the number of individual HTTP message headers that this has.
headerCount
in interface GenericHeader
public int indexOf(java.lang.String name)
indexOf
in interface GenericHeader
name
- name of the HTTP message header being searched for
public int indexOf(java.lang.String name, int from)
indexOf
in interface GenericHeader
name
- name of the HTTP message header being searched forfrom
- the index from which the search will start
public void add(java.lang.String name, java.lang.String value)
indexOf
in combination with the get methods.
add
in interface GenericHeader
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havepublic void set(java.lang.String name, java.lang.String value)
indexOf
in combination with the get methods.
This will perform a removeAll
using the issued
header name before the header value is set.
set
in interface GenericHeader
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havepublic void add(java.lang.String name, int value)
indexOf
in combination with the get methods.
add
in interface GenericHeader
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havepublic void set(java.lang.String name, int value)
indexOf
in combination with the get methods.
This will perform a removeAll
using the issued
header name before the header value is set.
set
in interface GenericHeader
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will havepublic void addDate(java.lang.String name, long date)
addDate
in interface GenericHeader
name
- the name of the HTTP message header to be addeddate
- the value the HTTP message header will have when
parsed into RFC 1123 formatpublic void setDate(java.lang.String name, long date)
removeAll
using the issued
header name before the header value is set.
setDate
in interface GenericHeader
name
- the name of the HTTP message header to be addeddate
- the value the HTTP message header will have when
parsed into RFC 1123 formatpublic void remove(int off)
indexOf
method previous to this. If the
index specified is not valid then an
IndexOutOfBoundsException
may be thrown.
remove
in interface GenericHeader
off
- index of the HTTP message header to be removedpublic void removeAll(java.lang.String name)
removeAll
in interface GenericHeader
name
- name of the message headers to be removedpublic java.lang.String getValue(int off)
getValue
in interface GenericHeader
off
- the offset of the HTTP message header value
public java.lang.String getName(int off)
getValue(int)
method so that the contents of the
HTTP message header can be fully examined.
getName
in interface GenericHeader
off
- the offset of the HTTP message header name value
public java.lang.String[] getValues(java.lang.String name)
indexOf
methods.
This will return an empty array if there are no headers of
the specified name within this list.
getValues
in interface GenericHeader
name
- the name of the headers that are to be retrieved
public long getDate(int off)
getDate
in interface GenericHeader
off
- the offset of the date HTTP message header value
public java.lang.String getValue(java.lang.String name)
indexOf
methods. This returns null if theres
not a HTTP message header.
getValue
in interface GenericHeader
name
- the HTTP message header to get the value from
public long getDate(java.lang.String name)
indexOf
methods. This returns -1 if theres not a
HTTP message header.
getDate
in interface GenericHeader
name
- the HTTP message header to get the value from
public void setContentLength(int length)
This removes any previous Content-Length headers from the message
header. This will then set the appropriate Content-Length header with
the correct length. If a the Connection method is set with the close
token then the semantics of the connection are such that the server
will close it once the OutputStream.close
is used.
setContentLength
in interface Response
length
- this is the length of the HTTP message bodypublic Attributes getAttributes()
Response
. The attributes contains certain
properties about the Response
. For example if
this response goes over a secure line then there may be any
arbitrary attributes.
getAttributes
in interface Response
Response
objectpublic java.lang.Object getAttribute(java.lang.String name)
Attributes
in order to retrieve the attribute directly from that object.
The attributes contain data specific to the response.
getAttribute
in interface Response
name
- this is the name of the attribute to acquire
public java.net.InetAddress getInetAddress()
Response
goes to. The Attributes
shares this information. This method is used to that objects
can determine, based on the retrieved I.P address, what type
of output is suitable. Statistics such as location can be
determined based on the DNS address obtained.
getInetAddress
in interface Response
public java.io.OutputStream getOutputStream() throws java.io.IOException
Response
. The
semantics of this OutputStream
will be determined
by the HTTP version of the client, and whether or not the content
length has been set, through the setContentLength
method. If the length of the output is not known then the output
is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
The OutputStream
issued must be thread safe so that
it can be used in a concurrent environment.
getOutputStream
in interface Response
OutputStream
with the specified semantics
java.io.IOException
- this is thrown if there was an I/O errorpublic java.io.OutputStream getOutputStream(int size) throws java.io.IOException
Response
. The
semantics of this OutputStream
will be determined
by the HTTP version of the client, and whether or not the content
length has been set, through the setContentLength
method. If the length of the output is not known then the output
is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
The OutputStream
issued must be thread safe so that
it can be used in a concurrent environment.
This will ensure that there is buffering done so that the output
can be reset using the reset
method. This will
enable the specified number of bytes to be written without
committing the response. This specified size is the minimum size
that the response buffer must be.
getOutputStream
in interface Response
size
- the minimum size that the response buffer must be
OutputStream
with the specified semantics
java.io.IOException
- this is thrown if there was an I/O errorpublic java.io.PrintStream getPrintStream() throws java.io.IOException
print
methods provided by
the PrintStream
. This will basically wrap the
getOutputStream
with a buffer size of zero.
The retrieved PrintStream
uses the charset used to
describe the content, with the Content-Type header. This will
check the charset parameter of the contents MIME type. So if
the Content-Type was text/plain; charset=UTF-8
the
resulting PrintStream
would encode the written data
using the UTF-8 encoding scheme. Care must be taken to ensure
that bytes written to the stream are correctly encoded.
Implementations of the Response
must guarantee
that this can be invoked repeatedly without effecting any issued
OutputStream
or PrintStream
object.
getPrintStream
in interface Response
PrintStream
that provides convenience
methods to the Response
for writing content
java.io.IOException
- this is thrown if there was an I/O errorpublic java.io.PrintStream getPrintStream(int size) throws java.io.IOException
print
methods provided by
the PrintStream
. This will basically wrap the
getOutputStream
with a specified buffer size.
The retrieved PrintStream
uses the charset used to
describe the content, with the Content-Type header. This will
check the charset parameter of the contents MIME type. So if
the Content-Type was text/plain; charset=UTF-8
the
resulting PrintStream
would encode the written data
using the UTF-8 encoding scheme. Care must be taken to ensure
that bytes written to the stream are correctly encoded.
Implementations of the Response
must guarantee
that this can be invoked repeatedly without effecting any issued
OutputStream
or PrintStream
object.
getPrintStream
in interface Response
size
- the minimum size that the response buffer must be
PrintStream
that provides convenience
methods to the Response
for writing content
java.io.IOException
- this is thrown if there was an I/O errorpublic void commit() throws java.io.IOException
Response
. Any further attempts to give headers
to the Response
will be futile as only the headers
that were given at the time of the first commit will be used
in the message header.
This also performs some final checks on the headers submitted. This is done to determine the optimal performance of the output. If no specific Connection header has been specified this will set the connection so that HTTP/1.0 closes by default.
commit
in interface Response
java.io.IOException
- thrown if there was a problem writingpublic boolean isCommitted()
Response
has been committed. This is true if the Response
was committed, either due to an explicit invocation of the
commit
method or due to the writing of content. If
the Response
has committed the reset
method will not work in resetting content already written.
isCommitted
in interface Response
Response
has been committedpublic void reset()
reset
method is used to reset the output
from an issued OutputStream
. This will not work
is the isCommitted
returns true. If the streams
byte buffer overflows the response will commit and the
reset
will fail.
reset
in interface Response
public boolean contains(java.lang.String name)
contains
in interface GenericHeader
name
- the HTTP message header to get the value from
public boolean contains(java.lang.String name, java.lang.String value)
contains
in interface GenericHeader
name
- the HTTP message header to get the value fromvalue
- this value to find within the HTTP value
public void clear()
headerCount
is zero after this method is
invoked, this is a convenience method.
clear
in interface GenericHeader
public java.lang.String toString()
String
that
contains each header formatted according to the HTTP/1.1
header format. The header will contain the status line
followed by each header and ended with the CRLF.
toString
in interface Response
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |