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:
RequestHeaderFields,ResponseHeaderFields
public abstract class AbstractHeaderFields<C extends Cookie,T extends HeaderFields<C,T>>
extends AbstractHttpFields<T>
implements HeaderFields<C,T>
Abstract implementation of the
HeaderFields type.- See Also:
-
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
ConstructorsConstructorDescriptionInstantiates a new abstract Header-Fields.AbstractHeaderFields(Map<String, List<String>> aHttpFields) Instantiates a new abstract Header-Fields. -
Method Summary
Modifier and TypeMethodDescriptionAdds an individual server-side cookie to be sent to the client to thisResponseHeaderFieldsinstance.Adds an individual server-side cookie to be sent to the client to thisResponseHeaderFieldsinstance.voidAdds 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.entrySet()Retrieves an array of cookies sent by the client stored in thisRequestHeaderFieldsinstance.protected abstract StringThe Header-Field name for theCookieelements.protected static booleanisCommaSeparatedHeaderField(String aHeaderName) Tests the given HTTP Header-Field name whether it holds a comma separated value.keySet()voidprotected 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
copyHttpFieldsMethods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, forEach, getOrDefault, isEmpty, merge, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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, withUserAgentMethods inherited from interface org.refcodes.web.HttpFields
addAll, addTo, addTo, addTo, addTo, addTo, getFirst, getFirst, put, put, put, put, toField, toField, withAddTo, withAddTo, withAddTo, withAddTo, withAddTo, withAddTo, withPut, withPut, withPut, withPut, withPut, withPutMethods 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
-
Constructor Details
-
AbstractHeaderFields
public AbstractHeaderFields()Instantiates a new abstract Header-Fields. -
AbstractHeaderFields
Instantiates a new abstract Header-Fields.- Parameters:
aHttpFields- the http fields
-
-
Method Details
-
get
-
keySet
-
entrySet
-
put
-
addTo
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
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
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
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
-
isCommaSeparatedHeaderField
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
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
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
Creates a plainCookiewith the given name and value. -
createCookie
- Parameters:
aHttpCookie- The text of the Header-Field for the cookie to be created.- Returns:
- The
Cookiewith the given cookie properties.
-