/** * Parses a cache directive. * * @param directive The directive to parse. * @return The cache directive or {@code null} if the directive cannot be parsed. */ public static CacheDirective from(final String directive) { if (directive == null) { return null; } else { Matcher matcher = PATTERN_MAX_AGE.matcher(directive); if (matcher.matches()) { return maxAgeDirective(Long.parseLong(matcher.group(1))); } else { matcher = PATTERN_NO_CACHE.matcher(directive); if (matcher.matches()) { return noCacheDirective(); } else { return null; } } } }
/** * Creates a new <em>no-cache</em> directive. * * @return The directive. */ public static CacheDirective noCacheDirective() { return new CacheDirective(true, 0); }
/** * Adds a caching directive to an AMQP 1.0 message. * <p> * The directive is put to the message's <em>application-properties</em> under key * {@link #APP_PROPERTY_CACHE_CONTROL}. * * @param msg The message to add the directive to. * @param cacheDirective The cache directive. * @throws NullPointerException if any of the parameters are {@code null}. */ public static void addCacheDirective(final Message msg, final CacheDirective cacheDirective) { addProperty(msg, APP_PROPERTY_CACHE_CONTROL, cacheDirective.toString()); }
.orElseGet(() -> { if (isCacheableStatusCode(response.getStatus())) { return CacheDirective.maxAgeDirective(getResponseCacheDefaultTimeout()); } else { return CacheDirective.noCacheDirective(); if (cacheDirective.isCachingAllowed()) { if (cacheDirective.getMaxAge() > 0) { responseCache.put(key, response, Duration.ofSeconds(cacheDirective.getMaxAge()));
TenantResult<JsonObject> getTenantResult(final String tenantId) { final TenantObject tenant = tenants.get(tenantId); if (tenant == null) { return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND); } else { return TenantResult.from( HttpURLConnection.HTTP_OK, JsonObject.mapFrom(tenant), CacheDirective.maxAgeDirective(MAX_AGE_GET_TENANT)); } }
private BufferResult(final int status, final String contentType, final Buffer payload) { super(status, payload, CacheDirective.noCacheDirective()); this.contentType = contentType; }
private R getRequestResponseResult(final Message message) { final Integer status = MessageHelper.getApplicationProperty( message.getApplicationProperties(), MessageHelper.APP_PROPERTY_STATUS, Integer.class); if (status == null) { return null; } else { final CacheDirective cacheDirective = CacheDirective.from(MessageHelper.getCacheDirective(message)); return getResult(status, message.getContentType(), MessageHelper.getPayload(message), cacheDirective); } }
TenantResult<JsonObject> getTenantResult(final String tenantId, final Span span) { final TenantObject tenant = tenants.get(tenantId); if (tenant == null) { TracingHelper.logError(span, "tenant not found"); return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND); } else { return TenantResult.from( HttpURLConnection.HTTP_OK, JsonObject.mapFrom(tenant), CacheDirective.maxAgeDirective(MAX_AGE_GET_TENANT)); } }
private BufferResult(final int status, final String contentType, final Buffer payload) { super(status, payload, CacheDirective.noCacheDirective()); this.contentType = contentType; }
private TenantResult<JsonObject> getForCertificateAuthority(final X500Principal subjectDn) { if (subjectDn == null) { return TenantResult.from(HttpURLConnection.HTTP_BAD_REQUEST); } else { final TenantObject tenant = getByCa(subjectDn); if (tenant == null) { return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND); } else { return TenantResult.from(HttpURLConnection.HTTP_OK, JsonObject.mapFrom(tenant), CacheDirective.maxAgeDirective(MAX_AGE_GET_TENANT)); } } }
/** * Creates a new result for a status code. * * @param status The status code indicating the outcome of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status) { return new CredentialsResult<>(status, null, CacheDirective.noCacheDirective()); }
/** * Parses a cache directive. * * @param directive The directive to parse. * @return The cache directive or {@code null} if the directive cannot be parsed. */ public static CacheDirective from(final String directive) { if (directive == null) { return null; } else { Matcher matcher = PATTERN_MAX_AGE.matcher(directive); if (matcher.matches()) { return maxAgeDirective(Long.parseLong(matcher.group(1))); } else { matcher = PATTERN_NO_CACHE.matcher(directive); if (matcher.matches()) { return noCacheDirective(); } else { return null; } } } }
/** * Creates a new <em>no-cache</em> directive. * * @return The directive. */ public static CacheDirective noCacheDirective() { return new CacheDirective(true, 0); }
/** * Adds a caching directive to an AMQP 1.0 message. * <p> * The directive is put to the message's <em>application-properties</em> under key * {@link #APP_PROPERTY_CACHE_CONTROL}. * * @param msg The message to add the directive to. * @param cacheDirective The cache directive. * @throws NullPointerException if any of the parameters are {@code null}. */ public static void addCacheDirective(final Message msg, final CacheDirective cacheDirective) { addProperty(msg, APP_PROPERTY_CACHE_CONTROL, cacheDirective.toString()); }
private TenantResult<JsonObject> getForCertificateAuthority(final X500Principal subjectDn, final Span span) { if (subjectDn == null) { TracingHelper.logError(span, "missing subject DN"); return TenantResult.from(HttpURLConnection.HTTP_BAD_REQUEST); } else { final TenantObject tenant = getByCa(subjectDn); if (tenant == null) { TracingHelper.logError(span, "no tenant found for subject DN"); return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND); } else { return TenantResult.from(HttpURLConnection.HTTP_OK, JsonObject.mapFrom(tenant), CacheDirective.maxAgeDirective(MAX_AGE_GET_TENANT)); } } }
/** * Creates a new result for a status code. * * @param status The status code indicating the outcome of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status) { return new CredentialsResult<>(status, null, CacheDirective.noCacheDirective()); }
/** * Creates a new <em>max-age</em> directive. * * @param maxAge The maximum age in number of seconds. * @return The directive. */ public static CacheDirective maxAgeDirective(final long maxAge) { if (maxAge <= 0) { throw new IllegalArgumentException("max age must be > 0"); } return new CacheDirective(false, maxAge); }
/** * Adds a property for the cache directive. * <p> * The property will only be added if the value is not {@code null}. * * @param directive The cache directive. * @return This message for chaining. */ public EventBusMessage setCacheDirective(final CacheDirective directive) { if (directive != null) { setProperty( MessageHelper.APP_PROPERTY_CACHE_CONTROL, Objects.requireNonNull(directive).toString()); } return this; }
HttpURLConnection.HTTP_OK, getAssertionPayload(tenantId, deviceId, result.getPayload().getJsonObject(RegistrationConstants.FIELD_DATA)), CacheDirective.maxAgeDirective(assertionFactory.getAssertionLifetime())); } else { TracingHelper.logError(span, "device not enabled");
/** * Creates a new result for a status code and payload. * <p> * This method simply invokes {@link #from(int, Object, CacheDirective)} * with {@link CacheDirective#noCacheDirective()}. * * @param status The status code indicating the outcome of the request. * @param payload The payload to convey to the sender of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status, final T payload) { return new CredentialsResult<>(status, payload, CacheDirective.noCacheDirective()); }