Class AppPathUtils

java.lang.Object
ru.vyarus.dropwizard.guice.url.util.AppPathUtils

public final class AppPathUtils extends Object
Utilities to resolve url-related server configuration (ports, mappings).
Since:
26.09.2025
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    getAdminContextPath(io.dropwizard.core.setup.Environment environment)
    Admin context is configured with server.adminContextPath and it is "/" by default ("/admin" for simple server).
    static int
    getAdminPort(io.dropwizard.core.setup.Environment environment)
    Get admin application context port.
    static String
    getAdminUrl(String host, io.dropwizard.core.setup.Environment environment)
    Get the admin application url.
    static String
    getAppContextPath(io.dropwizard.core.setup.Environment environment)
    Main context is configured with server.applicationContextPath and it is "/" by default.
    static int
    getAppPort(io.dropwizard.core.setup.Environment environment)
    Get main application context port.
    static String
    getAppUrl(String host, io.dropwizard.core.setup.Environment environment)
    Get the main application url.
    static String
    getRestContextPath(io.dropwizard.core.setup.Environment environment)
    Rest context is configured with server.rootPath and it is "/" by default.
    static String
    getRestUrl(String host, io.dropwizard.core.setup.Environment environment)
    Get the rest application url.
    static String
    getRooUrl(String host, io.dropwizard.core.setup.Environment environment)
    Get the root application url (note: it could be different from rest or main context!).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getAppPort

      public static int getAppPort(io.dropwizard.core.setup.Environment environment)
      Get main application context port.
      Parameters:
      environment - environment instance
      Returns:
      the actual port the connector is listening to, or -1 if it has not been opened, or -2 if it has been closed.
    • getAdminPort

      public static int getAdminPort(io.dropwizard.core.setup.Environment environment)
      Get admin application context port.
      Parameters:
      environment - environment instance
      Returns:
      the actual port the connector is listening to, or -1 if it has not been opened, or -2 if it has been closed.
    • getRestContextPath

      public static String getRestContextPath(io.dropwizard.core.setup.Environment environment)
      Rest context is configured with server.rootPath and it is "/" by default. Also, rest is mapped under the main context, so if main context mapping changed with server.applicationContextPath it must also be counted. The returned path counts both and so is relative to the server root.
      Parameters:
      environment - environment instance
      Returns:
      rest context (with a context path), relative to the server root path
    • getAppContextPath

      public static String getAppContextPath(io.dropwizard.core.setup.Environment environment)
      Main context is configured with server.applicationContextPath and it is "/" by default.
      Parameters:
      environment - environment instance
      Returns:
      main context (with a context path), relative to the server root path
    • getAdminContextPath

      public static String getAdminContextPath(io.dropwizard.core.setup.Environment environment)
      Admin context is configured with server.adminContextPath and it is "/" by default ("/admin" for simple server). Note that by default, admin is on different port.
      Parameters:
      environment - environment instance
      Returns:
      main context (with a context path), relative to the server root path
    • getRooUrl

      public static String getRooUrl(String host, io.dropwizard.core.setup.Environment environment)
      Get the root application url (note: it could be different from rest or main context!). Assumed application is accessible by configured url without a proxy. So for default server config, the call getRootUrl("http://myhost.com", environment) will return "http://myhost:8080/".

      If application is behind a proxy, hiding application port and, for example, applying some prefix (e.g., apache redirect "http://myhost.com/my-app" to "http://localhost:8080/"), then this method can't be used - use proxy prefix directly: "http://myhost.com/my-app/".

      Parameters:
      host - base host, including protocol and host name (like http://myhost.com)
      environment - environment instance
      Returns:
      root application url
    • getAppUrl

      public static String getAppUrl(String host, io.dropwizard.core.setup.Environment environment)
      Get the main application url. Assumed application is accessible by configured url without a proxy. So for default server config, the call getMainUrl("http://myhost.com", environment) will return "http://myhost:8080/".

      If application is behind a proxy, hiding application port and, for example, applying some prefix (e.g., apache redirect "http://myhost.com/my-app" to "http://localhost:8080/"), then this method can't be used - use only prefix in this case: "http://myhost.com/my-app" + getMainContextPath(environment).

      Parameters:
      host - base host, including protocol and host name (like http://myhost.com)
      environment - environment instance
      Returns:
      main application url (with a context path)
    • getAdminUrl

      public static String getAdminUrl(String host, io.dropwizard.core.setup.Environment environment)
      Get the admin application url. Assumed application is accessible by configured url without a proxy. So for default server config, the call getAdminUrl("http://myhost.com", environment) will return "http://myhost:8081/" (for simple server: "http://myhost:8080/admin").

      If application is behind a proxy, hiding application port and, for example, applying some prefix (e.g., apache redirect "http://myhost.com/my-app" to "http://localhost:8080/"), then this method can't be used - use only prefix in this case: "http://myhost.com/my-app" + getAdminContextPath(environment).

      Parameters:
      host - base host, including protocol and host name (like http://myhost.com)
      environment - environment instance
      Returns:
      admin application url (with a context path)
    • getRestUrl

      public static String getRestUrl(String host, io.dropwizard.core.setup.Environment environment)
      Get the rest application url. Assumed application is accessible by configured url without a proxy. So for default server config, the call getRestUrl("http://myhost.com", environment) will return "http://myhost:8080/".

      If application is behind a proxy, hiding application port and, for example, applying some prefix (e.g., apache redirect "http://myhost.com/my-app" to "http://localhost:8080/"), then this method can't be used - use only prefix in this case: "http://myhost.com/my-app" + getRestContextPath(environment).

      Parameters:
      host - base host, including protocol and host name (like http://myhost.com)
      environment - environment instance
      Returns:
      rest application url (with a context path)