|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.http.serve.Component
public abstract class Component
This is an abstract Resource
that handles the basic
HTTP status reports. For example messages like '404 Not Found'
are represented using this abstraction. This Resource
can be subclassed to give a Resource
the ability to
handle all generic status reports for 3xx, 4xx and 5xx defined by
RFC 2616.
This uses a various Report
objects to generate error
and status messages using the Format
supplied. This
also enables exceptions that propagate from the service objects
to be classified and for descriptions of those exceptions to be
represented as Report
objects that can be be used to
generate a formatted message that can be presented to the client.
Field Summary | |
---|---|
protected Context |
context
The Context that this resource is in. |
Constructor Summary | |
---|---|
protected |
Component()
Constructor that creates a Component without
any Context object. |
protected |
Component(Context context)
Constructor for the Component is given the
Context so that it can generate status reports. |
Method Summary | |
---|---|
void |
handle(Request req,
Response resp)
This handle is provided so that if any errors
occur when processing a HTTP transaction a '500 Server Error'
message will be sent to the client. |
void |
handle(Request req,
Response resp,
int code)
This is used to generate the status report from a status code. |
void |
handle(Request req,
Response resp,
Report report)
This is used to generate a formatted message using a report to describe the change in status. |
protected abstract void |
process(Request req,
Response resp)
This method is used to handle the HTTP transaction by subclasses of the Component . |
protected void |
process(Request req,
Response resp,
int code)
This method is used to handle the HTTP status reports so that if any Exception occurs the handle
method can capture and deal with the exception. |
protected void |
process(Request req,
Response resp,
Report report)
This method is used to handle the HTTP status reports so that if any Exception occurs the handle
method can capture and deal with the exception. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Context context
Context
that this resource is in.
Constructor Detail |
---|
protected Component()
Component
without
any Context
object. This is used so that if the
resource is a ProtocolHandler
or some other form
of resource that does not require a context then this will
allow that resource to inherit the functionality of this. The
typical implementation however will not use this constructor.
If this is used and a context is not set then there will be
an exception in handle(Request,Response,int)
.
protected Component(Context context)
Component
is given the
Context
so that it can generate status reports.
Every implementation of the Component
needs
to be constructed with a Context
to ensure that
the generation of error and status messages is successful.
context
- the context that this resource is inMethod Detail |
---|
public void handle(Request req, Response resp)
handle
is provided so that if any errors
occur when processing a HTTP transaction a '500 Server Error'
message will be sent to the client. This is used to invoke
the process
method which subclasses should
implement to process the HTTP transaction. If the exception
is a SecurityException
'403 Forbidden' is used
and a FileNotFoundException
is '404 Not Found'.
Any Exception
thrown from the process
method will be captured and the Request
and
Response
are handled by the default error handler
method handle(Request,Response,int)
with the code
500 which indicates the HTTP/1.1 error message 'Server Error'
This does not throw ant Exception
however any
user should handle RuntimeException
's that may
be thrown from handle(Request,Response,int)
.
handle
in interface Resource
req
- the Request
object to be processedresp
- the Response
object to be processedpublic void handle(Request req, Response resp, int code)
This does not throw Exception
's but users should
be prepared to handle any RuntimeException
's that
could propagate from this. If the Response
has
been committed then this will return quietly. Typically there
will be an IOException
writing the content body if
the stream has been closed. This will not report such exceptions.
handle
in interface Resource
req
- the Request
object to be processedresp
- the Response
object to be processedcode
- this is the HTTP status code of the responsepublic void handle(Request req, Response resp, Report report)
Format
object to prepare a formatted message that can be presented to
the client. This message will describe the status using the
issued Report
obejct. If the status code given
does not have a valid entry then this will result in an status
message description of 'Unknown'.
This does not throw Exception
's but users should
be prepared to handle any RuntimeException
's that
could propagate from this. If the Response
has
been committed then this will return quietly. Typically there
will be an IOException
writing the content body if
the stream has been closed. This will not report such exceptions.
handle
in interface Resource
req
- the Request
object to be processedresp
- the Response
object to be processedreport
- this is used to describe the change in statusprotected void process(Request req, Response resp, int code) throws java.lang.Exception
Exception
occurs the handle
method can capture and deal with the exception.
Subclasses should treat this as the handle
method
of the ProtocolHandler
. Exceptions that cannot be
recovered from, particularly RuntimeException
's
should be left propagate so the handle
method can
deal with the Exception
appropriately.
req
- the Request
object to be processedresp
- the Response
object to be processedcode
- this is the HTTP status code of the response
java.lang.Exception
- this can throw an error for anythingprotected void process(Request req, Response resp, Report report) throws java.lang.Exception
Exception
occurs the handle
method can capture and deal with the exception.
Subclasses should treat this as the handle
method
of the ProtocolHandler
. Exceptions that cannot be
recovered from, particularly RuntimeException
's
should be left propagate so the handle
method can
deal with the Exception
appropriately.
req
- the Request
object to be processedresp
- the Response
object to be processedreport
- this is used to describe the change in status
java.lang.Exception
- this can throw an error for anythingprotected abstract void process(Request req, Response resp) throws java.lang.Exception
Component
. This is used so that if there
are any Exception
's thrown while processing the
HTTP transaction they can be captured and the HTTP status line
will convey the status to the client.
Subclasses should treat this as the handle
method
of the ProtocolHandler
. Exceptions that cannot be
recovered from, particularly RuntimeException
's
should be left propagate so the handle
method can
prepare an appropriate response.
req
- the Request
object to be processedresp
- the Response
object to be processed
java.lang.Exception
- this can throw an error for anything
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |