Package com.mastfrog.acteur.server
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_PATHServerModule.SETTINGS_KEY_URLS_HOST_NAMEServerModule.SETTINGS_KEY_URLS_EXTERNAL_PORTServerModule.SETTINGS_KEY_URLS_EXTERNAL_SECURE_PORTServerModule.SETTINGS_KEY_GENERATE_SECURE_URLSServerModule.SETTINGS_KEY_GENERATE_URLS_WITH_INET_ADDRESS_GET_LOCALHOST
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.use @link{ServerModule.SETTINGS_KEY_BASE_PATH}static final StringDeprecated.use @link{ServerModule.SETTINGS_KEY_URLS_EXTERNAL_PORT}static final StringDeprecated.usestatic final StringDeprecated.use @link{ServerModule.SETTINGS_KEY_URLS_HOST_NAME}static final StringDeprecated.use @link{ServerModule.SETTINGS_KEY_GENERATE_SECURE_URLS} -
Method Summary
Modifier and TypeMethodDescriptiondefault URIconstructURI(String path) default URIconstructURI(String path, HttpEvent evt) constructURL(Path path) Generate a URL to this application, using the path and the system default for whether to use http or https.constructURL(Path path, boolean secure) Construct a URL suitable for external use, inserting the basepath and host name if necessary.constructURL(Protocol protocol, Path path) Construct a URL suitable for external use, inserting the basepath and host name if necessary.constructURL(Protocol protocol, Path path, boolean secure) constructURL(Protocol protocol, Path path, int port) default URLconstructURL(String path) Generate a URL to this application, using the path and the system default for whether to use http or https.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.intportForProtocol(Protocol protocol) toExternalPath(Path path) Prepend the base path if necessarytoExternalPath(String path) Prepend the base path if necessaryConvert a URI from a request to a path, stripping out the basepath if any.
-
Field Details
-
BASE_PATH_SETTINGS_KEY
Deprecated.use @link{ServerModule.SETTINGS_KEY_BASE_PATH}The string "basepath" as a settings key / @Named string- See Also:
-
HOSTNAME_SETTINGS_KEY
Deprecated.use @link{ServerModule.SETTINGS_KEY_URLS_HOST_NAME}- See Also:
-
EXTERNAL_PORT
Deprecated.use @link{ServerModule.SETTINGS_KEY_URLS_EXTERNAL_PORT}- See Also:
-
EXTERNAL_SECURE_PORT
Deprecated.use- See Also:
-
SETTINGS_KEY_DEFAULT_SECURE_URLS
Deprecated.use @link{ServerModule.SETTINGS_KEY_GENERATE_SECURE_URLS}- See Also:
-
-
Method Details
-
toPath
Convert a URI from a request to a path, stripping out the basepath if any.- Parameters:
uri- A URI- Returns:
- A path
-
constructURL
Construct a URL suitable for external use, inserting the basepath and host name if necessary.- Parameters:
path- The path relative to the web applicationsecure- Whether or not to construct an https URL- Returns:
- A url
-
constructURL
Construct a URL suitable for external use, inserting the basepath and host name if necessary.- Parameters:
protocol- The protocol for the new urlpath- The path relative to the web application- Returns:
- A url
-
constructURL
-
constructURL
-
toExternalPath
Prepend the base path if necessary- Parameters:
path- A path- Returns:
- a path
-
toExternalPath
Prepend the base path if necessary- Parameters:
path- A path- Returns:
- a path
-
constructURL
Generate a URL to this application, using the path and the system default for whether to use http or https.- Parameters:
path-- Returns:
-
portForProtocol
-
constructURL
Generate a URL to this application, using the path and the system default for whether to use http or https.- Parameters:
path-- Returns:
-
constructURL
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¶m2=y
- The same query item does not repeat
add(Headers.LOCATION.stringHeader(), "http://weird.url?foo&foo&foo&bar=");)- Parameters:
path- A url pathevt- 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
-
constructURI
-