Class ServletUtil

java.lang.Object
thredds.servlet.ServletUtil

public class ServletUtil extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    formFilename(String dirPath, String filePath)
    Return the file path dealing with leading and trailing path separators (which must be a slash ("/")) for the given directory and file paths.
    static void
    forwardToCatalogServices(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res)
    Forward this request to the CatalogServices servlet ("/catalog.html").
    static String
    getParameterIgnoreCase(jakarta.servlet.http.HttpServletRequest req, String paramName)
    Return the value of the given parameter for the given request.
    static String
    getReletiveURL(jakarta.servlet.http.HttpServletRequest req)
    Return the request URL relative to the server (i.e., starting with the context path).
    static String
    getRequest(jakarta.servlet.http.HttpServletRequest req)
    The entire request including query string
    static String
    getRequestBase(jakarta.servlet.http.HttpServletRequest req)
    This is everything except the query string
    static String
    getRequestPath(jakarta.servlet.http.HttpServletRequest req)
    servletPath + pathInfo
    static String
    getRequestServer(jakarta.servlet.http.HttpServletRequest req)
    This is the server part, eg http://motherlode:8080
    static URI
    getRequestURI(jakarta.servlet.http.HttpServletRequest req)
    The request base as a URI
    static void
    returnFile(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, File file, String contentType)
    Write a file to the response stream.
    static void
    returnFile(jakarta.servlet.http.HttpServlet servlet, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, File file, String contentType)
    Write a file to the response stream.
    static void
    returnFile(jakarta.servlet.http.HttpServlet servlet, String contentPath, String path, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String contentType)
    Write a file to the response stream.
    static void
    returnString(String contents, jakarta.servlet.http.HttpServletResponse res)
    Send given content string as the HTTP response.
    static int
    setResponseContentLength(jakarta.servlet.http.HttpServletResponse response, String s)
    Set the proper content length for the string
    static String
    showRequestDetail(jakarta.servlet.http.HttpServletRequest req)
    Show details about the request
    static String
    showRequestHeaders(jakarta.servlet.http.HttpServletRequest req)
     
    static String
    showSecurity(jakarta.servlet.http.HttpServletRequest req, String role)
     
    static void
    showSession(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, PrintStream out)
     
    static void
     
    static void
     
    static void
    writeMFileToResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String requestPath)
    Write an MFile to the response stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logServerStartup

      public static final org.slf4j.Logger logServerStartup
  • Constructor Details

    • ServletUtil

      public ServletUtil()
  • Method Details

    • formFilename

      public static String formFilename(String dirPath, String filePath)
      Return the file path dealing with leading and trailing path separators (which must be a slash ("/")) for the given directory and file paths.

      Note: Dealing with path strings is fragile. ToDo: Switch from using path strings to java.io.Files.

      Parameters:
      dirPath - the directory path.
      filePath - the file path.
      Returns:
      a full file path with the given directory and file paths.
    • returnFile

      public static void returnFile(jakarta.servlet.http.HttpServlet servlet, String contentPath, String path, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String contentType) throws IOException
      Write a file to the response stream.
      Parameters:
      servlet - called from this servlet, may be null
      contentPath - file root path
      path - file path relative to the root
      req - the request
      res - the response
      contentType - content type, or null
      Throws:
      IOException - on write error
    • returnFile

      public static void returnFile(jakarta.servlet.http.HttpServlet servlet, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, File file, String contentType) throws IOException
      Write a file to the response stream. Handles Range requests.
      Parameters:
      servlet - called from this servlet, may be null
      req - the request
      res - the response
      file - to serve
      contentType - content type, if null, will try to guess
      Throws:
      IOException - on write error
    • returnFile

      public static void returnFile(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, File file, String contentType) throws IOException
      Write a file to the response stream. Handles Range requests.
      Parameters:
      req - request
      res - response
      file - must exist and not be a directory
      contentType - must not be null
      Throws:
      IOException - or error
    • writeMFileToResponse

      public static void writeMFileToResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String requestPath) throws IOException
      Write an MFile to the response stream.
      Parameters:
      request - the HttpServletRequest
      response - the HttpServletResponse
      requestPath - the request path
      Throws:
      IOException - if an I/O error occurs while writing the response.
    • returnString

      public static void returnString(String contents, jakarta.servlet.http.HttpServletResponse res) throws IOException
      Send given content string as the HTTP response.
      Parameters:
      contents - the string to return as the HTTP response.
      res - the HttpServletResponse
      Throws:
      IOException - if an I/O error occurs while writing the response.
    • setResponseContentLength

      public static int setResponseContentLength(jakarta.servlet.http.HttpServletResponse response, String s) throws UnsupportedEncodingException
      Set the proper content length for the string
      Parameters:
      response - the HttpServletResponse to act upon
      s - the string that will be returned
      Returns:
      the number of bytes
      Throws:
      UnsupportedEncodingException - on bad character encoding
    • getReletiveURL

      public static String getReletiveURL(jakarta.servlet.http.HttpServletRequest req)
      Return the request URL relative to the server (i.e., starting with the context path).
      Parameters:
      req - request
      Returns:
      URL relative to the server
    • forwardToCatalogServices

      public static void forwardToCatalogServices(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException, jakarta.servlet.ServletException
      Forward this request to the CatalogServices servlet ("/catalog.html").
      Parameters:
      req - request
      res - response
      Throws:
      IOException - on IO error
      jakarta.servlet.ServletException - other error
    • showSystemProperties

      public static void showSystemProperties(PrintStream out)
    • getRequestServer

      public static String getRequestServer(jakarta.servlet.http.HttpServletRequest req)
      This is the server part, eg http://motherlode:8080
      Parameters:
      req - the HttpServletRequest
      Returns:
      request server
    • getRequestBase

      public static String getRequestBase(jakarta.servlet.http.HttpServletRequest req)
      This is everything except the query string
      Parameters:
      req - the HttpServletRequest
      Returns:
      parsed request base
    • getRequestURI

      public static URI getRequestURI(jakarta.servlet.http.HttpServletRequest req)
      The request base as a URI
      Parameters:
      req - the HttpServletRequest
      Returns:
      parsed request as a URI
    • getRequestPath

      public static String getRequestPath(jakarta.servlet.http.HttpServletRequest req)
      servletPath + pathInfo
      Parameters:
      req - the HttpServletRequest
      Returns:
      parsed request servletPath + pathInfo
    • getRequest

      public static String getRequest(jakarta.servlet.http.HttpServletRequest req)
      The entire request including query string
      Parameters:
      req - the HttpServletRequest
      Returns:
      entire parsed request
    • getParameterIgnoreCase

      public static String getParameterIgnoreCase(jakarta.servlet.http.HttpServletRequest req, String paramName)
      Return the value of the given parameter for the given request. Should only be used if the parameter is known to only have one value. If used on a multi-valued parameter, the first value is returned.
      Parameters:
      req - the HttpServletRequest
      paramName - the name of the parameter to find.
      Returns:
      the value of the given parameter for the given request.
    • showRequestDetail

      public static String showRequestDetail(jakarta.servlet.http.HttpServletRequest req)
      Show details about the request
      Parameters:
      req - the request
      Returns:
      string showing the details of the request.
    • showRequestHeaders

      public static String showRequestHeaders(jakarta.servlet.http.HttpServletRequest req)
    • showSession

      public static void showSession(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, PrintStream out)
    • showSecurity

      public static String showSecurity(jakarta.servlet.http.HttpServletRequest req, String role)
    • showThreads

      public static void showThreads(PrintStream pw)