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.
-
SC_ACCEPTED
-
-
SC_BAD_GATEWAY
-
-
SC_BAD_REQUEST
-
-
SC_CONFLICT
-
-
SC_CONTINUE
-
-
SC_CREATED
-
-
SC_FORBIDDEN
-
-
SC_GATEWAY_TIME_OUT
-
-
SC_GONE
-
-
SC_HTTP_VERSION_NOT_SUPPORTED
-
-
SC_INTERNAL_SERVER_ERROR
-
-
SC_LENGTH_REQUIRED
-
-
SC_METHOD_NOT_ALLOWED
-
-
SC_MOVED_PERMANENTLY
-
-
SC_MOVED_TEMPORARILY
-
-
SC_MULTIPLE_CHOICES
-
-
SC_NO_CONTENT
-
-
SC_NON_AUTHORITATIVE_INFORMATION
-
-
SC_NOT_ACCEPTABLE
-
-
SC_NOT_FOUND
-
-
SC_NOT_IMPLEMENTED
-
-
SC_NOT_MODIFIED
-
-
SC_OK
-
-
SC_PARTIAL_CONTENT
-
-
SC_PAYMENT_REQUIRED
-
-
SC_PRECONDITION_FAILED
-
-
SC_PROXY_AUTHENTICATION_REQUIRED
-
-
SC_REQUEST_ENTITY_TOO_LARGE
-
-
SC_REQUEST_TIME_OUT
-
-
SC_REQUEST_URI_TOO_LARGE
-
-
SC_RESET_CONTENT
-
-
SC_SEE_OTHER
-
-
SC_SERVICE_UNAVAILABLE
-
-
SC_SWITCHING_PROTOCOLS
-
-
SC_UNAUTHORIZED
-
-
SC_UNSUPPORTED_MEDIA_TYPE
-
-
SC_USE_PROXY
-
-
HttpMessage(Socket)
- Creates a HttpMessage by reading from a socket connection.
-
addDateResponseHeader(String, long)
-
Adds a field to the response header with a given name and
date-valued field.
-
addIntResponseHeader(String, int)
-
Adds a field to the response header with a given name and
integer value.
-
addResponseHeader(String, String)
-
Adds a field to the header with a given name and
value.
-
addResponseHeaderLine(String)
-
Adds a field line to the header with the given
value.
-
close()
-
-
error(int)
-
-
finalize()
-
-
getAuthType()
- Returns the authentication scheme of the request, or null if none.
-
getContent()
- Returns an input stream for reading the body.
-
getContentLength()
- Returns the size of the request entity data, or -1 if not known.
-
getContentType()
- Returns the Internet Media Type of the request entity data, or
null if not known.
-
getDateHeader(String)
- Returns the value of a date header field, or -1 if not found.
-
getHeader(String)
- Returns the value of a header field, or null if not known.
-
getHeaderNames()
- Returns an enumeration of strings representing the header names
for this request.
Deprecated.
-
getIntHeader(String)
- Returns the value of an integer header field, or -1 if not found.
-
getMethod()
- Returns the method with which the request was made.
-
getOutputStream()
- Returns an output stream for writing response data.
-
getPathInfo()
- Returns optional extra path information following the agent
path, but immediately preceding the query string.
-
getPostData()
- Returns the parsed POST data (CGI) from the HTTP request.
-
getProtocol()
- Returns the protocol and version of the request as a string of
the form
<protocol>/<major version>.<minor
version>.
-
getQuery()
- Returns the query part of the servlet URI, or
null if none.
-
getQueryData()
- Returns the parsed query data (CGI) from the HTTP request.
-
getRemoteHost()
- Returns the fully qualified host name of the agent that sent the
request.
-
getRemoteUser()
- Returns the name of the user making this request, or null if not
known.
-
getRequestURI()
- Returns the request URI as a URL object.
-
send()
-
-
sendChallenge(String, String)
- Sends a challenge to the client using the specified scheme and realm.
-
sendError(int)
- Sends an error response to the client using the specified status
code and descriptive message.
-
sendRedirect(String)
- Sends a redirect response to the client using the specified
redirect location URL.
-
sendRedirectDirectory()
- Sends a redirect response to the client to add a slash using the
request URL.
-
sendWithoutClose()
-
-
setDefaultObject(String)
- Sets the default (or root) web object/agent (normally index.html).
-
setResponseContent(Object)
- Sets the content.
-
setResponseContentLength(int)
- Sets the content length.
-
setResponseContentType(String)
- Sets the content type.
-
setResponseProtocol(String)
-
-
setStatus(int)
- Sets the status code and a default message for this response.
-
setStatus(int, String)
- Sets the status code and message for this response.
-
toString()
-
SC_CONTINUE
public static final int SC_CONTINUE
SC_SWITCHING_PROTOCOLS
public static final int SC_SWITCHING_PROTOCOLS
SC_OK
public static final int SC_OK
SC_CREATED
public static final int SC_CREATED
SC_ACCEPTED
public static final int SC_ACCEPTED
SC_NON_AUTHORITATIVE_INFORMATION
public static final int SC_NON_AUTHORITATIVE_INFORMATION
SC_NO_CONTENT
public static final int SC_NO_CONTENT
SC_RESET_CONTENT
public static final int SC_RESET_CONTENT
SC_PARTIAL_CONTENT
public static final int SC_PARTIAL_CONTENT
SC_MULTIPLE_CHOICES
public static final int SC_MULTIPLE_CHOICES
SC_MOVED_PERMANENTLY
public static final int SC_MOVED_PERMANENTLY
SC_MOVED_TEMPORARILY
public static final int SC_MOVED_TEMPORARILY
SC_SEE_OTHER
public static final int SC_SEE_OTHER
SC_NOT_MODIFIED
public static final int SC_NOT_MODIFIED
SC_USE_PROXY
public static final int SC_USE_PROXY
SC_BAD_REQUEST
public static final int SC_BAD_REQUEST
SC_UNAUTHORIZED
public static final int SC_UNAUTHORIZED
SC_PAYMENT_REQUIRED
public static final int SC_PAYMENT_REQUIRED
SC_FORBIDDEN
public static final int SC_FORBIDDEN
SC_NOT_FOUND
public static final int SC_NOT_FOUND
SC_METHOD_NOT_ALLOWED
public static final int SC_METHOD_NOT_ALLOWED
SC_NOT_ACCEPTABLE
public static final int SC_NOT_ACCEPTABLE
SC_PROXY_AUTHENTICATION_REQUIRED
public static final int SC_PROXY_AUTHENTICATION_REQUIRED
SC_REQUEST_TIME_OUT
public static final int SC_REQUEST_TIME_OUT
SC_CONFLICT
public static final int SC_CONFLICT
SC_GONE
public static final int SC_GONE
SC_LENGTH_REQUIRED
public static final int SC_LENGTH_REQUIRED
SC_PRECONDITION_FAILED
public static final int SC_PRECONDITION_FAILED
SC_REQUEST_ENTITY_TOO_LARGE
public static final int SC_REQUEST_ENTITY_TOO_LARGE
SC_REQUEST_URI_TOO_LARGE
public static final int SC_REQUEST_URI_TOO_LARGE
SC_UNSUPPORTED_MEDIA_TYPE
public static final int SC_UNSUPPORTED_MEDIA_TYPE
SC_INTERNAL_SERVER_ERROR
public static final int SC_INTERNAL_SERVER_ERROR
SC_NOT_IMPLEMENTED
public static final int SC_NOT_IMPLEMENTED
SC_BAD_GATEWAY
public static final int SC_BAD_GATEWAY
SC_SERVICE_UNAVAILABLE
public static final int SC_SERVICE_UNAVAILABLE
SC_GATEWAY_TIME_OUT
public static final int SC_GATEWAY_TIME_OUT
SC_HTTP_VERSION_NOT_SUPPORTED
public static final int SC_HTTP_VERSION_NOT_SUPPORTED
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.
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.
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.
getContentLength
public int getContentLength()
- Returns the size of the request entity data, or -1 if not known.
getContentType
public String getContentType()
- Returns the Internet Media Type of the request entity data, or
null if not known.
getProtocol
public String getProtocol()
- Returns the protocol and version of the request as a string of
the form
<protocol>/<major version>.<minor
version>.
getRemoteHost
public String getRemoteHost()
- Returns the fully qualified host name of the agent that sent the
request.
getContent
public Object getContent()
- Returns an input stream for reading the body.
getRequestURI
public String getRequestURI()
- Returns the request URI as a URL object.
getPathInfo
public String getPathInfo()
- Returns optional extra path information following the agent
path, but immediately preceding the query string. Returns null if
not specified.
getQuery
public String getQuery()
- Returns the query part of the servlet URI, or
null if none.
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.
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.
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.
getAuthType
public String getAuthType()
- Returns the authentication scheme of the request, or null if none.
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
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
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
getHeaderNames
public Enumeration getHeaderNames()
- Note: getHeaderNames() is deprecated.
Do not use!
- Returns an enumeration of strings representing the header names
for this request.
getOutputStream
public OutputStream getOutputStream() throws IOException
- Returns an output stream for writing response data.
- Throws: IOException
- if an I/O exception occures.
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
setStatus
public void setStatus(int sc)
- Sets the status code and a default message for this response.
- Parameters:
- sc - the status code
setResponseProtocol
public static final void setResponseProtocol(String protocol)
setResponseContentLength
public void setResponseContentLength(int len)
- Sets the content length.
- Parameters:
- len - the content length
setResponseContentType
public void setResponseContentType(String type)
- Sets the content type.
- Parameters:
- type - the content's MIME type
setResponseContent
public void setResponseContent(Object content)
- Sets the content.
- Parameters:
- content - the content
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
addResponseHeaderLine
public void addResponseHeaderLine(String header)
- Adds a field line to the header with the given
value.
- Parameters:
- header - the header
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
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
send
public void send() throws IOException
- Overrides:
- send in class Message
sendWithoutClose
public void sendWithoutClose() throws IOException
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.
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.
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.
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.
error
public void error(int code)
- Overrides:
- error in class Message
finalize
protected void finalize() throws IOException, Throwable
- Overrides:
- finalize in class Object
close
public void close() throws IOException
toString
public String toString()
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index