Class ExpiryCheckHandler
- java.lang.Object
-
- org.swisspush.gateleen.queue.expiry.ExpiryCheckHandler
-
public final class ExpiryCheckHandler extends java.lang.ObjectThe 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 java.lang.StringEXPIRE_AFTER_HEADERstatic java.lang.StringQUEUE_EXPIRE_AFTER_HEADERstatic java.lang.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 java.util.Optional<java.lang.String>getExpirationTimeAsString(int expireAfter)static java.lang.IntegergetExpireAfter(io.vertx.core.MultiMap headers)Extracts the value of the "X-Expire-After" header.static java.util.Optional<java.lang.Integer>getExpireAfterConcerningCaseOfCorruptHeaderAndInfinite(io.vertx.core.MultiMap headers)Delegates togetExpireValue(String)This is extended version ofgetExpireAfter(MultiMap)but also returning -1 for infinite.static java.lang.IntegergetQueueExpireAfter(io.vertx.core.MultiMap headers)Extracts the value of the "x-queue-expire-after" header.static booleanisExpired(io.vertx.core.MultiMap headers, java.lang.Long timestamp)Checks the expiration based on the given headers and a timstamp in milliseconds.static org.joda.time.DateTimeparseDateTime(java.lang.String datetime)Parses the given string to a DateTime object.static java.lang.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(org.swisspush.gateleen.core.http.HttpRequest request)Checks if a "X-Server-Timestamp" header is set or not.
-
-
-
Field Detail
-
SERVER_TIMESTAMP_HEADER
public static final java.lang.String SERVER_TIMESTAMP_HEADER
- See Also:
- Constant Field Values
-
EXPIRE_AFTER_HEADER
public static final java.lang.String EXPIRE_AFTER_HEADER
- See Also:
- Constant Field Values
-
QUEUE_EXPIRE_AFTER_HEADER
public static final java.lang.String QUEUE_EXPIRE_AFTER_HEADER
- See Also:
- Constant Field Values
-
-
Method Detail
-
updateServerTimestampHeader
public static void updateServerTimestampHeader(org.swisspush.gateleen.core.http.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 java.lang.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 java.util.Optional<java.lang.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 java.lang.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, java.lang.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 java.util.Optional<java.lang.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(java.lang.String datetime)
Parses the given string to a DateTime object.- Parameters:
datetime- datetime as string- Returns:
- DateTime
-
printDateTime
public static java.lang.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
-
-