Class PropertiesHelper
java.lang.Object
org.glassfish.jersey.internal.util.PropertiesHelper
Helper class containing convenience methods for reading
org.glassfish.jersey.server.ResourceConfig
and Configuration
properties.- Author:
- Martin Matula
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
convertValue
(Object value, Class<T> type) ConvertObject
value to a value of the specified class type.static String
getPropertyNameForRuntime
(String key, RuntimeType runtimeType) Returns specific property value for givenRuntimeType
.static PrivilegedAction<Properties>
Get system properties.static PrivilegedAction<String>
getSystemProperty
(String name) Get system property.static PrivilegedAction<String>
getSystemProperty
(String name, String def) Get system property.static <T> T
getValue
(Map<String, ?> properties, RuntimeType runtimeType, String key, Class<T> type, Map<String, String> legacyMap) Returns value of a specified property.static <T> T
getValue
(Map<String, ?> properties, RuntimeType runtimeType, String key, T defaultValue, Class<T> type, Map<String, String> legacyMap) Returns value of a specified property.static <T> T
getValue
(Map<String, ?> properties, RuntimeType runtimeType, String key, T defaultValue, Map<String, String> legacyMap) Return value of a specified property.static <T> T
Returns value of a specified property.static <T> T
getValue
(Map<String, ?> properties, String key, T defaultValue, Class<T> type, Map<String, String> legacyMap) Returns value of a specified property.static <T> T
Return value of a specified property.static boolean
isJaxRsServiceLoadingEnabled
(Map<String, Object> properties) Check whether loading of JAX-RS services is allowed or not.static boolean
isMetaInfServicesEnabled
(Map<String, Object> properties, RuntimeType runtimeType) Determine whetherCommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
does not globally disable META-INF/services lookup on client/server.static boolean
isProperty
(Object value) Get the value of the property converted toboolean
.static boolean
isProperty
(Map<String, Object> properties, String name) Get the value of the property with a given name converted toboolean
.static boolean
isPropertyOrNotSet
(Object value) Converts the property value toboolean
and checks it istrue
or empty.
-
Method Details
-
getSystemProperties
Get system properties. This method delegates toSystem.getProperties()
while running it in a privileged code block.- Returns:
- privileged action to obtain system properties.
-
getSystemProperty
Get system property. This method delegates toSystem.getProperty(String)
while running it in a privileged code block.- Parameters:
name
- system property name.- Returns:
- privileged action to obtain system property value that will return
null
if there's no such system property.
-
getSystemProperty
Get system property. This method delegates toSystem.getProperty(String)
while running it in a privileged code block.- Parameters:
name
- system property name.def
- default property value.- Returns:
- privileged action to obtain system property value that will return the default value if there's no such system property.
-
getValue
public static <T> T getValue(Map<String, ?> properties, String key, T defaultValue, Map<String, String> legacyMap) Return value of a specified property. If the property is not set or the real value type is not compatible with defaultValue type, the specified defaultValue is returned. Calling this method is equivalent to callingPropertyHelper.getValue(properties, key, defaultValue, (Class<T>) defaultValue.getClass())
- Type Parameters:
T
- Type of the property value.- Parameters:
properties
- Map of properties to get the property value from.key
- Name of the property.defaultValue
- Default value to be returned if the specified property is not set or cannot be read.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property name- Returns:
- Value of the property or defaultValue.
-
getValue
public static <T> T getValue(Map<String, ?> properties, RuntimeType runtimeType, String key, T defaultValue, Map<String, String> legacyMap) Return value of a specified property. If the property is not set or the real value type is not compatible with defaultValue type, the specified defaultValue is returned. Calling this method is equivalent to callingPropertyHelper.getValue(properties, runtimeType, key, defaultValue, (Class<T>) defaultValue.getClass())
- Type Parameters:
T
- Type of the property value.- Parameters:
properties
- Map of properties to get the property value from.runtimeType
- Runtime type which is used to check whether there is a property with the samekey
but post-fixed by runtime type (.server or.client
) which would override thekey
property.key
- Name of the property.defaultValue
- Default value to be returned if the specified property is not set or cannot be read.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property name- Returns:
- Value of the property or defaultValue.
-
getValue
public static <T> T getValue(Map<String, ?> properties, String key, T defaultValue, Class<T> type, Map<String, String> legacyMap) Returns value of a specified property. If the property is not set or the real value type is not compatible with the specified value type, returns defaultValue.- Type Parameters:
T
- Type of the property value.- Parameters:
properties
- Map of properties to get the property value from.key
- Name of the property.defaultValue
- Default value of the property.type
- Type to retrieve the value as.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property name- Returns:
- Value of the property or null.
-
getValue
public static <T> T getValue(Map<String, ?> properties, RuntimeType runtimeType, String key, T defaultValue, Class<T> type, Map<String, String> legacyMap) Returns value of a specified property. If the property is not set or the real value type is not compatible with the specified value type, returns defaultValue.- Type Parameters:
T
- Type of the property value.- Parameters:
properties
- Map of properties to get the property value from.runtimeType
- Runtime type which is used to check whether there is a property with the samekey
but post-fixed by runtime type (.server or.client
) which would override thekey
property.key
- Name of the property.defaultValue
- Default value of the property.type
- Type to retrieve the value as.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property name- Returns:
- Value of the property or null.
-
getValue
public static <T> T getValue(Map<String, ?> properties, String key, Class<T> type, Map<String, String> legacyMap) Returns value of a specified property. If the property is not set or the real value type is not compatible with the specified value type, returns null.- Type Parameters:
T
- Type of the property value.- Parameters:
properties
- Map of properties to get the property value from.key
- Name of the property.type
- Type to retrieve the value as.legacyMap
- Legacy fallback map, where key is the actual property name, value is the old property name- Returns:
- Value of the property or null.
-
getValue
public static <T> T getValue(Map<String, ?> properties, RuntimeType runtimeType, String key, Class<T> type, Map<String, String> legacyMap) Returns value of a specified property. If the property is not set or the real value type is not compatible with the specified value type, returns null.- Type Parameters:
T
- Type of the property value.- Parameters:
properties
- Map of properties to get the property value from.runtimeType
- Runtime type which is used to check whether there is a property with the samekey
but post-fixed by runtime type (.server or.client
) which would override thekey
property.key
- Name of the property.type
- Type to retrieve the value as.- Returns:
- Value of the property or null.
-
getPropertyNameForRuntime
Returns specific property value for givenRuntimeType
. Some properties have complementary client and server versions along with a common version (effective for both environments, if the specific one is not set). This methods returns a specific name for the environment (determined by convention), if runtime is not null, the property is a Jersey property name (starts withjersey.config
) and does not contain a runtime specific part already. If those conditions are not met, original property name is returned.- Parameters:
key
- property nameruntimeType
- runtime type- Returns:
- runtime-specific property name, where possible, original key in other cases. original key
-
convertValue
ConvertObject
value to a value of the specified class type.- Type Parameters:
T
- converted value type.- Parameters:
value
-Object
value to convert.type
- conversion type.- Returns:
- value converted to the specified class type.
-
isMetaInfServicesEnabled
public static boolean isMetaInfServicesEnabled(Map<String, Object> properties, RuntimeType runtimeType) Determine whetherCommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
does not globally disable META-INF/services lookup on client/server.- Parameters:
properties
- map containing application properties. May benull
runtimeType
- runtime (client or server) where the service finder binder is used.- Returns:
true
if theCommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
is not se to true
-
isJaxRsServiceLoadingEnabled
Check whether loading of JAX-RS services is allowed or not. Services shall implement Feature or DynamicFeature interface and be listed as SPI in an application- Parameters:
properties
- list of properties to be checked- Returns:
- false if loading of JAX-RS services is not enabled
- Since:
- 2.35
-
isProperty
Get the value of the property with a given name converted toboolean
. Returnsfalse
if the value is not convertible.- Parameters:
properties
- key-value map of properties.name
- property name.- Returns:
boolean
property value orfalse
if the property is not convertible.
-
isProperty
Get the value of the property converted toboolean
. Returnsfalse
if the value is not convertible.- Parameters:
value
- property value.- Returns:
boolean
property value orfalse
if the property is not convertible.
-
isPropertyOrNotSet
Converts the property value toboolean
and checks it istrue
or empty. Returnstrue
if the value istrue
or empty but notnull
.The rationale behind this is that system property
-Dprop=true
is the same as-Dprop
. The property-Dprop=false
behaves as if the-Dprop
is not set at all.- Parameters:
value
- property value.- Returns:
boolean
property value ortrue
if the property value is not set orfalse
if the property is otherwise not convertible.
-