Package thredds.servlet
Class ServletUtil
- java.lang.Object
-
- thredds.servlet.ServletUtil
-
public class ServletUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.LoggerlogServerStartup
-
Constructor Summary
Constructors Constructor Description ServletUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)Forward this request to the CatalogServices servlet ("/catalog.html").static StringgetParameterIgnoreCase(javax.servlet.http.HttpServletRequest req, String paramName)Return the value of the given parameter for the given request.static StringgetReletiveURL(javax.servlet.http.HttpServletRequest req)Return the request URL relative to the server (i.e., starting with the context path).static StringgetRequest(javax.servlet.http.HttpServletRequest req)The entire request including query stringstatic StringgetRequestBase(javax.servlet.http.HttpServletRequest req)This is everything except the query stringstatic StringgetRequestPath(javax.servlet.http.HttpServletRequest req)servletPath + pathInfostatic StringgetRequestServer(javax.servlet.http.HttpServletRequest req)This is the server part, eg http://motherlode:8080static URIgetRequestURI(javax.servlet.http.HttpServletRequest req)The request base as a URIstatic voidreturnFile(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, File file, String contentType)Write a file to the response stream.static voidreturnFile(javax.servlet.http.HttpServlet servlet, String contentPath, String path, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String contentType)Write a file to the response stream.static voidreturnFile(javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, File file, String contentType)Write a file to the response stream.static voidreturnString(String contents, javax.servlet.http.HttpServletResponse res)Send given content string as the HTTP response.static intsetResponseContentLength(javax.servlet.http.HttpServletResponse response, String s)Set the proper content length for the stringstatic StringshowRequestDetail(javax.servlet.http.HttpServletRequest req)Show details about the requeststatic StringshowRequestHeaders(javax.servlet.http.HttpServletRequest req)static StringshowSecurity(javax.servlet.http.HttpServletRequest req, String role)static voidshowSession(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, PrintStream out)static voidshowSystemProperties(PrintStream out)static voidshowThreads(PrintStream pw)static voidwriteMFileToResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String requestPath)Write an MFile to the response stream.
-
-
-
Method Detail
-
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(javax.servlet.http.HttpServlet servlet, String contentPath, String path, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String contentType) throws IOExceptionWrite 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(javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, File file, String contentType) throws IOExceptionWrite 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(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, File file, String contentType) throws IOExceptionWrite 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(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String requestPath) throws IOExceptionWrite 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, javax.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(javax.servlet.http.HttpServletResponse response, String s) throws UnsupportedEncodingExceptionSet 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
public static String getReletiveURL(javax.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(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException, javax.servlet.ServletExceptionForward this request to the CatalogServices servlet ("/catalog.html").- Parameters:
req- requestres- response- Throws:
IOException- on IO errorjavax.servlet.ServletException- other error
-
showSystemProperties
public static void showSystemProperties(PrintStream out)
-
getRequestServer
public static String getRequestServer(javax.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(javax.servlet.http.HttpServletRequest req)
This is everything except the query string- Parameters:
req- the HttpServletRequest- Returns:
- parsed request base
-
getRequestURI
public static URI getRequestURI(javax.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(javax.servlet.http.HttpServletRequest req)
servletPath + pathInfo- Parameters:
req- the HttpServletRequest- Returns:
- parsed request servletPath + pathInfo
-
getRequest
public static String getRequest(javax.servlet.http.HttpServletRequest req)
The entire request including query string- Parameters:
req- the HttpServletRequest- Returns:
- entire parsed request
-
getParameterIgnoreCase
public static String getParameterIgnoreCase(javax.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
public static String showRequestDetail(javax.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(javax.servlet.http.HttpServletRequest req)
-
showSession
public static void showSession(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, PrintStream out)
-
showSecurity
public static String showSecurity(javax.servlet.http.HttpServletRequest req, String role)
-
showThreads
public static void showThreads(PrintStream pw)
-
-