Package thredds.servlet
Class ServletUtil
java.lang.Object
thredds.servlet.ServletUtil
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformFilename(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 voidforwardToCatalogServices(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Forward this request to the CatalogServices servlet ("/catalog.html").static StringgetParameterIgnoreCase(jakarta.servlet.http.HttpServletRequest req, String paramName) Return the value of the given parameter for the given request.static StringgetReletiveURL(jakarta.servlet.http.HttpServletRequest req) Return the request URL relative to the server (i.e., starting with the context path).static StringgetRequest(jakarta.servlet.http.HttpServletRequest req) The entire request including query stringstatic StringgetRequestBase(jakarta.servlet.http.HttpServletRequest req) This is everything except the query stringstatic StringgetRequestPath(jakarta.servlet.http.HttpServletRequest req) servletPath + pathInfostatic StringgetRequestServer(jakarta.servlet.http.HttpServletRequest req) This is the server part, eg http://motherlode:8080static URIgetRequestURI(jakarta.servlet.http.HttpServletRequest req) The request base as a URIstatic voidreturnFile(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, File file, String contentType) Write a file to the response stream.static voidreturnFile(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 voidreturnFile(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 voidreturnString(String contents, jakarta.servlet.http.HttpServletResponse res) Send given content string as the HTTP response.static intsetResponseContentLength(jakarta.servlet.http.HttpServletResponse response, String s) Set the proper content length for the stringstatic StringshowRequestDetail(jakarta.servlet.http.HttpServletRequest req) Show details about the requeststatic StringshowRequestHeaders(jakarta.servlet.http.HttpServletRequest req) static StringshowSecurity(jakarta.servlet.http.HttpServletRequest req, String role) static voidshowSession(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, PrintStream out) static voidstatic voidstatic voidwriteMFileToResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String requestPath) Write an MFile to the response stream.
-
Field Details
-
logServerStartup
public static final org.slf4j.Logger logServerStartup
-
-
Constructor Details
-
ServletUtil
public ServletUtil()
-
-
Method Details
-
formFilename
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 nullcontentPath- file root pathpath- file path relative to the rootreq- the requestres- the responsecontentType- 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 nullreq- the requestres- the responsefile- to servecontentType- 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- requestres- responsefile- must exist and not be a directorycontentType- 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 HttpServletRequestresponse- the HttpServletResponserequestPath- 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 upons- the string that will be returned- Returns:
- the number of bytes
- Throws:
UnsupportedEncodingException- on bad character encoding
-
getReletiveURL
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- requestres- response- Throws:
IOException- on IO errorjakarta.servlet.ServletException- other error
-
showSystemProperties
-
getRequestServer
This is the server part, eg http://motherlode:8080- Parameters:
req- the HttpServletRequest- Returns:
- request server
-
getRequestBase
This is everything except the query string- Parameters:
req- the HttpServletRequest- Returns:
- parsed request base
-
getRequestURI
The request base as a URI- Parameters:
req- the HttpServletRequest- Returns:
- parsed request as a URI
-
getRequestPath
servletPath + pathInfo- Parameters:
req- the HttpServletRequest- Returns:
- parsed request servletPath + pathInfo
-
getRequest
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 HttpServletRequestparamName- the name of the parameter to find.- Returns:
- the value of the given parameter for the given request.
-
showRequestDetail
Show details about the request- Parameters:
req- the request- Returns:
- string showing the details of the request.
-
showRequestHeaders
-
showSession
public static void showSession(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, PrintStream out) -
showSecurity
-
showThreads
-