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
public static class HTMLContext.HTTPReply extends Object implements Closeable
TheHTTPReply
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 correspondingHTMLContext
. 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 thisHTTPReply
. 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 thisHTTPReply
) need to be adapted to the actual URL (protocol, host and port).
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,List<HTMLContext.Attachment>>
attachmentLists
Field forgetAttachmentLists()
.protected Map<String,HTMLContext.Attachment>
attachments
Field forgetAttachments()
.protected Cleanup<IOException>
cleanup
The clean-up for closing the attachments as post-mortem action of thisHTTPReply
.protected Function<String,String>
headers
The function allowing access to the request headers which are used to adapt URLs.protected Logger
logger
The logger for problems when adapting URLs.protected Map<String,List<String>>
parameterLists
Field forgetParameterLists()
.protected Map<String,String>
parameters
Field forgetParameters()
.
-
Constructor Summary
Constructors Constructor Description HTTPReply(Map<String,String> parameters, Map<String,HTMLContext.Attachment> attachments, Map<String,List<String>> parameterLists, Map<String,List<HTMLContext.Attachment>> attachmentLists, HTMLContext.Attachment body)
Deprecated.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 newHTTPReply
with the designated attributes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description URL
adaptUrlToRequest(URL url)
Adapts the designated URL by setting protocol, host and port accordingly to data from the headers of the corresponding HTTP request.void
close()
Map<String,List<HTMLContext.Attachment>>
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.Map<String,HTMLContext.Attachment>
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.HTMLContext.Attachment
getBody()
Gets the HTTP request's body, in case there was a body sent by the browser.Map<String,List<String>>
getParameterLists()
Gets the parameters (mapping from parameter name to several values) that occur several times in the HTTP-reply and therefore have several values.Map<String,String>
getParameters()
Gets the parameters (mapping from parameter name to value) that occur only once in the HTTP-reply and therefore have only one value.
-
-
-
Field Detail
-
attachmentLists
protected final Map<String,List<HTMLContext.Attachment>> attachmentLists
Field forgetAttachmentLists()
.
-
attachments
protected final Map<String,HTMLContext.Attachment> attachments
Field forgetAttachments()
.
-
parameterLists
protected final Map<String,List<String>> parameterLists
Field forgetParameterLists()
.
-
parameters
protected final Map<String,String> parameters
Field forgetParameters()
.
-
headers
protected final Function<String,String> headers
The function allowing access to the request headers which are used to adapt URLs.
-
logger
protected final Logger logger
The logger for problems when adapting URLs.
-
cleanup
protected final Cleanup<IOException> cleanup
The clean-up for closing the attachments as post-mortem action of thisHTTPReply
.
-
-
Constructor Detail
-
HTTPReply
@Deprecated 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)
Deprecated.Creates a newHTTPReply
with 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
.
-
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 newHTTPReply
with 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 benull
but should not be.
-
-
Method Detail
-
getParameters
public Map<String,String> 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
public Map<String,HTMLContext.Attachment> 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
public Map<String,List<String>> 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
public Map<String,List<HTMLContext.Attachment>> 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
public HTMLContext.Attachment 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
null
if there was none. The HTMLContext.Attachment will be coupled to thisHTTPReply
, so do not close it; clone it if required longer than thisHTTPReply
.
-
adaptUrlToRequest
public URL adaptUrlToRequest(URL url)
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
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-