All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sics.agentbase.http.HttpMessage

java.lang.Object
   |
   +----sics.agentbase.core.Message
           |
           +----sics.agentbase.http.HttpMessage

public class HttpMessage
extends Message
HttpMessage is a HTTP message that contain an HTTP request. There are methods for getting information about the request and methods for responding.


Variable Index

 o SC_ACCEPTED
 o SC_BAD_GATEWAY
 o SC_BAD_REQUEST
 o SC_CONFLICT
 o SC_CONTINUE
 o SC_CREATED
 o SC_FORBIDDEN
 o SC_GATEWAY_TIME_OUT
 o SC_GONE
 o SC_HTTP_VERSION_NOT_SUPPORTED
 o SC_INTERNAL_SERVER_ERROR
 o SC_LENGTH_REQUIRED
 o SC_METHOD_NOT_ALLOWED
 o SC_MOVED_PERMANENTLY
 o SC_MOVED_TEMPORARILY
 o SC_MULTIPLE_CHOICES
 o SC_NO_CONTENT
 o SC_NON_AUTHORITATIVE_INFORMATION
 o SC_NOT_ACCEPTABLE
 o SC_NOT_FOUND
 o SC_NOT_IMPLEMENTED
 o SC_NOT_MODIFIED
 o SC_OK
 o SC_PARTIAL_CONTENT
 o SC_PAYMENT_REQUIRED
 o SC_PRECONDITION_FAILED
 o SC_PROXY_AUTHENTICATION_REQUIRED
 o SC_REQUEST_ENTITY_TOO_LARGE
 o SC_REQUEST_TIME_OUT
 o SC_REQUEST_URI_TOO_LARGE
 o SC_RESET_CONTENT
 o SC_SEE_OTHER
 o SC_SERVICE_UNAVAILABLE
 o SC_SWITCHING_PROTOCOLS
 o SC_UNAUTHORIZED
 o SC_UNSUPPORTED_MEDIA_TYPE
 o SC_USE_PROXY

Constructor Index

 o HttpMessage(Socket)
Creates a HttpMessage by reading from a socket connection.

Method Index

 o addDateResponseHeader(String, long)
Adds a field to the response header with a given name and date-valued field.
 o addIntResponseHeader(String, int)
Adds a field to the response header with a given name and integer value.
 o addResponseHeader(String, String)
Adds a field to the header with a given name and value.
 o addResponseHeaderLine(String)
Adds a field line to the header with the given value.
 o close()
 o error(int)
 o finalize()
 o getAuthType()
Returns the authentication scheme of the request, or null if none.
 o getContent()
Returns an input stream for reading the body.
 o getContentLength()
Returns the size of the request entity data, or -1 if not known.
 o getContentType()
Returns the Internet Media Type of the request entity data, or null if not known.
 o getDateHeader(String)
Returns the value of a date header field, or -1 if not found.
 o getHeader(String)
Returns the value of a header field, or null if not known.
 o getHeaderNames()
Returns an enumeration of strings representing the header names for this request. Deprecated.
 o getIntHeader(String)
Returns the value of an integer header field, or -1 if not found.
 o getMethod()
Returns the method with which the request was made.
 o getOutputStream()
Returns an output stream for writing response data.
 o getPathInfo()
Returns optional extra path information following the agent path, but immediately preceding the query string.
 o getPostData()
Returns the parsed POST data (CGI) from the HTTP request.
 o getProtocol()
Returns the protocol and version of the request as a string of the form <protocol>/<major version>.<minor version>.
 o getQuery()
Returns the query part of the servlet URI, or null if none.
 o getQueryData()
Returns the parsed query data (CGI) from the HTTP request.
 o getRemoteHost()
Returns the fully qualified host name of the agent that sent the request.
 o getRemoteUser()
Returns the name of the user making this request, or null if not known.
 o getRequestURI()
Returns the request URI as a URL object.
 o send()
 o sendChallenge(String, String)
Sends a challenge to the client using the specified scheme and realm.
 o sendError(int)
Sends an error response to the client using the specified status code and descriptive message.
 o sendRedirect(String)
Sends a redirect response to the client using the specified redirect location URL.
 o sendRedirectDirectory()
Sends a redirect response to the client to add a slash using the request URL.
 o sendWithoutClose()
 o setDefaultObject(String)
Sets the default (or root) web object/agent (normally index.html).
 o setResponseContent(Object)
Sets the content.
 o setResponseContentLength(int)
Sets the content length.
 o setResponseContentType(String)
Sets the content type.
 o setResponseProtocol(String)
 o setStatus(int)
Sets the status code and a default message for this response.
 o setStatus(int, String)
Sets the status code and message for this response.
 o toString()

