Interface PathFactory


public interface PathFactory
Provider of paths for a web application, which can normalize paths and strip out the base path for the web application, if any. Uses Settings to look up default values for host name, port, etc. This enables an application to generate fully qualified URLs to paths within it, without needing to know if it is reverse-proxied, or if a path element is prepended to all URLs as part of that proxying.
Author:
Tim Boudreau
See Also:
  • ServerModule.SETTINGS_KEY_BASE_PATH
  • ServerModule.SETTINGS_KEY_URLS_HOST_NAME
  • ServerModule.SETTINGS_KEY_URLS_EXTERNAL_PORT
  • ServerModule.SETTINGS_KEY_URLS_EXTERNAL_SECURE_PORT
  • ServerModule.SETTINGS_KEY_GENERATE_SECURE_URLS
  • ServerModule.SETTINGS_KEY_GENERATE_URLS_WITH_INET_ADDRESS_GET_LOCALHOST
  • Field Details

  • Method Details

    • toPath

      Path toPath(String uri)
      Convert a URI from a request to a path, stripping out the basepath if any.
      Parameters:
      uri - A URI
      Returns:
      A path
    • constructURL

      URL constructURL(Path path, boolean secure)
      Construct a URL suitable for external use, inserting the basepath and host name if necessary.
      Parameters:
      path - The path relative to the web application
      secure - Whether or not to construct an https URL
      Returns:
      A url
    • constructURL

      URL constructURL(Protocol protocol, Path path)
      Construct a URL suitable for external use, inserting the basepath and host name if necessary.
      Parameters:
      protocol - The protocol for the new url
      path - The path relative to the web application
      Returns:
      A url
    • constructURL

      URL constructURL(Protocol protocol, Path path, boolean secure)
    • constructURL

      URL constructURL(Protocol protocol, Path path, int port)
    • toExternalPath

      Path toExternalPath(Path path)
      Prepend the base path if necessary
      Parameters:
      path - A path
      Returns:
      a path
    • toExternalPath

      Path toExternalPath(String path)
      Prepend the base path if necessary
      Parameters:
      path - A path
      Returns:
      a path
    • constructURL

      URL constructURL(Path path)
      Generate a URL to this application, using the path and the system default for whether to use http or https.
      Parameters:
      path -
      Returns:
    • portForProtocol

      int portForProtocol(Protocol protocol)
    • constructURL

      default URL constructURL(String path)
      Generate a URL to this application, using the path and the system default for whether to use http or https.
      Parameters:
      path -
      Returns:
    • constructURL

      URL constructURL(String path, HttpEvent evt)
      Generate a URL to this application, using the path and the system default for whether to use http or https.

      This method will preserve any query string in the path, assuming the following:

      • The query item follows the pattern ?param1=x&param2=y
      • The same query item does not repeat
      (Hint: if you need to do a redirect that doesn't follow this pattern, add(Headers.LOCATION.stringHeader(), "http://weird.url?foo&foo&foo&bar=");)
      Parameters:
      path - A url path
      evt - An event to use the host header from if available.
      Returns:
      A URL
      Throws:
      IllegalArgumentException - if the path is not a legal URL path (character set, etc.) - convert using IDN first if you need to; or if the port in the Host header is not a number.
    • constructURI

      default URI constructURI(String path, HttpEvent evt)
    • constructURI

      default URI constructURI(String path)