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- TheCookietype 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.util.Map<C,T>,BasicAuthCredentialsAccessor,BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<C>,BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator,BasicAuthCredentialsAccessor.BasicAuthCredentialsProperty,BearerAuthCredentialsAccessor,BearerAuthCredentialsAccessor.BearerAuthCredentialsBuilder<C>,BearerAuthCredentialsAccessor.BearerAuthCredentialsMutator,BearerAuthCredentialsAccessor.BearerAuthCredentialsProperty,HeaderFields<C,T>,HttpFields<C>
- 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 theHeaderFieldstype.- 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 CaddCookie(C aCookie)Adds an individual server-side cookie to be sent to the client to thisResponseHeaderFieldsinstance.CaddCookie(java.lang.String aCookieName, java.lang.String aValue)Adds an individual server-side cookie to be sent to the client to thisResponseHeaderFieldsinstance.voidaddTo(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 CcreateCookie(java.lang.String aHttpCookie)Creates aCookiefrom the given HTTP cookieStringas retrieved from the according Header-Field.protected abstract CcreateCookie(java.lang.String aCookieName, java.lang.String aValue)Creates a plainCookiewith 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 thisRequestHeaderFieldsinstance.protected abstract java.lang.StringgetCookieFieldName()The Header-Field name for theCookieelements.protected static booleanisCommaSeparatedHeaderField(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)voidputAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> aMap)protected java.lang.StringtoHeaderField(java.lang.Object aHeaderField)Normalizes the case of the provided Header-Field to conform to theHeaderField.getName()format if possible.protected static voidtoHeaderFields(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, getAuthorization, getBasicAuth, getBasicAuthCredentials, getBearerAuthCredentials, getContentEncoding, getContentLength, getContentType, getCookies, getFirst, getFirstCookie, getHost, getRequestId, getSessionId, getUnknownAcceptTypes, getUnknownContentTypes, getUserAgent, put, put, put, putAcceptCharsets, putAcceptCharsets, putAcceptEncodings, putAcceptEncodings, putAcceptTypes, putAcceptTypes, putAllowMethods, putAllowMethods, putAuthenticate, putAuthorization, putAuthorization, putAuthorization, putBasicAuthCredentials, putBasicAuthRequired, putBearerAuthCredentials, putContentEncoding, putContentLength, putContentType, putContentType, putHost, putRequestId, putSessionId, putUserAgent, remove, removeAcceptCharsets, removeAcceptEncodings, removeAcceptTypes, removeAllowMethods, removeAuthenticate, removeAuthorization, removeBasicAuthCredentials, removeBasicAuthenticate, removeBearerAuthCredentials, removeContentEncoding, removeContentLength, removeContentType, removeHost, removeRequestId, removeSessionId, removeUserAgent, toBasicAuthRealm, toHeaderFields, toHttpCookies, withAcceptCharsets, withAcceptCharsets, withAcceptEncodings, withAcceptEncodings, withAcceptTypes, withAcceptTypes, withAddCookie, withAddCookie, withAddTo, withAddTo, withAddTo, withAllowMethods, withAllowMethods, withAuthenticate, withAuthorization, withAuthorization, withAuthorization, withBasicAuthCredentials, withBasicAuthCredentials, withBasicAuthRequired, withBearerAuthCredentials, withBearerAuthCredentials, withContentEncoding, withContentLength, 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
-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entry, equals, forEach, getOrDefault, hashCode, isEmpty, merge, of, of, of, of, of, of, of, of, of, of, of, ofEntries, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
-
-
-
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:
addToin 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 thisResponseHeaderFieldsinstance. The server-side cookies are retrieved from theHeaderField.SET_COOKIEHeader-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_COOKIEHeader-Field.- Specified by:
addCookiein 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
ResponseHeaderFieldsinstance!
-
getAllCookies
public java.util.List<C> getAllCookies()
Retrieves an array of cookies sent by the client stored in thisRequestHeaderFieldsinstance. If no cookie has been found, then an empty array is returned. The client-side cookies are retrieved from theHeaderField.COOKIEHeader-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_COOKIEHeader-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:
getAllCookiesin interfaceHeaderFields<C extends Cookie,T extends HeaderFields<C,T>>- Returns:
- An array containing the cookies (key/value) stored in this
RequestHeaderFieldsinstance.
-
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 thisResponseHeaderFieldsinstance. The server-side cookies are retrieved from theHeaderField.SET_COOKIEHeader-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_COOKIEHeader-Field.- Specified by:
addCookiein 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
ResponseHeaderFieldsinstance!
-
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 theCookieelements. The Header-Field name differs from the context, e.g. when setting aCookieserver-side or when retrieving aCookieclient-side.- Returns:
- The Header-Field where the
Cookieelements are stored.
-
createCookie
protected abstract C createCookie(java.lang.String aCookieName, java.lang.String aValue)
Creates a plainCookiewith the given name and value.
-
createCookie
protected abstract C createCookie(java.lang.String aHttpCookie)
Creates aCookiefrom the given HTTP cookieStringas retrieved from the according Header-Field.- Parameters:
aHttpCookie- The text of the Header-Field for the cookie to be created.- Returns:
- The
Cookiewith the given cookie properties.
-
-