Variables

 o SC_CONTINUE
 public static final int SC_CONTINUE
 o SC_SWITCHING_PROTOCOLS
 public static final int SC_SWITCHING_PROTOCOLS
 o SC_OK
 public static final int SC_OK
 o SC_CREATED
 public static final int SC_CREATED
 o SC_ACCEPTED
 public static final int SC_ACCEPTED
 o SC_NON_AUTHORITATIVE_INFORMATION
 public static final int SC_NON_AUTHORITATIVE_INFORMATION
 o SC_NO_CONTENT
 public static final int SC_NO_CONTENT
 o SC_RESET_CONTENT
 public static final int SC_RESET_CONTENT
 o SC_PARTIAL_CONTENT
 public static final int SC_PARTIAL_CONTENT
 o SC_MULTIPLE_CHOICES
 public static final int SC_MULTIPLE_CHOICES
 o SC_MOVED_PERMANENTLY
 public static final int SC_MOVED_PERMANENTLY
 o SC_MOVED_TEMPORARILY
 public static final int SC_MOVED_TEMPORARILY
 o SC_SEE_OTHER
 public static final int SC_SEE_OTHER
 o SC_NOT_MODIFIED
 public static final int SC_NOT_MODIFIED
 o SC_USE_PROXY
 public static final int SC_USE_PROXY
 o SC_BAD_REQUEST
 public static final int SC_BAD_REQUEST
 o SC_UNAUTHORIZED
 public static final int SC_UNAUTHORIZED
 o SC_PAYMENT_REQUIRED
 public static final int SC_PAYMENT_REQUIRED
 o SC_FORBIDDEN
 public static final int SC_FORBIDDEN
 o SC_NOT_FOUND
 public static final int SC_NOT_FOUND
 o SC_METHOD_NOT_ALLOWED
 public static final int SC_METHOD_NOT_ALLOWED
 o SC_NOT_ACCEPTABLE
 public static final int SC_NOT_ACCEPTABLE
 o SC_PROXY_AUTHENTICATION_REQUIRED
 public static final int SC_PROXY_AUTHENTICATION_REQUIRED
 o SC_REQUEST_TIME_OUT
 public static final int SC_REQUEST_TIME_OUT
 o SC_CONFLICT
 public static final int SC_CONFLICT
 o SC_GONE
 public static final int SC_GONE
 o SC_LENGTH_REQUIRED
 public static final int SC_LENGTH_REQUIRED
 o SC_PRECONDITION_FAILED
 public static final int SC_PRECONDITION_FAILED
 o SC_REQUEST_ENTITY_TOO_LARGE
 public static final int SC_REQUEST_ENTITY_TOO_LARGE
 o SC_REQUEST_URI_TOO_LARGE
 public static final int SC_REQUEST_URI_TOO_LARGE
 o SC_UNSUPPORTED_MEDIA_TYPE
 public static final int SC_UNSUPPORTED_MEDIA_TYPE
 o SC_INTERNAL_SERVER_ERROR
 public static final int SC_INTERNAL_SERVER_ERROR
 o SC_NOT_IMPLEMENTED
 public static final int SC_NOT_IMPLEMENTED
 o SC_BAD_GATEWAY
 public static final int SC_BAD_GATEWAY
 o SC_SERVICE_UNAVAILABLE
 public static final int SC_SERVICE_UNAVAILABLE
 o SC_GATEWAY_TIME_OUT
 public static final int SC_GATEWAY_TIME_OUT
 o SC_HTTP_VERSION_NOT_SUPPORTED
 public static final int SC_HTTP_VERSION_NOT_SUPPORTED

Constructors

 o HttpMessage
 public HttpMessage(Socket connection) throws IOException
Creates a HttpMessage by reading from a socket connection.

Parameters:
connection - an open socket connection with a HTTP request to parse.

Methods

 o setDefaultObject
 public static void setDefaultObject(String object)
Sets the default (or root) web object/agent (normally index.html).

Parameters:
agent - the default web page object/agent.
 o getMethod
 public String getMethod()
Returns the method with which the request was made. The returned value can be "GET", "HEAD", "POST", or an extension method.

 o getContentLength
 public int getContentLength()
Returns the size of the request entity data, or -1 if not known.

 o getContentType
 public String getContentType()
Returns the Internet Media Type of the request entity data, or null if not known.

 o getProtocol
 public String getProtocol()
Returns the protocol and version of the request as a string of the form <protocol>/<major version>.<minor version>.

 o getRemoteHost
 public String getRemoteHost()
Returns the fully qualified host name of the agent that sent the request.

 o getContent
 public Object getContent()
Returns an input stream for reading the body.

 o getRequestURI
 public String getRequestURI()
Returns the request URI as a URL object.

 o getPathInfo
 public String getPathInfo()
