public enum HttpUtils extends Enum<HttpUtils>
Utility functions related to HTTP calls.
Note, the overloading performed in this class is to allow for compile time validation of the args passed in (vs. taking a generic Object and throwing an exception if the class isn't supported at runtime).
Modifier and Type | Method and Description |
---|---|
static Object |
attemptEncodeQueryParam(Object queryParam)
Attempts to encode a query param if it is a String.
|
static <T> WrappedWebTarget |
encodeCollectionFormatQueryParam(WrappedWebTarget target,
String queryParamName,
List<T> values,
CollectionFormatType collectionFormatType)
Attempts to encode a query parameter which is described by a list of values for that parameter and a
CollectionFormatType which describes how the values should appear
in the query string (e.g. |
static WrappedWebTarget |
encodeMapQueryParam(WrappedWebTarget target,
String prefix,
Map<String,?> queryParam)
Attempts to encode a query param if it is a
Map . |
static String |
encodePathSegment(Boolean pathSegment)
Encodes a path segment.
|
static String |
encodePathSegment(Character pathSegment)
Encodes a path segment.
|
static String |
encodePathSegment(Number pathSegment)
Encodes a path segment.
|
static String |
encodePathSegment(String pathSegment)
Encodes a path segment.
|
static String |
encodePathSegment(UUID pathSegment)
Encodes a path segment.
|
static String |
urlPathSegmentEscape(String pathSegment)
Escape a URL path segment string.
|
static HttpUtils |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static HttpUtils[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static HttpUtils[] values()
for (HttpUtils c : HttpUtils.values()) System.out.println(c);
public static HttpUtils valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static String urlPathSegmentEscape(String pathSegment)
Escape a URL path segment string.
pathSegment
- path segment to escapepublic static String encodePathSegment(@Nonnull String pathSegment)
Encodes a path segment.
pathSegment
- The path segment to encode.public static String encodePathSegment(@Nonnull Number pathSegment)
Encodes a path segment.
pathSegment
- The path segment to encode.public static String encodePathSegment(@Nonnull Boolean pathSegment)
Encodes a path segment.
pathSegment
- The path segment to encode.public static String encodePathSegment(@Nonnull Character pathSegment)
Encodes a path segment.
pathSegment
- The path segment to encode.public static String encodePathSegment(@Nonnull UUID pathSegment)
Encodes a path segment.
pathSegment
- The path segment to encode.public static Object attemptEncodeQueryParam(Object queryParam)
Attempts to encode a query param if it is a String. This does not try to encode non-String values as Jersey uses different serializers for non-String values, so we can’t assume what the string value would be.
Note: this should be called much lower in the HTTP stack (currently being called through the generated code), so it can encode the serialized values.
queryParam
- The query parameter to encode.public static WrappedWebTarget encodeMapQueryParam(WrappedWebTarget target, String prefix, Map<String,?> queryParam)
Attempts to encode a query param if it is a Map
. Each key is prefixed with the value passed as
prefix
. If a value is a Collection
, then the “{prefix}{key}={item}” output is repeated for each
item in the collection, where “{item}” is encoded using attemptEncodeQueryParam(Object)
.
If the value is not a collection, then the output is simply “{prefix}{key}={value}”, where the value is again
encoded.
Note: this should be called much lower in the HTTP stack (currently being called through the generated code), so it can encode the serialized values.
target
- target instanceprefix
- prefix for each keyqueryParam
- The map query parameter to encode.public static <T> WrappedWebTarget encodeCollectionFormatQueryParam(WrappedWebTarget target, String queryParamName, List<T> values, CollectionFormatType collectionFormatType)
Attempts to encode a query parameter which is described by a list of values for that parameter and a
CollectionFormatType
which describes how the values should appear
in the query string (e.g. as multiple parameters, as a single parameter with a given delimiter).
target
- target instancequeryParamName
- the name of the query parameter as it should appear in the query stringvalues
- the values for the query parameter. An empty or null list will result in no action being taken
on the target instance. Additionally, any null values inside the list will be ignoredcollectionFormatType
- describes how entries should appear in the query string, for example as multiple
parameters with the name query string parameter name/key, or as a single parameter with its values separated
by a delimiter character (comma, space, tab or pipe)Copyright © 2016–2023. All rights reserved.