Class EndpointBuilder


  • public class EndpointBuilder
    extends Object
    EndpointBuilder provides a wrapper to construct the appropriate endpoint for a service.

    The service may override the endpoint template, but if not, a default template will be used.

    • Field Detail

      • OPTIONS_REGEX

        public static final String OPTIONS_REGEX
        Regex to detect options defined in the endpoint template.

        It checks for the following pattern:

        • Starts with an opening curly brace ({)
        • Followed by 1 or more word characters
        • Followed by a question mark (?)
        • Followed by any one of the following:
          • one or more word characters, followed by a period:one or more word characters, followed by a period
          • one or more word characters, followed by a period:zero or more whitespace characters
          • zero or more whitespace characters:one or more word characters, followed by a period
        • Ends with a closing curly brace (})

        Example: {option?v1.:v2.}, {option?:v2.}, {option?v1.:} are valid patterns

        Example: {option?v1:v2+}, {option?:v2}, {option?v1?:} {option?:} are invalid pattern

        See Also:
        Constant Field Values
      • OPTIONS_PATTERN

        public static final Pattern OPTIONS_PATTERN
    • Method Detail

      • getRealmSpecificEndpointTemplate

        public static String getRealmSpecificEndpointTemplate​(String regionId,
                                                              Service service,
                                                              Realm realm)
      • getServiceEndpointTemplateToUse

        public static String getServiceEndpointTemplateToUse​(String regionId,
                                                             Service service,
                                                             Realm realm)
      • overrideRegionId

        public static void overrideRegionId​(@Nonnull
                                            String regionId,
                                            @Nonnull
                                            String overrideRegionId)
        Temporary ability to override the region for a given regionId.

        This will most likely be removed at a later point in time. It is not intended for use outside of the SDK.

        Parameters:
        regionId - The value obtained from Region.getRegionId().
        overrideRegionId - The alternative regionId to use.
      • populateServiceParametersInEndpoint

        public static final WrappedWebTarget populateServiceParametersInEndpoint​(RestClient client,
                                                                                 Map<String,​Object> requiredParametersMap)
        Populate the parameters in the endpoint with its corresponding value and update the base endpoint.

        The value will be populated iff the parameter in endpoint is a required request path parameter or a required request query parameter. If not, the parameter in the endpoint will be ignored and left blank.

        Parameters:
        client - The RestClient in use
        requiredParametersMap - Map of parameter name as key and value set in request path or query parameter as value
      • getEndpointWithPopulatedServiceParams

        protected static String getEndpointWithPopulatedServiceParams​(String baseUriString,
                                                                      Map<String,​Object> requiredParametersMap,
                                                                      Map<String,​Boolean> optionsMap)
        Populate the parameters in the endpoint with its corresponding value, process options, and return the processed endpoint.

        For parameters, the value will be populated iff the parameter in endpoint is a required request path parameter or a required request query parameter. If not, the parameter in the endpoint will be ignored and left blank.

        For options, the true-choice or the false-choice will be entered into the endpoint, depending on the state of the option. If the option is unknown, the entire option construct will be removed, meaning neither the true-choice nor the false-choice will be used.

        Parameters:
        baseUriString - base URI string, may be parameterized
        requiredParametersMap - the map from required parameter name to their values
        optionsMap - the map from option name to enabled/disabled status
        Returns:
        endpoint with parameters replaced with their values
      • isEndpointParameterized

        public static boolean isEndpointParameterized​(String endpoint)
        Checks if the given endpoint string contains any placeholders.

        A placeholder is denoted by the presence of ‘{’ character.

        Parameters:
        endpoint - the endpoint string to check for parameterization
        Returns:
        true if the endpoint is parameterized, false otherwise
      • removeAllParametersFromEndpoint

        public static String removeAllParametersFromEndpoint​(String updatedEndpoint)
        Removes all placeholders from the given endpoint string.
        Parameters:
        updatedEndpoint - the endpoint string to remove parameters from
        Returns:
        the endpoint string with all placeholders removed