Class AppPathUtils
- Since:
- 26.09.2025
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetAdminContextPath(io.dropwizard.core.setup.Environment environment) Admin context is configured withserver.adminContextPathand it is "/" by default ("/admin" for simple server).static intgetAdminPort(io.dropwizard.core.setup.Environment environment) Get admin application context port.static StringgetAdminUrl(String host, io.dropwizard.core.setup.Environment environment) Get the admin application url.static StringgetAppContextPath(io.dropwizard.core.setup.Environment environment) Main context is configured withserver.applicationContextPathand it is "/" by default.static intgetAppPort(io.dropwizard.core.setup.Environment environment) Get main application context port.static StringGet the main application url.static StringgetRestContextPath(io.dropwizard.core.setup.Environment environment) Rest context is configured withserver.rootPathand it is "/" by default.static StringgetRestUrl(String host, io.dropwizard.core.setup.Environment environment) Get the rest application url.static StringGet the root application url (note: it could be different from rest or main context!).
-
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
Rest context is configured withserver.rootPathand it is "/" by default. Also, rest is mapped under the main context, so if main context mapping changed withserver.applicationContextPathit 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
Main context is configured withserver.applicationContextPathand it is "/" by default.- Parameters:
environment- environment instance- Returns:
- main context (with a context path), relative to the server root path
-
getAdminContextPath
Admin context is configured withserver.adminContextPathand 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
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 callgetRootUrl("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
Get the main application url. Assumed application is accessible by configured url without a proxy. So for default server config, the callgetMainUrl("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
Get the admin application url. Assumed application is accessible by configured url without a proxy. So for default server config, the callgetAdminUrl("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
Get the rest application url. Assumed application is accessible by configured url without a proxy. So for default server config, the callgetRestUrl("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)
-