Class HTMLContext.HTTPReply

  • All Implemented Interfaces:
    Closeable, AutoCloseable
    Enclosing interface:
    HTMLContext

    public static class HTMLContext.HTTPReply
    extends Object
    implements Closeable
    The 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).

    • 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)
        Creates a new HTTPReply 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 be null.
        attachments - The map containing all attachment parameters (uploaded files) having only one value/attachment. This must not be null!
        The HTMLContext.Attachments will be coupled to this HTTPReply, so do not close them; clone them if required longer than this HTTPReply.
        parameterLists - The map containing all simple parameters having several value. This must not be null.
        attachmentLists - The map containing all attachment parameters (uploaded files) having several values/attachments. This must not be null!
        The HTMLContext.Attachments will be coupled to this HTTPReply, so do not close them; clone them if required longer than this HTTPReply.
        body - The request's body, if any. The HTMLContext.Attachment will be coupled to this HTTPReply, so do not close it; clone it if required longer than this HTTPReply.
      • 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 new HTTPReply 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 be null.
        attachments - The map containing all attachment parameters (uploaded files) having only one value/attachment. This must not be null!
        The HTMLContext.Attachments will be coupled to this HTTPReply, so do not close them; clone them if required longer than this HTTPReply.
        parameterLists - The map containing all simple parameters having several value. This must not be null.
        attachmentLists - The map containing all attachment parameters (uploaded files) having several values/attachments. This must not be null!
        The HTMLContext.Attachments will be coupled to this HTTPReply, so do not close them; clone them if required longer than this HTTPReply.
        body - The request's body, if any. The HTMLContext.Attachment will be coupled to this HTTPReply, so do not close it; clone it if required longer than this HTTPReply.
        headers - The function allowing access to the request headers which are used to adapt URLs. This may be null.
        logger - The logger for problems when adapting URLs. This may be null 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 this HTTPReply, so do not close them; clone them if required longer than this HTTPReply.
      • 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 this HTTPReply, so do not close them; clone them if required longer than this HTTPReply.
      • 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 this HTTPReply, so do not close it; clone it if required longer than this HTTPReply.
      • 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 be null.
        Returns:
        The URL with protocol, host and/or port changed to the values provided by the headers of the corresponding HTTP request.