Package com.iizix.jetty
Class WSHelper
java.lang.Object
com.iizix.jetty.WSHelper
Helper class for common functions for Jetty.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic StringgetDomain(HttpServletRequest request, int check, String originator) Helper to get the domain name from a servlet request and to optionally check if there is a matching "host" header for it.static StringExtracts the domain name from an HttpServletRequest from the "host" header field (removing the port specification - keeping in mind that it could be an IPv6 address).static StringgetDomainFromURL(HttpServletRequest request) Extracts the domain name from an HttpServletRequest from the URL.static StringgetExternalBaseServerURL(String extServerURL, String bind, int port, int securePort, boolean hasExtSSL) Returns the external base server URL with protocol, host name and potentially port number.static StringvalidateExternalHostName(String urlString) Validates an external host URL.
Constructor Details
WSHelper
public WSHelper()
Method Details
getExternalBaseServerURL
public static String getExternalBaseServerURL(String extServerURL, String bind, int port, int securePort, boolean hasExtSSL) Returns the external base server URL with protocol, host name and potentially port number.The name will be taken from:
- external host name if specified,
- resolved bind address if specified and possible to retrieve,
- bind address if specified,
- resolved local host name if possible to retrieve,
- local host name if possible to retrieve,
- "localhost" last.
If "localhost" is used, a warning message is logged about it.
The protocol to use will be secure HTTPS if possible, otherwise the HTTP, even if it is zero for none.
- Parameters:
extServerURL- The external server URL, null or empty for none.bind- Bind address specified, null or empty for none.port- HTTP port number, zero for none.securePort- HTTPS port number, zero for none.hasExtSSL- HTTP port is externally secured.
validateExternalHostName
Validates an external host URL.- Parameters:
urlString- The external host URL to validate, null or empty for none.- Returns:
- null if valid or none is specified, otherwise an error reason.
getDomain
Helper to get the domain name from a servlet request and to optionally check if there is a matching "host" header for it. In case there is no matching "host" header, logging can be performed.- Parameters:
request- The servlet request.check- How to perform the check:
0 = no warnings, no logging, just return it,
1 = warning if "host" doesn't match, but return it,
2 = error if "host" doesn't match, and return null.originator- String to mark as originator when logging error.- Returns:
- The domain name or "host" header field, null if this fails.
getDomainFromURL
Extracts the domain name from an HttpServletRequest from the URL.- Parameters:
request- The HttpServletRequest request.- Returns:
- The domain name, or "unknown" if the request URL/URI is formatted incorrectly.
getDomainFromHostHeader
Extracts the domain name from an HttpServletRequest from the "host" header field (removing the port specification - keeping in mind that it could be an IPv6 address).If the header field 'host' is missing, the return value will be set to
request.getServerName().- Parameters:
request- The HttpServletRequest request.- Returns:
- The domain name, or
nullfor missing "host" header field and failure to get it usingrequest.getServerName().