Class URLUtil

java.lang.Object
org.apache.solr.common.util.URLUtil

public class URLUtil extends Object
  • Field Details

    • URL_PREFIX

      public static final Pattern URL_PREFIX
  • Constructor Details

    • URLUtil

      public URLUtil()
  • Method Details

    • removeScheme

      public static String removeScheme(String url)
    • hasScheme

      public static boolean hasScheme(String url)
    • getScheme

      public static String getScheme(String url)
    • isBaseUrl

      public static boolean isBaseUrl(String url)
    • extractBaseUrl

      public static String extractBaseUrl(String coreUrl)
      Parameters:
      coreUrl - a URL pointing to a specific "core" or collection (i.e. that adheres loosely to the form "scheme://host:port/solr/coreName")
      Returns:
      a URL pointing to the Solr node's root path
    • extractCoreFromCoreUrl

      public static String extractCoreFromCoreUrl(String coreUrl)
    • buildCoreUrl

      public static String buildCoreUrl(String baseUrl, String coreName)
      Create a core URL (e.g. "http://localhost:8983/solr/myCore") from its individual components
      Parameters:
      baseUrl - a Solr "base URL" (e.g. "http://localhost:8983/solr/")
      coreName - the name of a Solr core or collection (with no leading or trailing slashes)
    • getBaseUrlForNodeName

      public static String getBaseUrlForNodeName(String nodeName, String urlScheme)
      Construct a V1 base url for the Solr node, given its name (e.g., 'app-node-1:8983_solr') and a URL scheme.
      Parameters:
      nodeName - name of the Solr node
      urlScheme - scheme for the base url ('http' or 'https')
      Returns:
      url that looks like https://app-node-1:8983/solr
      Throws:
      IllegalArgumentException - if the provided node name is malformed
    • getBaseUrlForNodeName

      public static String getBaseUrlForNodeName(String nodeName, String urlScheme, boolean isV2)
      Construct a V1 or a V2 base url for the Solr node, given its name (e.g., 'app-node-1:8983_solr') and a URL scheme.
      Parameters:
      nodeName - name of the Solr node
      urlScheme - scheme for the base url ('http' or 'https')
      isV2 - whether a V2 url should be constructed
      Returns:
      url that looks like https://app-node-1:8983/api (V2) or https://app-node-1:8983/solr (V1)
      Throws:
      IllegalArgumentException - if the provided node name is malformed
    • getNodeNameForBaseUrl

      public static String getNodeNameForBaseUrl(String solrUrl) throws MalformedURLException, URISyntaxException
      Construct base Solr URL to a Solr node name
      Parameters:
      solrUrl - Given a base Solr URL string (e.g., 'https://app-node-1:8983/solr')
      Returns:
      Node name that looks like app-node-1:8983_solr
      Throws:
      MalformedURLException - if the provided URL string is malformed
      URISyntaxException - if the provided URL string could not be parsed as a URI reference.
    • buildURI

      public static URI buildURI(URI baseUri, String path)
      Constructs a properly encoded URI by combining a base URI with a request path. This ensures special characters (like umlauts) are properly percent-encoded.
      Parameters:
      baseUri - the base URI (e.g., URI for "http://localhost:8983/solr")
      path - the path to append (e.g., "/config/overlay" or "admin/cores")
      Returns:
      a properly encoded URI
      Throws:
      IllegalArgumentException - if the baseUri or path are invalid
    • buildURI

      public static URI buildURI(URI baseUri, String path, SolrParams queryParams)
      Constructs a properly encoded URI by combining a base URI with a request path and optional query parameters. This ensures special characters are properly percent-encoded.
      Parameters:
      baseUri - the base URI (e.g., URI for "http://localhost:8983/solr")
      path - the path to append (e.g., "/config/overlay" or "admin/cores"). May include a query string (e.g., "/select?q=test")
      queryParams - optional query parameters to append (can be null). If the path already contains a query string, these params will be added to it.
      Returns:
      a properly encoded URI
      Throws:
      IllegalArgumentException - if the baseUri or path are invalid