Package com.iizix.jetty
Class WSHelper
- java.lang.Object
- com.iizix.jetty.WSHelper
public class WSHelper extends java.lang.Object
Helper class for common functions for Jetty.- Author:
- Christopher Mindus
Field Summary
Fields Modifier and Type Field Description static int
MIN_GZIP_SIZE
The minimum size for data before it is GZip deflate enabled: 128 bytes.
Constructor Summary
Constructors Constructor Description WSHelper()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
getDomain(HttpServletRequest request, int check, java.lang.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 java.lang.String
getDomainFromHostHeader(HttpServletRequest request)
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).static java.lang.String
getDomainFromURL(HttpServletRequest request)
Extracts the domain name from an HttpServletRequest from the URL.static java.lang.String
getExternalBaseServerURL(java.lang.String extServerURL, java.lang.String bind, int port, int securePort)
Returns the external base server URL with protocol, host name and potentially port number.static java.lang.String
validateExternalHostName(java.lang.String urlString)
Validates an external host URL.
Method Detail
getExternalBaseServerURL
public static java.lang.String getExternalBaseServerURL(java.lang.String extServerURL, java.lang.String bind, int port, int securePort)
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.
validateExternalHostName
public static java.lang.String validateExternalHostName(java.lang.String urlString)
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
public static java.lang.String getDomain(HttpServletRequest request, int check, java.lang.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. 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
public static java.lang.String getDomainFromURL(HttpServletRequest request)
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
public static java.lang.String getDomainFromHostHeader(HttpServletRequest request)
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
null
for missing "host" header field and failure to get it usingrequest.getServerName()
.