org.appng.api

## Class RequestUtil

- java.lang.Object
- - org.appng.api.RequestUtil

-     public class RequestUtil
      extends Object

  Utility-class for mapping requests to `Site`s. Also creates a `Path` object based on a `ServletRequest`.

  Mapping logic

  - If the platform is running in `VHostMode.IP_BASED`:

    The value of `ServletRequest.getLocalAddr()` is compared against the values returned by `Site.getHost()` and `Site.getHostAliases()` of each site. If a site matches, it is returned.

  - If the platform is running in `VHostMode.NAME_BASED`:

    If the `ServletRequest` contains the `SERVER_LOCAL_NAME` attribute or the header `X_APPNG_SITE`, it is assumed that an upstream reverse-proxy has taken care of site-mapping already and the respective attribute contains a site name (`Nameable.getName()`). If a site with this name exists, it is returned. `Site.getHost()` and `Site.getHostAliases()` are ignored.

    If the mentioned attributes are not present, the value of `ServletRequest.getServerName()` (corresponds to the `HOST` header) is compared against the values returned by `Site.getHost()` and `Site.getHostAliases()` of each site. If a site matches, it is returned.

  Author:
    Matthias Müller, Dirk Heuvels

- - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `getHostIdentifier(javax.servlet.ServletRequest request, Environment env)` Deprecated. use `getRequestIdentifier(Environment, ServletRequest)`
    `static PathInfo` | `getPathInfo(Environment env, Site site, String servletPath)` Creates and returns a `PathInfo`-object based upon the given parameters.
    `static org.appng.api.RequestUtil.RequestIdentifier` | `getRequestIdentifier(Environment env, javax.servlet.ServletRequest request)` Retrieves a name according to the mapping logic described in the class documentation above together with the matching scope to be applied.
    `static Site` | `getSite(Environment env, javax.servlet.ServletRequest servletRequest)` Retrieves a `Site` using the mapping logic described in the class documentation above.
    `static Site` | `getSiteByHost(Environment env, String host)` Retrieves a `Site` by its hostnames (primary and aliases).
    `static Site` | `getSiteByName(Environment env, String name)` Retrieves a `Site` by its name.
    `static String` | `getSiteName(Environment env, javax.servlet.ServletRequest request)` Deprecated. use `getRequestIdentifier(Environment, ServletRequest)`
    `static Set<String>` | `getSiteNames(Environment env)` Returns an immutable `Set` containing all the `Site` names.
    `static Site` | `waitForSite(Environment env, String name)` Retrieves a `Site` by its name, waiting up to `Platform.Property#MAX_WAIT_TIME` milliseconds until it's state is `SiteState#STARTED`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getSite

          public static Site getSite(Environment env,
                                     javax.servlet.ServletRequest servletRequest)

      Retrieves a `Site` using the mapping logic described in the class documentation above.
      Parameters:
        `env` - the current `Environment`
        `servletRequest` - the current `ServletRequest`
      Returns:
        the `Site` or null, if no site matched

    - #### getSiteByHost

          public static Site getSiteByHost(Environment env,
                                           String host)

      Retrieves a `Site` by its hostnames (primary and aliases).
      Parameters:
        `env` - the current `Environment`
        `host` - the name to be compared against the `Site`'s hostnames
      Returns:
        the `Site` or null if no site matches
      See Also:
        `Site.getHost()`, `Site.getHostAliases()`

    - #### getSiteByName

          public static Site getSiteByName(Environment env,
                                           String name)

      Retrieves a `Site` by its name.
      Parameters:
        `env` - the current `Environment`
        `name` - the name of the `Site`
      Returns:
        the `Site`, if any
      See Also:
        `Nameable.getName()`

    - #### waitForSite

          public static Site waitForSite(Environment env,
                                         String name)

      Retrieves a `Site` by its name, waiting up to `Platform.Property#MAX_WAIT_TIME` milliseconds until it's state is `SiteState#STARTED`.
      Parameters:
        `env` - the current `Environment`
        `name` - the name of the `Site`
      Returns:
        the `Site`, if any
      See Also:
        `getSiteByName(Environment, String)`, `Site.hasState(SiteState...)`

    - #### getSiteNames

          public static Set<String> getSiteNames(Environment env)

      Returns an immutable `Set` containing all the `Site` names.
      Parameters:
        `env` - the current `Environment`
      Returns:
        the `Site` names

    - #### getPathInfo

          public static PathInfo getPathInfo(Environment env,
                                             Site site,
                                             String servletPath)

      Creates and returns a `PathInfo`-object based upon the given parameters.
      Parameters:
        `env` - the current `Environment`
        `site` - the current `Site`
        `servletPath` - the current servlet-path
      Returns:
        a `PathInfo`-object

    - #### getHostIdentifier

          @Deprecated
          public static String getHostIdentifier(javax.servlet.ServletRequest request,
                                                             Environment env)

      Deprecated. use `getRequestIdentifier(Environment, ServletRequest)`

    - #### getSiteName

          @Deprecated
          public static String getSiteName(Environment env,
                                                       javax.servlet.ServletRequest request)

      Deprecated. use `getRequestIdentifier(Environment, ServletRequest)`

    - #### getRequestIdentifier

          public static org.appng.api.RequestUtil.RequestIdentifier getRequestIdentifier(Environment env,
                                                                                         javax.servlet.ServletRequest request)

      Retrieves a name according to the mapping logic described in the class documentation above together with the matching scope to be applied.
      Parameters:
        `env` - an `Environment`
        `request` - the `ServletRequest`
      Returns:
        `RequestUtil.RequestIdentifier` object

Copyright © 2011–2023 aiticon GmbH. All rights reserved.