ccs.http
Class HException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.io.IOException
              extended by ccs.http.HException
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
RedirectException

public class HException
extends java.io.IOException

An Exception related to the HTTP protocol, which will be returned to the client via HTTP's response mechanism. Not all HTTP responses constitute error conditions; it may be found convenient to use the exception handling mechanism to handle some types of these non-error returns as well, and this is permissible. HException is also used to wrap other exceptions, as an aide to displaying them.

See Also:
Serialized Form

Constructor Summary
HException(int code)
          Create an HException with the specified code and no extra information.
HException(int code, java.lang.String msg)
          Create an HException with the specified code and the specified extra information.
HException(java.lang.Throwable th)
          Create a suitable HException to wrap the specified Throwable.
 
Method Summary
 SwappingBuffer defaultBody(java.lang.String method, java.lang.String uri)
          Builds a default HTML message body which describes this exception.
 int getCode()
          The HTTP response code responding to this exception.
 java.lang.String getCodeString()
          The human-friendly version of this response code.
 java.lang.String getLocalizedMessage()
          The annotated, I18N'ed, message.
 void send(java.io.OutputStream os, java.lang.String authCookie, SwappingBuffer body, java.lang.String method)
          send this HException back to the client, as a raw HTTP response.
protected  void sendln(java.io.OutputStream os, java.lang.String s)
          Send a string as a line of ASCII text.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HException

public HException(int code)
Create an HException with the specified code and no extra information.

Parameters:
code - The HTTP response code (see RFC2616 and good luck too you).

HException

public HException(java.lang.Throwable th)
Create a suitable HException to wrap the specified Throwable. This allows the server to report pretty much anything thrown at it by whatever logic it's fronting for. It translates the most common types into suitable 4xx codes. Error maps to 500 (server broken) while most of the rest become 502 (invalid reply from upstream). Use getCause to retrieve the throwable.


HException

public HException(int code,
                  java.lang.String msg)
Create an HException with the specified code and the specified extra information.

Parameters:
code - The HTTP response code (see RFC2616 and good luck too you).
msg - Anything else you want to say. This should usually be a short-form message code: before display, it will be washed through the I18N machinery in ccs.utils.MsgHelper.
Method Detail

getCode

public int getCode()
The HTTP response code responding to this exception.

Returns:
The code

getCodeString

public java.lang.String getCodeString()
The human-friendly version of this response code.


getLocalizedMessage

public java.lang.String getLocalizedMessage()
The annotated, I18N'ed, message. This takes into account a number of factors, including whether this HException is wrapping another exception. This is suitable for display purposes directly; getMessage will usually contain a short error code, if anything. The return is never null.

Overrides:
getLocalizedMessage in class java.lang.Throwable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Throwable

defaultBody

public SwappingBuffer defaultBody(java.lang.String method,
                                  java.lang.String uri)
                           throws java.io.IOException
Builds a default HTML message body which describes this exception. This is functional but plain, and serves as a fallback if more advanced "pretty-print" mechanisms are not available.

Parameters:
method - The HTTP method in force at the time.
uri - The URI being requested.
Throws:
java.io.IOException

sendln

protected void sendln(java.io.OutputStream os,
                      java.lang.String s)
               throws java.io.IOException
Send a string as a line of ASCII text.

Parameters:
os - The stream to send the string to.
s - The string to send.
Throws:
java.io.IOException

send

public void send(java.io.OutputStream os,
                 java.lang.String authCookie,
                 SwappingBuffer body,
                 java.lang.String method)
          throws java.io.IOException
send this HException back to the client, as a raw HTTP response. Legacy, for HTTPAdaptor only; that's about to get junked, and when that happens, so will this.

Parameters:
os - The stream to send on.
authCookie - An authentication cookie, to be returned by the browser with subsequent requests. Ommitted if null.
body - An HTML body describing this exception. Use defaultBody() if nothing better is handy.
method - The HTTP method requested.
Throws:
java.io.IOException