Class WSHelper

java.lang.Object
com.iizix.jetty.WSHelper

public class WSHelper extends Object
Helper class for common functions for Jetty.
Author:
Christopher Mindus
  • Field Details

    • MIN_GZIP_SIZE

      public static int MIN_GZIP_SIZE
      The 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

    • 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:

      1. external host name if specified,
      2. resolved bind address if specified and possible to retrieve,
      3. bind address if specified,
      4. resolved local host name if possible to retrieve,
      5. local host name if possible to retrieve,
      6. "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

      public static String validateExternalHostName(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 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. 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 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 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 using request.getServerName().