Class UrlParsingUtils
java.lang.Object
io.opentelemetry.instrumentation.jdbc.internal.parser.UrlParsingUtils
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classResult of parsing a server string into host and port components.static final classLightweight wrapper for URL parameters that provides cleaner access patterns. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildShortUrl(String type, String subtype, String host, Integer port) Build the short URL for db.connection_string attribute.static UrlParsingUtils.HostPortextractHostPort(String serverName) Extract host and port from a server string, handling IPv6 addresses.extractParams(String jdbcUrl, String startDelimiter, String splitSeparator) Extract parameters from a JDBC URL.extractQueryParams(String jdbcUrl, String separator) Extract query-style URL parameters from a JDBC URL.extractSemicolonParams(String jdbcUrl) Extract semicolon-delimited URL parameters from a JDBC URL.static StringextractSubtype(String jdbcUrl) Extract subtype from a JDBC URL of the form "type:subtype://...".static intindexOfAny(String str, char... chars) Find the index of the first occurrence of any of the specified characters.static IntegerParse an integer value, returning null if parsing fails.splitQuery(String query, String separator) Split a query string into key-value pairs.
-
Field Details
-
IPV6_PATTERN
-
-
Method Details
-
splitQuery
Split a query string into key-value pairs.- Parameters:
query- the query stringseparator- the separator between pairs (e.g., "&" or ";")- Returns:
- a map of key-value pairs
-
parsePort
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 nameport- 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 URLstartDelimiter- the delimiter marking the start of parameters (";" or "?")splitSeparator- the separator between parameters (";" or "&")- Returns:
- a map of parameter key-value pairs
-
extractSemicolonParams
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
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
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
Find the index of the first occurrence of any of the specified characters.- Parameters:
str- the string to searchchars- the characters to search for- Returns:
- the index of the first occurrence, or -1 if none found
-
extractHostPort
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
-