sk.baka.ambient.commons
Class ServerHttpException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by sk.baka.ambient.commons.ServerHttpException
All Implemented Interfaces:
Serializable

public final class ServerHttpException
extends Exception

The server-side HTTP exception.

Author:
Martin Vysny
See Also:
Serialized Form

Field Summary
 int errorCode
          The error code.
 
Constructor Summary
ServerHttpException(int errorCode)
          Creates new exception.
ServerHttpException(int errorCode, String message)
          Creates new exception.
ServerHttpException(int errorCode, Throwable cause)
          Creates new exception.
 
Method Summary
 String getResponseLine(byte httpVersion)
          Returns the response line, for example "HTTP/1.1 501 Not Implemented".
static String getResponseLine(byte httpVersion, int errorCode)
          Returns the response line, for example "HTTP/1.1 501 Not Implemented".
static String getStatus(int errorCode)
          Returns status name for given error code.
static void writeResponse(byte httpVersion, int errorCode, String message, OutputStream out)
          Returns the entire response, for example "HTTP/1.1 501 Not Implemented\r\nPUT Not implemented\r\n\r\n".
 void writeResponse(byte httpVersion, OutputStream out)
          Returns the response line, for example "HTTP/1.1 501 Not Implemented\r\nPUT Not implemented\r\n\r\n".
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

errorCode

public final int errorCode
The error code.

Constructor Detail

ServerHttpException

public ServerHttpException(int errorCode)
Creates new exception.

Parameters:
errorCode - the error code.

ServerHttpException

public ServerHttpException(int errorCode,
                           String message)
Creates new exception.

Parameters:
errorCode - the error code.
message - optional additional error info.

ServerHttpException

public ServerHttpException(int errorCode,
                           Throwable cause)
Creates new exception.

Parameters:
errorCode - the error code.
cause - the cause.
Method Detail

getStatus

public static String getStatus(int errorCode)
Returns status name for given error code.

Parameters:
errorCode - the error code. See error codes list for details.
Returns:
the status name.

writeResponse

public void writeResponse(byte httpVersion,
                          OutputStream out)
                   throws IOException
Returns the response line, for example "HTTP/1.1 501 Not Implemented\r\nPUT Not implemented\r\n\r\n".

Parameters:
httpVersion - the http version, 0 or 1.
out - write the response here.
Throws:
IOException - if i/o error occurs.

getResponseLine

public String getResponseLine(byte httpVersion)
Returns the response line, for example "HTTP/1.1 501 Not Implemented".

Parameters:
httpVersion - the http version, 0 or 1.
Returns:
the response line.

getResponseLine

public static String getResponseLine(byte httpVersion,
                                     int errorCode)
Returns the response line, for example "HTTP/1.1 501 Not Implemented".

Parameters:
httpVersion - the http version, 0 or 1.
errorCode - the HTTP error code.
Returns:
the response line.

writeResponse

public static void writeResponse(byte httpVersion,
                                 int errorCode,
                                 String message,
                                 OutputStream out)
                          throws IOException
Returns the entire response, for example "HTTP/1.1 501 Not Implemented\r\nPUT Not implemented\r\n\r\n".

Parameters:
httpVersion - the http version, 0 or 1.
errorCode - the HTTP error code.
message - optional additional error info.
out - write the result here.
Throws:
IOException - if i/o error occurs.


Copyright © 2007-2008. All Rights Reserved.