Package de.aristaflow.adept2.ui.htmlgui
Class HTMLContext.HTTPReply
java.lang.Object
de.aristaflow.adept2.ui.htmlgui.HTMLContext.HTTPReply
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing interface:
- HTMLContext
The
The keys in the provided maps are the names of the parameters or the form elements in the corresponding HTML set in the corresponding
HTTPReply wraps the data sent as GET or POST to the web server. It supports
simple strings, attachments (that is binary data and/or uploaded files) as well as lists of
both types. Attachments may only be provided by multipart form-content while normal POST (or
GET) may contain URL-encoded form data. The keys in the provided maps are the names of the parameters or the form elements in the corresponding HTML set in the corresponding
HTMLContext. If a parameter (or form
element name) occurs several times and therefore has several values, they will be provided via
the appropriate list-methods of this HTTPReply. Simple parameters occurring only
once are provided via the simple maps.
HTTPReply also allows for creating URLs which respect the URL used by the caller.
A caller may need to use different URLs than known by the server, e. g. in case there are
proxies between client and server. In this case the URLs created by the server (the users of
this HTTPReply) need to be adapted to the actual URL (protocol, host and port).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String,List<HTMLContext.Attachment>> Field forgetAttachmentLists().protected final Map<String,HTMLContext.Attachment> Field forgetAttachments().protected final Cleanup<IOException>The clean-up for closing the attachments as post-mortem action of thisHTTPReply.The function allowing access to the request headers which are used to adapt URLs.protected final LoggerThe logger for problems when adapting URLs.Field forgetParameterLists().Field forgetParameters(). -
Constructor Summary
ConstructorsConstructorDescriptionHTTPReply(Map<String, String> parameters, Map<String, HTMLContext.Attachment> attachments, Map<String, List<String>> parameterLists, Map<String, List<HTMLContext.Attachment>> attachmentLists, HTMLContext.Attachment body, Function<String, String> headers, Logger logger) Creates a newHTTPReplywith the designated attributes. -
Method Summary
Modifier and TypeMethodDescriptionadaptUrlToRequest(URL url) Adapts the designated URL by setting protocol, host and port accordingly to data from the headers of the corresponding HTTP request.voidclose()Gets the parameters (mapping from parameter name to several attachments) that are binary data and/or files and occur several times in the HTTP-reply.Gets the parameters (mapping from parameter name to attachment) that are binary data and/or files and occur only once in the HTTP-reply.getBody()Gets the HTTP request's body, in case there was a body sent by the browser.Gets the parameters (mapping from parameter name to several values) that occur several times in the HTTP-reply and therefore have several values.Gets the parameters (mapping from parameter name to value) that occur only once in the HTTP-reply and therefore have only one value.
-
Field Details
-
attachmentLists
Field forgetAttachmentLists(). -
attachments
Field forgetAttachments(). -
parameterLists
Field forgetParameterLists(). -
parameters
Field forgetParameters(). -
headers
The function allowing access to the request headers which are used to adapt URLs. -
logger
The logger for problems when adapting URLs. -
cleanup
The clean-up for closing the attachments as post-mortem action of thisHTTPReply.
-
-
Constructor Details
-
HTTPReply
public HTTPReply(Map<String, String> parameters, Map<String, HTMLContext.Attachment> attachments, Map<String, List<String>> parameterLists, Map<String, List<HTMLContext.Attachment>> attachmentLists, HTMLContext.Attachment body, Function<String, String> headers, Logger logger) Creates a newHTTPReplywith the designated attributes. All maps are stored unmodifiable including the lists in the map. Do not modify the maps or lists after calling this constructor. This may cause unwanted side-effects since neither the maps nor the lists are copied.- Parameters:
parameters- The map containing all simple parameters having only one value. This must not benull.attachments- The map containing all attachment parameters (uploaded files) having only one value/attachment. This must not benull!
The HTMLContext.Attachments will be coupled to thisHTTPReply, so do not close them; clone them if required longer than thisHTTPReply.parameterLists- The map containing all simple parameters having several value. This must not benull.attachmentLists- The map containing all attachment parameters (uploaded files) having several values/attachments. This must not benull!
The HTMLContext.Attachments will be coupled to thisHTTPReply, so do not close them; clone them if required longer than thisHTTPReply.body- The request's body, if any. The HTMLContext.Attachment will be coupled to thisHTTPReply, so do not close it; clone it if required longer than thisHTTPReply.headers- The function allowing access to the request headers which are used to adapt URLs. This may benull.logger- The logger for problems when adapting URLs. This may benullbut should not be.
-
-
Method Details
-
getParameters
Gets the parameters (mapping from parameter name to value) that occur only once in the HTTP-reply and therefore have only one value.- Returns:
- An unmodifiable map providing the parameters (mapping from parameter name to value) having only one value in the HTTP-reply sent by the client.
-
getAttachments
Gets the parameters (mapping from parameter name to attachment) that are binary data and/or files and occur only once in the HTTP-reply.- Returns:
- An unmodifiable map providing the binary data/file parameters (mapping from parameter
name to attachment) having only one attachment in the HTTP-reply sent by the client.
The HTMLContext.Attachments will be coupled to thisHTTPReply, so do not close them; clone them if required longer than thisHTTPReply.
-
getParameterLists
Gets the parameters (mapping from parameter name to several values) that occur several times in the HTTP-reply and therefore have several values.- Returns:
- An unmodifiable map providing the parameters (mapping from parameter name to values) having several values in the HTTP-reply sent by the client.
-
getAttachmentLists
Gets the parameters (mapping from parameter name to several attachments) that are binary data and/or files and occur several times in the HTTP-reply.- Returns:
- An unmodifiable map providing the binary data/file parameters (mapping from parameter
name to attachments) having several attachments in the HTTP-reply sent by the client.
The HTMLContext.Attachments will be coupled to thisHTTPReply, so do not close them; clone them if required longer than thisHTTPReply.
-
getBody
Gets the HTTP request's body, in case there was a body sent by the browser. The file name is always null.- Returns:
- The request body or
nullif there was none. The HTMLContext.Attachment will be coupled to thisHTTPReply, so do not close it; clone it if required longer than thisHTTPReply.
-
adaptUrlToRequest
Adapts the designated URL by setting protocol, host and port accordingly to data from the headers of the corresponding HTTP request. This allows to change the known values to the ones provided by the HTTP request which may be routed through a proxy. That is, the URL working for the requestor may need to be different from the URL known by our service.
If there is no such header data, the designated URL will be returned unchanged.- Parameters:
url- The URL which may need to be adapted to a different protocol, host and/or port. This must not benull.- Returns:
- The URL with protocol, host and/or port changed to the values provided by the headers of the corresponding HTTP request.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-