com.univocity.api.net
Class HttpMessage

java.lang.Object
  extended by com.univocity.api.net.HttpMessage
Direct Known Subclasses:
HttpRequest

public abstract class HttpMessage
extends Object

Basic details of a HTTP message (request or response)


Field Summary
protected  LinkedHashMap<String,String> cookies
           
protected  LinkedHashMap<String,List<String>> headers
           
protected  RequestMethod requestMethod
           
 
Constructor Summary
HttpMessage()
           
 
Method Summary
 Map<String,String> getCookies()
          Returns the cookies to be added to the Cookie HTTP header.
 String getCookieValue(String name)
          Returns the value associated with a given cookie name
 Map<String,String> getHeaders()
          Returns the headers and their corresponding values in this HTTP message.
 String getHeaderValue(String header)
          Returns the value(s) currently defined for a given header.
 List<String> getHeaderValues(String header)
          Returns the list of values currently defined for a given header.
 Map<String,List<String>> getMultiHeaders()
          Returns the headers and their corresponding values in this HTTP message.
 String getReferrer()
          Returns the current Referer request header that identifies the address of the web-page that linked to the resource being requested.
 RequestMethod getRequestMethod()
          Returns the RequestMethod to be used by this request.
 String getUserAgent()
          Returns the current User-Agent request header, which identifies the user agent originating the request.
 boolean hasCookie(String name)
          Verifies whether a cookie has been set
 boolean hasHeader(String name)
          Checks whether this HTTP message has a given header defined.
 boolean hasHeaderWithValue(String name, String value)
          Verifies whether a given header has a value
 boolean isKeepAliveEnabled()
          Returns a flag indicating whether the connection is meant to be reused for further requests (i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestMethod

protected RequestMethod requestMethod

headers

protected LinkedHashMap<String,List<String>> headers

cookies

protected LinkedHashMap<String,String> cookies
Constructor Detail

HttpMessage

public HttpMessage()
Method Detail

getHeaders

public final Map<String,String> getHeaders()
Returns the headers and their corresponding values in this HTTP message. If multiple values are associated with the same header, they will be be separated by comma. Use getMultiHeaders() to obtain the multiple values in a list.

Returns:
a map of headers and their values.

hasHeader

public final boolean hasHeader(String name)
Checks whether this HTTP message has a given header defined. The search is case insensitive.

Parameters:
name - the header name to look for
Returns:
true if the given header exists in this HTTP message, otherwise false

getMultiHeaders

public final Map<String,List<String>> getMultiHeaders()
Returns the headers and their corresponding values in this HTTP message. Multiple values can be associated with the same header, use getHeaders() to obtain them as a comma separated sequence

Returns:
a map of headers and their values.

getHeaderValue

public final String getHeaderValue(String header)
Returns the value(s) currently defined for a given header. If multiple values are associated with the header the resulting String will have them separated by a comma. Use getHeaderValues(String) to obtain the header values as a List

Parameters:
header - the header name whose value(s) will be returned.
Returns:
the value(s) associated with the given header, or null if the header is not defined

getHeaderValues

public final List<String> getHeaderValues(String header)
Returns the list of values currently defined for a given header. Use getHeaderValue(String) to obtain the header values as a comma delimited String

Parameters:
header - the header name whose value(s) will be returned.
Returns:
the list of values associated with the given header, or null if the header is not defined

getCookies

public final Map<String,String> getCookies()
Returns the cookies to be added to the Cookie HTTP header.

Returns:
a map of cookie names and values.

getRequestMethod

public final RequestMethod getRequestMethod()
Returns the RequestMethod to be used by this request. The method type identifies an action to be performed on the identified (remote) resource. Defaults to RequestMethod.GET

Returns:
the HTTP method to use

isKeepAliveEnabled

public final boolean isKeepAliveEnabled()
Returns a flag indicating whether the connection is meant to be reused for further requests (i.e. persistent) or not, in which case the Connection request header is set to close. If the Connection header is not set, it is assumed that the connection is persistent, and this method will return true.

Returns:
flag indicating whether or not the HTTP connection is persistent (i.e kept alive).

getUserAgent

public final String getUserAgent()
Returns the current User-Agent request header, which identifies the user agent originating the request.

Returns:
the User-Agent header

getReferrer

public final String getReferrer()
Returns the current Referer request header that identifies the address of the web-page that linked to the resource being requested.

Returns:
the Referer header

getCookieValue

public final String getCookieValue(String name)
Returns the value associated with a given cookie name

Parameters:
name - the name that identifies a cookie
Returns:
the value associated with the cookie, it any.

hasCookie

public final boolean hasCookie(String name)
Verifies whether a cookie has been set

Parameters:
name - the name that identifies a cookie
Returns:
true if a cookie with the given name has been defined, otherwise false

hasHeaderWithValue

public final boolean hasHeaderWithValue(String name,
                                        String value)
Verifies whether a given header has a value

Parameters:
name - the header name whose values will be verified
value - the value to find among the possible multiple values associated with the given header
Returns:
true if the given value is associated with the given header name, otherwise false


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.