Class ExpiryCheckHandler
- java.lang.Object
-
- org.swisspush.gateleen.queue.expiry.ExpiryCheckHandler
-
public final class ExpiryCheckHandler extends Object
The ExpiryCheckHandler allows you to check the expiry of a request. It also offers methods for setting default values for expiration and timestamps to the request header.- Author:
- https://github.com/ljucam [Mario Ljuca]
-
-
Field Summary
Fields Modifier and Type Field Description static StringEXPIRE_AFTER_HEADERstatic StringQUEUE_EXPIRE_AFTER_HEADERstatic StringSERVER_TIMESTAMP_HEADER
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.joda.time.DateTimegetExpirationTime(int expireAfter)Returns the expiration time, based on the current time (now) in addition with the expireAfter value.static Optional<String>getExpirationTimeAsString(int expireAfter)static IntegergetExpireAfter(io.vertx.core.MultiMap headers)Extracts the value of the "X-Expire-After" header.static Optional<Integer>getExpireAfterConcerningCaseOfCorruptHeaderAndInfinite(io.vertx.core.MultiMap headers)Delegates togetExpireValue(String)This is extended version ofgetExpireAfter(MultiMap)but also returning -1 for infinite.static IntegergetQueueExpireAfter(io.vertx.core.MultiMap headers)Extracts the value of the "x-queue-expire-after" header.static booleanisExpired(io.vertx.core.MultiMap headers, Long timestamp)Checks the expiration based on the given headers and a timstamp in milliseconds.static org.joda.time.DateTimeparseDateTime(String datetime)Parses the given string to a DateTime object.static StringprintDateTime(org.joda.time.DateTime datetime)Prints the given datetime as a string.static voidsetExpireAfter(io.vertx.core.http.HttpServerRequest request, int expireAfter)Sets an "X-Expire-After" header.static voidsetQueueExpireAfter(io.vertx.core.MultiMap headers, int queueExpireAfter)Sets an "x-queue-expire-after" header.static voidupdateServerTimestampHeader(io.vertx.core.MultiMap headers)Checks if a "X-Server-Timestamp" header is set or not.static voidupdateServerTimestampHeader(HttpRequest request)Checks if a "X-Server-Timestamp" header is set or not.
-
-
-
Field Detail
-
SERVER_TIMESTAMP_HEADER
public static final String SERVER_TIMESTAMP_HEADER
- See Also:
- Constant Field Values
-
EXPIRE_AFTER_HEADER
public static final String EXPIRE_AFTER_HEADER
- See Also:
- Constant Field Values
-
QUEUE_EXPIRE_AFTER_HEADER
public static final String QUEUE_EXPIRE_AFTER_HEADER
- See Also:
- Constant Field Values
-
-
Method Detail
-
updateServerTimestampHeader
public static void updateServerTimestampHeader(HttpRequest request)
Checks if a "X-Server-Timestamp" header is set or not. If no valid value is found, the current timestamp is set.- Parameters:
request- request
-
updateServerTimestampHeader
public static void updateServerTimestampHeader(io.vertx.core.MultiMap headers)
Checks if a "X-Server-Timestamp" header is set or not. If no valid value is found, the current timestamp is set.- Parameters:
headers- headers
-
getExpireAfter
public static Integer getExpireAfter(io.vertx.core.MultiMap headers)
Extracts the value of the "X-Expire-After" header. If the value can't be extracted (not found, invalid, and so on), null is returned.- Parameters:
headers- headers- Returns:
- expire-after time in seconds or null if nothing is found
-
getExpireAfterConcerningCaseOfCorruptHeaderAndInfinite
public static Optional<Integer> getExpireAfterConcerningCaseOfCorruptHeaderAndInfinite(io.vertx.core.MultiMap headers)
Delegates togetExpireValue(String)This is extended version ofgetExpireAfter(MultiMap)but also returning -1 for infinite.- Parameters:
headers- Headers to fetch value from.- Returns:
The parsed expire-after value.
Returns empty in case
getExpireValue(String)returned null.
-
getQueueExpireAfter
public static Integer getQueueExpireAfter(io.vertx.core.MultiMap headers)
Extracts the value of the "x-queue-expire-after" header. If the value can't be extracted (not found, invalid, and so on), null is returned.- Parameters:
headers- headers- Returns:
- queue-expire-after time in seconds or null if nothing is found
-
isExpired
public static boolean isExpired(io.vertx.core.MultiMap headers, Long timestamp)Checks the expiration based on the given headers and a timstamp in milliseconds.- Parameters:
headers- headers- Returns:
- true if the request has expired, false otherwise
-
getExpirationTime
public static org.joda.time.DateTime getExpirationTime(int expireAfter)
Returns the expiration time, based on the current time (now) in addition with the expireAfter value.- Parameters:
expireAfter- - in seconds- Returns:
- expiration time
-
getExpirationTimeAsString
public static Optional<String> getExpirationTimeAsString(int expireAfter)
- Returns:
- Expiration time based on passed expireAfter or empty in case of an infinite expiration.
-
parseDateTime
public static org.joda.time.DateTime parseDateTime(String datetime)
Parses the given string to a DateTime object.- Parameters:
datetime- datetime as string- Returns:
- DateTime
-
printDateTime
public static String printDateTime(org.joda.time.DateTime datetime)
Prints the given datetime as a string.- Parameters:
datetime- datetime- Returns:
- String
-
setExpireAfter
public static void setExpireAfter(io.vertx.core.http.HttpServerRequest request, int expireAfter)Sets an "X-Expire-After" header. If such a header already exist, it's overridden by the new value.- Parameters:
request- requestexpireAfter- expireAfter
-
setQueueExpireAfter
public static void setQueueExpireAfter(io.vertx.core.MultiMap headers, int queueExpireAfter)Sets an "x-queue-expire-after" header. If such a header already exist, it's overridden by the new value.- Parameters:
headers- headersqueueExpireAfter- queueExpireAfter
-
-