Package org.refcodes.net
Class AbstractHeaderFields<C extends Cookie,T extends HeaderFields<C,T>>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<java.lang.String,java.util.List<java.lang.String>>
-
- org.refcodes.net.AbstractHttpFields<T>
-
- org.refcodes.net.AbstractHeaderFields<C,T>
-
- Type Parameters:
C
- TheCookie
type to be used by sub-classes.T
- The type of the sub-class, required for the builder methods such asHeaderFields.withHost(String)
.
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.String,java.util.List<java.lang.String>>
,BasicAuthCredentialsAccessor
,BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<T>
,BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator
,BasicAuthCredentialsAccessor.BasicAuthCredentialsProperty
,BearerAuthCredentialsAccessor
,BearerAuthCredentialsAccessor.BearerAuthCredentialsBuilder<T>
,BearerAuthCredentialsAccessor.BearerAuthCredentialsMutator
,BearerAuthCredentialsAccessor.BearerAuthCredentialsProperty
,HeaderFields<C,T>
,HttpFields<T>
- Direct Known Subclasses:
RequestHeaderFieldsImpl
,ResponseHeaderFieldsImpl
public abstract class AbstractHeaderFields<C extends Cookie,T extends HeaderFields<C,T>> extends AbstractHttpFields<T> implements HeaderFields<C,T>
Abstract implementation of theHeaderFields
type.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,V extends java.lang.Object>
-
Nested classes/interfaces inherited from interface org.refcodes.net.BasicAuthCredentialsAccessor
BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<B extends BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<B>>, BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator, BasicAuthCredentialsAccessor.BasicAuthCredentialsProperty
-
Nested classes/interfaces inherited from interface org.refcodes.net.BearerAuthCredentialsAccessor
BearerAuthCredentialsAccessor.BearerAuthCredentialsBuilder<B extends BearerAuthCredentialsAccessor.BearerAuthCredentialsBuilder<B>>, BearerAuthCredentialsAccessor.BearerAuthCredentialsMutator, BearerAuthCredentialsAccessor.BearerAuthCredentialsProperty
-
-
Field Summary
-
Fields inherited from interface org.refcodes.net.HeaderFields
BASIC_REALM
-
-
Constructor Summary
Constructors Constructor Description AbstractHeaderFields()
Instantiates a new abstract Header-Fields.AbstractHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> aHttpFields)
Instantiates a new abstract Header-Fields.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description C
addCookie(C aCookie)
Adds an individual server-side cookie to be sent to the client to thisResponseHeaderFields
instance.C
addCookie(java.lang.String aCookieName, java.lang.String aValue)
Adds an individual server-side cookie to be sent to the client to thisResponseHeaderFields
instance.void
addTo(java.lang.String aHeaderField, java.lang.String aValue)
Adds a value to the list of values associated with the given Header-Field (key),.protected abstract C
createCookie(java.lang.String aHttpCookie)
Creates aCookie
from the given HTTP cookieString
as retrieved from the according Header-Field.protected abstract C
createCookie(java.lang.String aCookieName, java.lang.String aValue)
Creates a plainCookie
with the given name and value.java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>>
entrySet()
java.util.List<java.lang.String>
get(java.lang.Object aKey)
java.util.List<C>
getAllCookies()
Retrieves an array of cookies sent by the client stored in thisRequestHeaderFields
instance.protected abstract java.lang.String
getCookieFieldName()
The Header-Field name for theCookie
elements.protected static boolean
isCommaSeparatedHeaderField(java.lang.String aHeaderName)
Tests the given HTTP Header-Field name whether it holds a comma separated value.java.util.Set<java.lang.String>
keySet()
java.util.List<java.lang.String>
put(java.lang.String aKey, java.util.List<java.lang.String> aValue)
void
putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> aMap)
protected java.lang.String
toHeaderField(java.lang.Object aHeaderField)
Normalizes the case of the provided Header-Field to conform to theHeaderField.getName()
format if possible.protected static void
toHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> aFromFields, HeaderFields<?,?> aToFields)
Copies the provided "from" fields into the provided "to" fields.-
Methods inherited from class org.refcodes.net.AbstractHttpFields
copyHttpFields
-
Methods inherited from interface org.refcodes.net.BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator
putBasicAuthCredentials
-
Methods inherited from interface org.refcodes.net.BearerAuthCredentialsAccessor.BearerAuthCredentialsMutator
putBearerAuthCredentials
-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, forEach, getOrDefault, isEmpty, merge, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from interface org.refcodes.net.HeaderFields
addCookie, addTo, addTo, addTo, get, getAcceptCharsets, getAcceptEncodings, getAcceptTypes, getAllowMethods, getAuthenticate, getBasicAuth, getBasicAuthCredentials, getBearerAuthCredentials, getContentEncoding, getContentType, getCookies, getFirst, getFirstCookie, getHost, getRequestId, getSessionId, getUnknownAcceptTypes, getUnknownContentTypes, getUserAgent, put, put, put, putAcceptCharsets, putAcceptCharsets, putAcceptEncodings, putAcceptEncodings, putAcceptTypes, putAcceptTypes, putAllowMethods, putAllowMethods, putAuthenticate, putBasicAuthCredentials, putBasicAuthRequired, putBearerAuthCredentials, putContentEncoding, putContentType, putContentType, putHost, putRequestId, putSessionId, putUserAgent, remove, removeAcceptCharsets, removeAcceptEncodings, removeAcceptTypes, removeAllowMethods, removeAuthenticate, removeBasicAuthCredentials, removeBasicAuthenticate, removeBearerAuthCredentials, removeContentEncoding, removeContentType, removeHost, removeRequestId, removeSessionId, removeUserAgent, toBasicAuthRealm, toHeaderFields, toHttpCookies, withAcceptCharsets, withAcceptCharsets, withAcceptEncodings, withAcceptEncodings, withAcceptTypes, withAcceptTypes, withAddCookie, withAddCookie, withAddTo, withAddTo, withAddTo, withAllowMethods, withAllowMethods, withAuthenticate, withBasicAuthCredentials, withBasicAuthCredentials, withBasicAuthRequired, withBearerAuthCredentials, withBearerAuthCredentials, withContentEncoding, withContentType, withContentType, withHost, withPut, withPut, withPut, withRequestId, withSessionId, withUserAgent
-
Methods inherited from interface org.refcodes.net.HttpFields
addTo, addTo, addTo, addTo, addTo, getFirst, getFirst, put, put, put, put, toField, toField, withAddTo, withAddTo, withAddTo, withAddTo, withAddTo, withAddTo, withPut, withPut, withPut, withPut, withPut, withPut
-
-
-
-
Constructor Detail
-
AbstractHeaderFields
public AbstractHeaderFields()
Instantiates a new abstract Header-Fields.
-
AbstractHeaderFields
public AbstractHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> aHttpFields)
Instantiates a new abstract Header-Fields.- Parameters:
aHttpFields
- the http fields
-
-
Method Detail
-
get
public java.util.List<java.lang.String> get(java.lang.Object aKey)
-
keySet
public java.util.Set<java.lang.String> keySet()
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> entrySet()
-
put
public java.util.List<java.lang.String> put(java.lang.String aKey, java.util.List<java.lang.String> aValue)
-
addTo
public void addTo(java.lang.String aHeaderField, java.lang.String aValue)
Adds a value to the list of values associated with the given Header-Field (key),.- Specified by:
addTo
in interfaceHttpFields<C extends Cookie>
- Parameters:
aHeaderField
- The Header-Field (key) of which's list of values a value is to be added.aValue
- The value to be added to the list of values associated to the given Header-Field (key).
-
addCookie
public C addCookie(C aCookie)
Adds an individual server-side cookie to be sent to the client to thisResponseHeaderFields
instance. The server-side cookies are retrieved from theHeaderField.SET_COOKIE
Header-Field. WITH THE METHODHeaderFields.getAllCookies()
andHeaderFields.getCookies(String)
as well asHeaderFields.getFirstCookie(String)
ONLY THE COOKIES SENT BY THE CLIENT CAN BE RETRIEVED (E.G. COOKIES RESIDING IN THE HEADER FIELDHeaderField.COOKIE
). COOKIES SET VIAHeaderFields.addCookie(String, String)
ORHeaderFields.withAddCookie(String, String)
CANNOT BE RETRIEVED, AS THE COOKIES BEING SET SERVER-SIDE ARE PUT IN THEHeaderField.SET_COOKIE
Header-Field.- Specified by:
addCookie
in interfaceHeaderFields<C extends Cookie,T extends HeaderFields<C,T>>
- Parameters:
aCookie
- The cookie to be added.- Returns:
- The resulting cookie builder being added which can be modified
affecting(!) this
ResponseHeaderFields
instance!
-
getAllCookies
public java.util.List<C> getAllCookies()
Retrieves an array of cookies sent by the client stored in thisRequestHeaderFields
instance. If no cookie has been found, then an empty array is returned. The client-side cookies are retrieved from theHeaderField.COOKIE
Header-Field. WITH THE METHODHeaderFields.getAllCookies()
andHeaderFields.getCookies(String)
as well asHeaderFields.getFirstCookie(String)
ONLY THE COOKIES SENT BY THE CLIENT CAN BE RETRIEVED (E.G. COOKIES RESIDING IN THE HEADER FIELDHeaderField.COOKIE
). COOKIES SET VIAHeaderFields.addCookie(String, String)
ORHeaderFields.withAddCookie(String, String)
CANNOT BE RETRIEVED, AS THE COOKIES BEING SET SERVER-SIDE ARE PUT IN THEHeaderField.SET_COOKIE
Header-Field. According to the Netscape cookie_spec (https://curl.haxx.se/rfc/cookie_spec.html) the entire NAME=VALUE string of a cookie is a sequence of characters excluding semi-colon, comma and white space.- Specified by:
getAllCookies
in interfaceHeaderFields<C extends Cookie,T extends HeaderFields<C,T>>
- Returns:
- An array containing the cookies (key/value) stored in this
RequestHeaderFields
instance.
-
addCookie
public C addCookie(java.lang.String aCookieName, java.lang.String aValue)
Adds an individual server-side cookie to be sent to the client to thisResponseHeaderFields
instance. The server-side cookies are retrieved from theHeaderField.SET_COOKIE
Header-Field. WITH THE METHODHeaderFields.getAllCookies()
andHeaderFields.getCookies(String)
as well asHeaderFields.getFirstCookie(String)
ONLY THE COOKIES SENT BY THE CLIENT CAN BE RETRIEVED (E.G. COOKIES RESIDING IN THE HEADER FIELDHeaderField.COOKIE
). COOKIES SET VIAHeaderFields.addCookie(String, String)
ORHeaderFields.withAddCookie(String, String)
CANNOT BE RETRIEVED, AS THE COOKIES BEING SET SERVER-SIDE ARE PUT IN THEHeaderField.SET_COOKIE
Header-Field.- Specified by:
addCookie
in interfaceHeaderFields<C extends Cookie,T extends HeaderFields<C,T>>
- Parameters:
aCookieName
- The name for the cookie to be added.aValue
- The value of the cookie to be added.- Returns:
- The resulting cookie builder being added which can be modified
affecting(!) this
ResponseHeaderFields
instance!
-
putAll
public void putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> aMap)
-
isCommaSeparatedHeaderField
protected static boolean isCommaSeparatedHeaderField(java.lang.String aHeaderName)
Tests the given HTTP Header-Field name whether it holds a comma separated value. You may overwrite this method and add your own implementation or extend this method by overwriting it and calling it in you overwritten method.- Parameters:
aHeaderName
- The name of the header to be tested.- Returns:
- True if the value being held by the given Header-Field name is a comma separated list.
-
toHeaderFields
protected static void toHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> aFromFields, HeaderFields<?,?> aToFields)
Copies the provided "from" fields into the provided "to" fields. Omits empty or null values.- Parameters:
aFromFields
- The fields from which to copy.aToFields
- The fields to which to copy.
-
toHeaderField
protected java.lang.String toHeaderField(java.lang.Object aHeaderField)
Normalizes the case of the provided Header-Field to conform to theHeaderField.getName()
format if possible. Else the unmodified Header-Field is returned.- Parameters:
aHeaderField
- The field to normalize.- Returns:
- The Header-Field, in case of normalization the normalized one.
-
getCookieFieldName
protected abstract java.lang.String getCookieFieldName()
The Header-Field name for theCookie
elements. The Header-Field name differs from the context, e.g. when setting aCookie
server-side or when retrieving aCookie
client-side.- Returns:
- The Header-Field where the
Cookie
elements are stored.
-
createCookie
protected abstract C createCookie(java.lang.String aCookieName, java.lang.String aValue)
Creates a plainCookie
with the given name and value.
-
createCookie
protected abstract C createCookie(java.lang.String aHttpCookie)
Creates aCookie
from the given HTTP cookieString
as retrieved from the according Header-Field.- Parameters:
aHttpCookie
- The text of the Header-Field for the cookie to be created.- Returns:
- The
Cookie
with the given cookie properties.
-
-