Module org.refcodes.web
Package org.refcodes.web
Class AbstractHeaderFields<C extends Cookie,T extends HeaderFields<C,T>>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,List<String>>
-
- org.refcodes.web.AbstractHttpFields<T>
-
- org.refcodes.web.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:
Serializable,Cloneable,Map<String,List<String>>,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 theHeaderFieldstype.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
-
Fields inherited from interface org.refcodes.web.HeaderFields
BASIC_REALM
-
-
Constructor Summary
Constructors Constructor Description AbstractHeaderFields()Instantiates a new abstract Header-Fields.AbstractHeaderFields(Map<String,List<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(String aCookieName, String aValue)Adds an individual server-side cookie to be sent to the client to thisResponseHeaderFieldsinstance.voidaddTo(String aHeaderField, String aValue)Adds a value to the list of values associated with the given Header-Field (key).protected abstract CcreateCookie(String aHttpCookie)protected abstract CcreateCookie(String aCookieName, String aValue)Creates a plainCookiewith the given name and value.Set<Map.Entry<String,List<String>>>entrySet()List<String>get(Object aKey)List<C>getAllCookies()Retrieves an array of cookies sent by the client stored in thisRequestHeaderFieldsinstance.protected abstract StringgetCookieFieldName()The Header-Field name for theCookieelements.protected static booleanisCommaSeparatedHeaderField(String aHeaderName)Tests the given HTTP Header-Field name whether it holds a comma separated value.Set<String>keySet()List<String>put(String aKey, List<String> aValue)voidputAll(Map<? extends String,? extends List<String>> aMap)protected StringtoHeaderField(Object aHeaderField)Normalizes the case of the provided Header-Field to conform to theHeaderField.getName()format if possible.protected static voidtoHeaderFields(Map<String,List<String>> aFromFields, HeaderFields<?,?> aToFields)Copies the provided "from" fields into the provided "to" fields.-
Methods inherited from class org.refcodes.web.AbstractHttpFields
copyHttpFields
-
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 class java.util.AbstractMap
equals, hashCode, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.web.HeaderFields
addCookie, addTo, addTo, addTo, get, getAcceptCharsets, getAcceptEncodings, getAcceptLanguages, 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, putAcceptLanguages, putAcceptLanguages, putAcceptTypes, putAcceptTypes, putAllowMethods, putAllowMethods, putAuthenticate, putAuthorization, putAuthorization, putAuthorization, putBasicAuthCredentials, putBasicAuthCredentials, putBasicAuthRequired, putBearerAuthCredentials, putBearerAuthCredentials, putContentEncoding, putContentLength, putContentType, putContentType, putHost, putRequestId, putSessionId, putUserAgent, remove, removeAcceptCharsets, removeAcceptEncodings, removeAcceptLanguages, removeAcceptTypes, removeAllowMethods, removeAuthenticate, removeAuthorization, removeBasicAuthCredentials, removeBasicAuthenticate, removeBearerAuthCredentials, removeContentEncoding, removeContentLength, removeContentType, removeHost, removeRequestId, removeSessionId, removeUserAgent, toBasicAuthRealm, toHeaderFields, toHttpCookies, withAcceptCharsets, withAcceptCharsets, withAcceptEncodings, withAcceptEncodings, withAcceptLanguages, withAcceptLanguages, 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.web.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, equals, forEach, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
-
-
-
Method Detail
-
addTo
public void addTo(String aHeaderField, 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 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 FILE=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(String aCookieName, 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!
-
isCommaSeparatedHeaderField
protected static boolean isCommaSeparatedHeaderField(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(Map<String,List<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 String toHeaderField(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 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(String aCookieName, String aValue)
Creates a plainCookiewith the given name and value.
-
-