|
Femto Web Server V1.4-F | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.util.Dictionary
|
+--java.util.Hashtable
|
+--dfischer.femtowebserver.httpd.HttpResponse
Sets the Weblet HTTP response data (server response) and (optionally) allows a Filter to modify every HTTP 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
Programming Example I:
package mypackage;
import dfischer.femtowebserver.httpd.*;
public class TestWeblet implements HttpdWebletInterface
{
public void execute(HttpRequest req, HttpResponse res, HttpdProperties httpdProperties) throws Exception
{
res.println("<HTML>");
res.println("<BODY>");
res.println("This is a Test Weblet");
res.println("</BODY>");
res.println("</HTML>");
}
}
Programming Example II:
package mypackage;
import dfischer.femtowebserver.httpd.*;
public class RedirectTestWeblet implements HttpdWebletInterface
{
public void execute(HttpRequest req, HttpResponse res, HttpdProperties httpdProperties) throws Exception
{
res.addHeaderField("Location", "http://www.d-fischer.com");
res.setStatus(302, "Found");
}
}
HttpdWebletInterface,
HttpdProperties,
HttpdFilter,
HttpdSession, Serialized Form| Inner classes inherited from class java.util.Map |
java.util.Map.Entry |
| Field Summary | |
static java.lang.String |
HTTP_DEFAULT_CONTENT_TYPE
The default content type for the Weblet response is "TEXT/HTML" (without a content subtype). |
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 |
addHeaderField(java.lang.String headerFieldName,
java.lang.String headerFieldValue)
Allows to add additional HTTP header fields inside the HTTP response header. |
void |
clearContent()
Clears the content. |
void |
dropCookie(java.lang.String name,
java.lang.String startPath)
Allows to delete cookies, before they are sent. |
void |
dump()
Dumps the HTTP response header and the response content to the log output. |
byte[] |
getContent()
Returns the current content as byte[] array. |
java.lang.String |
getContentAsString()
Returns the current content as string. |
java.lang.String |
getContentSubtype()
Returns the current content subtype. |
java.lang.String |
getContentType()
Returns the current content type, without the the content subtype. |
java.lang.String |
getHeaderField(java.lang.String headerFieldName)
Returns the value of a HTTP header field name. |
java.lang.String[] |
getHeaderFieldNames()
Returns a String[] array of all HTTP header field names. |
HttpdSession |
getSession()
Returns the current http session (only if a session handler is active). |
int |
getStatus()
Returns the current HTTP status code. |
java.lang.String |
getStatusText()
Returns the current HTTP status text. |
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 |
removeHeaderField(java.lang.String headerFieldName)
Removes a HTTP header field. |
void |
setAdditionalHeaderField(java.lang.String headerFieldName,
java.lang.String headerFieldValue)
Deprecated. Replaced by addHeaderField() |
void |
setContent(byte[] content)
Sets the content data of the HTTP response. |
void |
setContentType(java.lang.String mimeContentType)
Sets the MIME content type and (optionally) the content subtype 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 |
setPermanentCookie(java.lang.String name,
java.lang.String value,
java.lang.String path,
int expiresInDays,
boolean secure)
Transfers a new permanent cookie to the agent (browser). |
void |
setSession(HttpdSession httpdSession)
Allows to set a HTTP session before the request will be processed by the Femto Web Server. |
void |
setStatus(int httpStatus,
java.lang.String httpStatusText)
Sets the HTTP status code and the HTTP status text. |
void |
setTransientCookie(java.lang.String name,
java.lang.String value,
java.lang.String path,
boolean secure)
Transfers a new transient (session-) cookie to the agent (browser). |
void |
updateHeaderField(java.lang.String headerFieldName,
java.lang.String headerFieldValue)
Allows to replace a HTTP header field value inside the HTTP response header. |
| Methods inherited from class java.util.Hashtable |
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, remove, size, toString, values |
| Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.String HTTP_VERSION
public static final int HTTP_DEFAULT_STATUS_CODE
setStatus(int, java.lang.String),
setError(int, java.lang.String)public static final java.lang.String HTTP_DEFAULT_STATUS_TEXT
setStatus(int, java.lang.String),
setError(int, java.lang.String)public static final java.lang.String HTTP_DEFAULT_CONTENT_TYPE
setContentType(java.lang.String)| Method Detail |
public void setSession(HttpdSession httpdSession)
httpdSession - the HTTP sessionHttpdFilter,
HttpSessionCookieHandlerpublic HttpdSession getSession()
HttpSessionCookieHandler
public void setStatus(int httpStatus,
java.lang.String httpStatusText)
httpStatus - HTTP status codehttpStatusText - HTTP status text, or set this value to null, if you don't want to transfer a status textsetError(int, java.lang.String)public int getStatus()
HttpdFilterpublic java.lang.String getStatusText()
HttpdFilter
public void setError(int httpStatus,
java.lang.String httpStatusText)
Important Hint: all content data that you have set by print(), println() or setContent() and setContentType() will be overwritten.
httpStatus - HTTP status codehttpStatusText - HTTP status text (must not be null).setStatus(int, java.lang.String)
public void setAdditionalHeaderField(java.lang.String headerFieldName,
java.lang.String headerFieldValue)
addHeaderField(java.lang.String, java.lang.String)
public void addHeaderField(java.lang.String headerFieldName,
java.lang.String headerFieldValue)
headerFieldName - the header field name to addheaderFieldValue - the value of the header fieldHttpdFilter
public void updateHeaderField(java.lang.String headerFieldName,
java.lang.String headerFieldValue)
headerFieldName - the header field name whose value should be modifiedheaderFieldValue - the new value of the header fieldaddHeaderField(java.lang.String, java.lang.String),
getHeaderField(java.lang.String),
HttpdFilterpublic java.lang.String getHeaderField(java.lang.String headerFieldName)
headerFieldName - the name of the HTTP header fieldgetContentType(),
getContent(),
getContentAsString(),
addHeaderField(java.lang.String, java.lang.String),
updateHeaderField(java.lang.String, java.lang.String),
HttpdFilterpublic java.lang.String[] getHeaderFieldNames()
getHeaderField(java.lang.String),
getContentType(),
getContent(),
getContentAsString(),
HttpdFilterpublic void removeHeaderField(java.lang.String headerFieldName)
headerFieldName - the name of the HTTP header field to remove. If the field name is not found
inside the HTTP response header, this method will also complete successful.HttpdFilter
public void setTransientCookie(java.lang.String name,
java.lang.String value,
java.lang.String path,
boolean secure)
name - the cookie namevalue - the cookie valuepath - the subset of URLs for which the cookie is valid. Set this value to "/" to transfer a transient cookie that is
valid for all URL paths.secure - this value must always set to false, because encrypted HTTPS/SSL connections are currently not supported.setPermanentCookie(java.lang.String, java.lang.String, java.lang.String, int, boolean)
public void setPermanentCookie(java.lang.String name,
java.lang.String value,
java.lang.String path,
int expiresInDays,
boolean secure)
name - the cookie namevalue - the cookie valuepath - the subset of URLs for which the cookie is valid. Set this value to "/" to transfer a permanent cookie that is
valid for all URL paths.expiresInDays - valid life time of that cookie in days (from now on).secure - this value must always set to false, because encrypted HTTPS/SSL connections are currently not supported.setTransientCookie(java.lang.String, java.lang.String, java.lang.String, boolean)
public void dropCookie(java.lang.String name,
java.lang.String startPath)
name - the name of the cookie(s) to delete - (only) if the startPath matches. If several cookies have te same name,
all of these cookies are deleted.startPath - start-string of the path. All cookies with the selected name - whose paths starts with this string - are deletetd.
Set this value to "/" (used as wildcard) to select all cookies with the same name.public void setContentType(java.lang.String mimeContentType)
mimeContentType - the MIME content type and (optionally) the content subtype of the content dataHTTP_DEFAULT_CONTENT_TYPE,
setContent(byte[])public java.lang.String getContentType()
HttpdFilter,
getContentSubtype()public java.lang.String getContentSubtype()
HttpdFilter,
getContentType()public void setContent(byte[] content)
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.
content - content data of the HTTP responsesetContentType(java.lang.String),
print(java.lang.String),
println()public void print(java.lang.String text)
Important Hint: this method will clear all content that have already set with setContent().
text - text to append to the response content (must not be null)println(String),
setContent(byte[])public void println()
Important Hint: this method will clear all content that have already set with setContent().
print(java.lang.String),
println(String),
setContent(byte[])public void println(java.lang.String text)
Important Hint: this method will clear all content that have already set with setContent().
text - text to append to the response content (must not be null)print(java.lang.String),
println(),
setContent(byte[])public byte[] getContent()
getContentAsString(),
HttpdFilterpublic java.lang.String getContentAsString()
getContent(),
HttpdFilterpublic void clearContent()
HttpdFilter
public void dump()
throws java.io.IOException
Httpd.setLogStream(java.io.PrintStream)
|
Femto Web Server V1.4-F | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||