Package com.iizix.jetty
Class WSHelper
java.lang.Object
com.iizix.jetty.WSHelper
Helper class for common functions for Jetty.
- Author:
- Christopher Mindus
- Field SummaryFieldsModifier and TypeFieldDescription- static intThe minimum size for data before it is GZip deflate enabled: 128 bytes.
- Constructor SummaryConstructors
- Method SummaryModifier and TypeMethodDescription- static String- getDomain- (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 String- getDomainFromURL- (HttpServletRequest request) Extracts the domain name from an HttpServletRequest from the URL.- 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.- static String- validateExternalHostName- (String urlString) Validates an external host URL.
- Field Details- MIN_GZIP_SIZEpublic static int MIN_GZIP_SIZEThe minimum size for data before it is GZip deflate enabled: 128 bytes.- FYI: the break-even size is 23, and a common minimum is 32. 
 
- Constructor Details- WSHelperpublic WSHelper()
 
- Method Details- getExternalBaseServerURLpublic 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.
 
- validateExternalHostNameValidates 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.
 
- getDomainHelper 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.
 
- getDomainFromURLExtracts 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.
 
- getDomainFromHostHeaderExtracts 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().