/** * Same as `tryGetGlobalProperty` but with null as implicit default value * @param key Variable name * @return Environment or System property value or null if not found */ public static String tryGetGlobalProperty(String key) { return tryGetGlobalProperty(key, null); }
/** * Same as `tryGetGlobalIntegerProperty` but with null as implicit default value * @param key Variable name * @return Environment or System property value or null if not found */ public static Integer tryGetGlobalIntegerProperty(String key) { return tryGetGlobalIntegerProperty(key, null); } }
/** * Get a global string property. This method will first try to get the value from an * environment variable and if that does not exist it will look up a system property. * @param key Name of the variable * @param defaultValue Returned if neither env var nor system property are defined * @return String the value of the Environment or System Property if defined, the given * default value otherwise */ public static String tryGetGlobalProperty(String key, String defaultValue) { try { String value = System.getenv(formatEnvironmentVariable(key)); if (value == null) { value = tryGetProperty(key, defaultValue); } return value; } catch (SecurityException e) { logger.error("Could not get value of global property {} due to SecurityManager. Using default value.", key, e); return defaultValue; } }
@SuppressWarnings("unchecked") private static <T> T getProperty(VariantType type, ConfigurationProperty property, T defaultValue, Class<T> expectedType) { String systemPropertyName = getSystemPropertyName(type, property); if (expectedType == String.class) { return (T) ConfigurationUtils.tryGetGlobalProperty(systemPropertyName, (String) defaultValue); } else if (expectedType == Integer.class) { return (T) ConfigurationUtils.tryGetGlobalIntegerProperty(systemPropertyName, (Integer) defaultValue); } else { throw new IllegalStateException("Unexpected type: " + expectedType); } }
/** * Get a global integer property. This method will first try to get the value from an * environment variable and if that does not exist it will look up a system property. * @param key Name of the variable * @param defaultValue Returned if neither env var nor system property are defined * @return String the value of the Environment or System Property if defined, the given * default value otherwise */ public static Integer tryGetGlobalIntegerProperty(String key, Integer defaultValue) { try { String value = System.getenv(formatEnvironmentVariable(key)); if (value == null) { return tryGetIntegerProperty(key, defaultValue); } else { return Integer.parseInt(value); } } catch (SecurityException | NumberFormatException e) { logger.error("Could not get value of global property {} due to SecurityManager. Using default value.", key, e); return defaultValue; } }
@SuppressWarnings("unchecked") private static <T> T getProperty(VariantType type, ConfigurationProperty property, T defaultValue, Class<T> expectedType) { String systemPropertyName = getSystemPropertyName(type, property); if (expectedType == String.class) { return (T) ConfigurationUtils.tryGetGlobalProperty(systemPropertyName, (String) defaultValue); } else if (expectedType == Integer.class) { return (T) ConfigurationUtils.tryGetGlobalIntegerProperty(systemPropertyName, (Integer) defaultValue); } else { throw new IllegalStateException("Unexpected type: " + expectedType); } }
/** * Same as `tryGetGlobalProperty` but with null as implicit default value * @param key Variable name * @return Environment or System property value or null if not found */ public static String tryGetGlobalProperty(String key) { return tryGetGlobalProperty(key, null); }
/** * Same as `tryGetGlobalIntegerProperty` but with null as implicit default value * @param key Variable name * @return Environment or System property value or null if not found */ public static Integer tryGetGlobalIntegerProperty(String key) { return tryGetGlobalIntegerProperty(key, null); } }
/** * Get a global string property. This method will first try to get the value from an * environment variable and if that does not exist it will look up a system property. * @param key Name of the variable * @param defaultValue Returned if neither env var nor system property are defined * @return String the value of the Environment or System Property if defined, the given * default value otherwise */ public static String tryGetGlobalProperty(String key, String defaultValue) { try { String value = System.getenv(formatEnvironmentVariable(key)); if (value == null) { value = tryGetProperty(key, defaultValue); } return value; } catch (SecurityException e) { logger.error("Could not get value of global property {} due to SecurityManager. Using default value.", key, e); return defaultValue; } }
/** * Get a global integer property. This method will first try to get the value from an * environment variable and if that does not exist it will look up a system property. * @param key Name of the variable * @param defaultValue Returned if neither env var nor system property are defined * @return String the value of the Environment or System Property if defined, the given * default value otherwise */ public static Integer tryGetGlobalIntegerProperty(String key, Integer defaultValue) { try { String value = System.getenv(formatEnvironmentVariable(key)); if (value == null) { return tryGetIntegerProperty(key, defaultValue); } else { return Integer.parseInt(value); } } catch (SecurityException | NumberFormatException e) { logger.error("Could not get value of global property {} due to SecurityManager. Using default value.", key, e); return defaultValue; } }
@Override protected HttpURLConnection getConnection(String url) throws IOException { // let's see if there is a different URL we should post to (e.g. load/stress testing) final String fcmURL = ConfigurationUtils.tryGetGlobalProperty(CUSTOM_AEROGEAR_FCM_PUSH_HOST, FCM_ENDPOINT_HOST); return (HttpURLConnection) new URL(fcmURL).openConnection(); }
/** * We trigger a delete of all {@link org.jboss.aerogear.unifiedpush.api.FlatPushMessageInformation} objects that are * <i>older</i> than 30 days! */ public void deleteOutdatedFlatPushInformationData() { final Date historyDate = DateUtils.calculatePastDate(ConfigurationUtils.tryGetGlobalIntegerProperty(AEROGEAR_METRICS_STORAGE_MAX_DAYS, 30)); logger.trace("Delete all until {}", historyDate.getTime()); flatPushMessageInformationDao.deletePushInformationOlderThan(historyDate); }
@Override protected HttpURLConnection getConnection(String url) throws IOException { // let's see if there is a different URL we should post to (e.g. load/stress testing) final String fcmURL = ConfigurationUtils.tryGetGlobalProperty(CUSTOM_AEROGEAR_FCM_PUSH_HOST, FCM_ENDPOINT_HOST); return (HttpURLConnection) new URL(fcmURL).openConnection(); }
@GET @Produces(MediaType.APPLICATION_JSON) public Response configurationFile() throws JsonProcessingException { final String realmName = ConfigurationUtils.tryGetGlobalProperty(REALM_NAME_PROPERTY); final String keycloakServerURL = removeDefaultHttpPorts(ConfigurationUtils.tryGetGlobalProperty(REALM_URL_PROPERTY)); final Config config = new Config(realmName, keycloakServerURL); logger.trace("rendering '{}' realm config, for {}", realmName, keycloakServerURL); return Response.ok(mapper.writeValueAsString(config)).build(); }