Returns optional extra path information following the agent path, but immediately preceding the query string. Returns null if not specified.

 o getQuery
 public String getQuery()
Returns the query part of the servlet URI, or null if none.

 o getQueryData
 public Hashtable getQueryData()
Returns the parsed query data (CGI) from the HTTP request.

Returns:
the CGI parsed query data as a Hashtable or null if no query data exists.
 o getPostData
 public Hashtable getPostData()
Returns the parsed POST data (CGI) from the HTTP request.

Returns:
the parsed POST data (CGI) as a Hashtable or null if no POST data exists.
 o getRemoteUser
 public String getRemoteUser()
Returns the name of the user making this request, or null if not known. The user name is set with HTTP authentication. Whether the user name will continue to be sent with each subsequent communication is browser-dependent.

 o getAuthType
 public String getAuthType()
Returns the authentication scheme of the request, or null if none.

 o getHeader
 public String getHeader(String name)
Returns the value of a header field, or null if not known. The case of the header field name is ignored.

Parameters:
name - the case-insensitive header field name
 o getIntHeader
 public int getIntHeader(String name)
Returns the value of an integer header field, or -1 if not found. The case of the header field name is ignored.

Parameters:
name - the case-insensitive header field name
 o getDateHeader
 public long getDateHeader(String name)
Returns the value of a date header field, or -1 if not found. The case of the header field name is ignored.

Parameters:
name - the case-insensitive header field name
 o getHeaderNames
 public Enumeration getHeaderNames()
Note: getHeaderNames() is deprecated. Do not use!

Returns an enumeration of strings representing the header names for this request.

 o getOutputStream
 public OutputStream getOutputStream() throws IOException
Returns an output stream for writing response data.

Throws: IOException
if an I/O exception occures.
 o setStatus
 public void setStatus(int sc,
                       String sm)
Sets the status code and message for this response.

Parameters:
sc - the status code
sm - the status message
 o setStatus
 public void setStatus(int sc)
Sets the status code and a default message for this response.

Parameters:
sc - the status code
 o setResponseProtocol
 public static final void setResponseProtocol(String protocol)
 o setResponseContentLength
 public void setResponseContentLength(int len)
Sets the content length.

Parameters:
len - the content length
 o setResponseContentType
 public void setResponseContentType(String type)
Sets the content type.

Parameters:
type - the content's MIME type
 o setResponseContent
 public void setResponseContent(Object content)
Sets the content.

Parameters:
content - the content
 o addResponseHeader
 public void addResponseHeader(String name,
                               String value)
Adds a field to the header with a given name and value.

Parameters:
name - the header field name
value - the header field value
 o addResponseHeaderLine
 public void addResponseHeaderLine(String header)
Adds a field line to the header with the given value.

Parameters:
header - the header
 o addIntResponseHeader
 public void addIntResponseHeader(String name,
                                  int value)
Adds a field to the response header with a given name and integer value. If the field had already been set, the new value overwrites the previous one.

Parameters:
name - the header field name
value - the header field integer value
 o addDateResponseHeader
 public void addDateResponseHeader(String name,
                                   long date)
Adds a field to the response header with a given name and date-valued field. The date is specified in terms of milliseconds since the epoch. If the date field had already been set, the new value overwrites the previous one.

Parameters:
name - the header field name
value - the header field date value
 o send
 public void send() throws IOException
Overrides:
send in class Message
 o sendWithoutClose
 public void sendWithoutClose() throws IOException
 o sendError
 public void sendError(int sc) throws IOException
Sends an error response to the client using the specified status code and descriptive message.

Parameters:
sc - the status code
msg - the detail message
Throws: IOException
if an I/O error occurs.
 o sendChallenge
 public void sendChallenge(String authScheme,
                           String realm) throws IOException
Sends a challenge to the client using the specified scheme and realm.

Parameters:
authScheme - the authorization scheme.
realm - the realm value.
Throws: IOException
if an I/O error occurs.
 o sendRedirect
 public void sendRedirect(String location) throws IOException
Sends a redirect response to the client using the specified redirect location URL. The URL must be absolute (e.g., http://hostname/path/file.html). Relative URLs are not permitted here.

Parameters:
location - the redirect location URL
Throws: IOException
if an I/O error occurs.
 o sendRedirectDirectory
 public void sendRedirectDirectory() throws IOException
Sends a redirect response to the client to add a slash using the request URL. E.g. the request http://hostname/path will result in a new request http://hostname/path/.

Parameters:
location - the redirect location URL
Throws: IOException
if an I/O error has occurs.
 o error
 public void error(int code)
Overrides:
error in class Message
 o finalize
 protected void finalize() throws IOException, Throwable
Overrides:
finalize in class Object
 o close
 public void close() throws IOException
 o toString
 public String toString()
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index