dfischer.femtowebserver.httpd
Class HttpResponse

java.lang.Object
  |
  +--dfischer.femtowebserver.httpd.HttpResponse

public class HttpResponse
extends java.lang.Object

Sets the Weblet HTTP response data (server response).

Use the methods print() and println() to transmit ASCII-content like HTML data to the agent (browser). For all other type of content, especially for binary data, you must use the method setContent(). Take into consideration that if you use setContent(), you must also set the right MIME type of your content data with the method setContentType().

More information about the HTTP protocol is available at http://www.w3.org

See Also:
HttpdWebletInterface, HttpdProperties

Field Summary
static java.lang.String HTTP_DEFAULT_CONTENT_TYPE
          The default content type for the Weblet response is "TEXT/HTML".
static int HTTP_DEFAULT_STATUS_CODE
          The default HTTP status code for a Weblet is 200.
static java.lang.String HTTP_DEFAULT_STATUS_TEXT
          The default HTTP status text for a Weblet is "OK".
static java.lang.String HTTP_VERSION
          The Femto Web Server supports only the HTTP protocol version 1.0 .
 
Method Summary
 void print(java.lang.String text)
          Appends (text) content to HTTP response.
 void println()
          Appends a <CR><NL> to the HTTP response.
 void println(java.lang.String text)
          Appends text content to the HTTP response and adds a <CR><NL>.
 void setAdditionalHeaderField(java.lang.String headerFieldName, java.lang.String headerFieldValue)
          Allows to set additional fields inside the HTTP response header.
 void setContent(byte[] content)
          Sets the content data of the HTTP response.
 void setContentType(java.lang.String mimeContentType)
          Sets the MIME content type of the content data.
 void setError(int httpStatus, java.lang.String httpStatusText)
          Sets the HTTP status code and the HTTP status text, and appends a small HTML error message as content.
 void setStatus(int httpStatus, java.lang.String httpStatusText)
          Sets the HTTP status code and the HTTP status text.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_VERSION

public static final java.lang.String HTTP_VERSION
The Femto Web Server supports only the HTTP protocol version 1.0 .
This means that the network connection will be closed after processing a request.

HTTP_DEFAULT_STATUS_CODE

public static final int HTTP_DEFAULT_STATUS_CODE
The default HTTP status code for a Weblet is 200.
This means that the server response is valid.
See Also:
setStatus(int, java.lang.String), setError(int, java.lang.String)

HTTP_DEFAULT_STATUS_TEXT

public static final java.lang.String HTTP_DEFAULT_STATUS_TEXT
The default HTTP status text for a Weblet is "OK".
See Also:
setStatus(int, java.lang.String), setError(int, java.lang.String)

HTTP_DEFAULT_CONTENT_TYPE

public static final java.lang.String HTTP_DEFAULT_CONTENT_TYPE
The default content type for the Weblet response is "TEXT/HTML".
See Also:
setContentType(java.lang.String)
Method Detail

setStatus

public void setStatus(int httpStatus,
                      java.lang.String httpStatusText)
Sets the HTTP status code and the HTTP status text. Use this method only if you don't want to transfer a "200 OK" to the agent (browser).
Parameters:
httpStatus - HTTP status code
httpStatusText - HTTP status text, or set this value to null, if you don't want to transfer a status text
See Also:
setError(int, java.lang.String)

setError

public void setError(int httpStatus,
                     java.lang.String httpStatusText)
Sets the HTTP status code and the HTTP status text, and appends a small HTML error message as content. Use this method only if you don't want to transfer a "200 OK" to the agent (browser).

Important Hint: all content data that you have set by print(), println() or setContent() and setContentType() will be overwritten.

Parameters:
httpStatus - HTTP status code
httpStatusText - HTTP status text (must not be null).
See Also:
setStatus(int, java.lang.String)

setAdditionalHeaderField

public void setAdditionalHeaderField(java.lang.String headerFieldName,
                                     java.lang.String headerFieldValue)
Allows to set additional fields inside the HTTP response header.
The following header field names are already set and can not be added:
Parameters:
headerFieldName - the header field name to add
headerFieldValue - the value of the header field

setContentType

public void setContentType(java.lang.String mimeContentType)
Sets the MIME content type of the content data. Use this method only if you have an other content type than "TEXT/HTML".
Parameters:
mimeContentType - the MIME content type of the content data
See Also:
setContent(byte[])

setContent

public void setContent(byte[] content)
Sets the content data of the HTTP response.

Important Hint: this method will overwrite all content data of the methods print() and println(). Consider also that you must set the appropriate content type if you use this method.

Parameters:
content - content data of the HTTP response
See Also:
setContentType(java.lang.String), print(java.lang.String), println()

print

public void print(java.lang.String text)
Appends (text) content to HTTP response. You may call this method as often as you want to append (more and more) text.

Important Hint: this method will clear all content that have already set with setContent().

Parameters:
text - text to append to the response content (must not be null)
See Also:
println(String), setContent(byte[])

println

public void println()
Appends a <CR><NL> to the HTTP response. You may call this method as often as you want to append (more and more) text.

Important Hint: this method will clear all content that have already set with setContent().

See Also:
print(java.lang.String), println(String), setContent(byte[])

println

public void println(java.lang.String text)
Appends text content to the HTTP response and adds a <CR><NL>. You may call this method as often as you want to append (more and more) text.

Important Hint: this method will clear all content that have already set with setContent().

Parameters:
text - text to append to the response content (must not be null)
See Also:
print(java.lang.String), println(), setContent(byte[])