java.lang.Object
io.opentelemetry.instrumentation.jdbc.internal.parser.UrlParsingUtils

public final class UrlParsingUtils extends Object
Utility methods for parsing JDBC URLs.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

  • Field Details

    • IPV6_PATTERN

      public static final Pattern IPV6_PATTERN
  • Method Details

    • splitQuery

      public static Map<String,String> splitQuery(String query, String separator)
      Split a query string into key-value pairs.
      Parameters:
      query - the query string
      separator - the separator between pairs (e.g., "&" or ";")
      Returns:
      a map of key-value pairs
    • parsePort

      @Nullable public static Integer parsePort(@Nullable String value)
      Parse an integer value, returning null if parsing fails.
      Parameters:
      value - the string value to parse
      Returns:
      the parsed integer, or null if parsing fails
    • buildShortUrl

      public static String buildShortUrl(String type, @Nullable String subtype, @Nullable String host, @Nullable Integer port)
      Build the short URL for db.connection_string attribute.
      Parameters:
      type - the JDBC type (e.g., "postgresql", "mysql")
      subtype - optional subtype (e.g., "thin" for Oracle, "aurora" for MySQL)
      host - the host name
      port - the port number
      Returns:
      the short URL in format "type:[subtype:]//host:port" or "type:" if no host
    • extractParams

      public static Map<String,String> extractParams(String jdbcUrl, String startDelimiter, String splitSeparator)
      Extract parameters from a JDBC URL.
      Parameters:
      jdbcUrl - the JDBC URL
      startDelimiter - the delimiter marking the start of parameters (";" or "?")
      splitSeparator - the separator between parameters (";" or "&")
      Returns:
      a map of parameter key-value pairs
    • extractSemicolonParams

      public static Map<String,String> extractSemicolonParams(String jdbcUrl)
      Extract semicolon-delimited URL parameters from a JDBC URL.
      Parameters:
      jdbcUrl - the JDBC URL containing parameters after semicolon
      Returns:
      a map of parameter key-value pairs
    • extractQueryParams

      public static Map<String,String> extractQueryParams(String jdbcUrl, String separator)
      Extract query-style URL parameters from a JDBC URL.
      Parameters:
      jdbcUrl - the JDBC URL containing parameters after "?"
      separator - the parameter separator (typically "&")
      Returns:
      a map of parameter key-value pairs
    • extractSubtype

      @Nullable public static String extractSubtype(String jdbcUrl)
      Extract subtype from a JDBC URL of the form "type:subtype://...".

      For example, "mysql:aurora://host:port/db" returns "aurora", "oceanbase:oracle://host/db" returns "oracle".

      Parameters:
      jdbcUrl - the JDBC URL
      Returns:
      the subtype, or null if no subtype is present
    • indexOfAny

      public static int indexOfAny(String str, char... chars)
      Find the index of the first occurrence of any of the specified characters.
      Parameters:
      str - the string to search
      chars - the characters to search for
      Returns:
      the index of the first occurrence, or -1 if none found
    • extractHostPort

      public static UrlParsingUtils.HostPort extractHostPort(String serverName)
      Extract host and port from a server string, handling IPv6 addresses. Supports formats: host, host:port, [ipv6], [ipv6]:port, ipv6 (auto-bracketed).
      Parameters:
      serverName - the server string to parse
      Returns:
      the extracted host and port