public class ServletUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CONTENT_TEXT |
static org.slf4j.Logger |
logServerStartup |
static int |
STATUS_CLIENT_ABORT |
static int |
STATUS_FORWARD_FAILURE |
static int |
STATUS_FORWARDED |
| Constructor and Description |
|---|
ServletUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
copyDir(java.lang.String fromDir,
java.lang.String toDir) |
static java.lang.String |
formFilename(java.lang.String dirPath,
java.lang.String filePath)
Return the file path dealing with leading and trailing path
seperators (which must be a slash ("/")) for the given directory
and file paths.
|
static void |
forwardToCatalogServices(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Forward this request to the CatalogServices servlet ("/catalog.html").
|
static java.lang.String |
getContentPath()
Return the content path for the given servlet.
|
static java.lang.String |
getContextPath()
Return the context path for the given servlet.
|
static java.lang.String |
getFileURL(java.lang.String filename) |
static java.lang.String |
getInitialContentPath()
Return the default/initial content path for the given servlet.
|
static java.lang.String |
getParameterIgnoreCase(javax.servlet.http.HttpServletRequest req,
java.lang.String paramName)
Return the value of the given parameter for the given request.
|
static java.lang.String[] |
getParameterValuesIgnoreCase(javax.servlet.http.HttpServletRequest req,
java.lang.String paramName)
Return the values of the given parameter (ignoring case) for the given request.
|
static java.lang.String |
getReletiveURL(javax.servlet.http.HttpServletRequest req)
Return the request URL relative to the server (i.e., starting with the context path).
|
static java.lang.String |
getRequest(javax.servlet.http.HttpServletRequest req)
The entire request including query string
|
static java.lang.String |
getRequestBase(javax.servlet.http.HttpServletRequest req)
This is everything except the query string
|
static java.lang.String |
getRequestParsed(javax.servlet.http.HttpServletRequest req)
Show the pieces of the request, for debugging
|
static java.lang.String |
getRequestPath(javax.servlet.http.HttpServletRequest req)
servletPath + pathInfo
|
static java.lang.String |
getRequestServer(javax.servlet.http.HttpServletRequest req)
This is the server part, eg http://motherlode:8080
|
static java.net.URI |
getRequestURI(javax.servlet.http.HttpServletRequest req)
The request base as a URI
|
static java.lang.String |
getRootPath()
Return the real path on the servers file system that corresponds to the root document ("/") on the given servlet.
|
static void |
handleException(java.lang.Throwable t,
javax.servlet.http.HttpServletResponse res)
************************************************************************
Sends an error to the client.
|
static void |
handleRequestForContentFile(java.lang.String path,
javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Handle an explicit request for a content directory file (path must start
with "/content/".
|
static void |
handleRequestForRawFile(java.lang.String path,
javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Handle a request for a raw/static file (i.e., not a catalog or dataset request).
|
static void |
handleRequestForRootFile(java.lang.String path,
javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Handle an explicit request for a root directory file (path must start
with "/root/".
|
static void |
initContext(javax.servlet.ServletContext context)
Deprecated.
Now handled in TdsContext.init().
|
static void |
initDebugging(javax.servlet.ServletContext webapp) |
static void |
returnFile(javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.io.File file,
java.lang.String contentType)
Write a file to the response stream.
|
static void |
returnFile(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.io.File file,
java.lang.String contentType)
Write a file to the response stream.
|
static void |
returnFile(javax.servlet.http.HttpServlet servlet,
java.lang.String contentPath,
java.lang.String path,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String contentType)
Write a file to the response stream.
|
static void |
returnString(java.lang.String contents,
javax.servlet.http.HttpServletResponse res)
Send given content string as the HTTP response.
|
static boolean |
saveFile(javax.servlet.http.HttpServlet servlet,
java.lang.String contentPath,
java.lang.String path,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res) |
static void |
sendPermanentRedirect(java.lang.String targetPath,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Send a permanent redirect (HTTP status 301 "Moved Permanently") response
with the given target path.
|
static void |
setContentPath(java.lang.String newContentPath) |
static void |
setContextPath(java.lang.String newContextPath) |
static int |
setResponseContentLength(javax.servlet.http.HttpServletResponse response,
java.lang.String s)
Set the proper content length for the string
|
static void |
setRootPath(java.lang.String newRootPath) |
static java.lang.String |
showRequestDetail(javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req)
Show details about the request
|
static java.lang.String |
showRequestHeaders(javax.servlet.http.HttpServletRequest req) |
static java.lang.String |
showSecurity(javax.servlet.http.HttpServletRequest req,
java.lang.String role) |
static void |
showServerInfo(java.io.PrintStream out) |
static void |
showServletInfo(javax.servlet.http.HttpServlet servlet,
java.io.PrintStream out) |
static void |
showSession(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.io.PrintStream out) |
static void |
showSession(javax.servlet.http.HttpServletRequest req,
java.io.PrintStream out) |
static void |
showThreads(java.io.PrintStream pw) |
public static final org.slf4j.Logger logServerStartup
public static final java.lang.String CONTENT_TEXT
public static final int STATUS_CLIENT_ABORT
public static final int STATUS_FORWARDED
public static final int STATUS_FORWARD_FAILURE
public static void initContext(javax.servlet.ServletContext context)
context - the Servlet context.public static void setContextPath(java.lang.String newContextPath)
public static void setRootPath(java.lang.String newRootPath)
public static void setContentPath(java.lang.String newContentPath)
public static void initDebugging(javax.servlet.ServletContext webapp)
public static java.lang.String getRootPath()
public static java.lang.String getContextPath()
public static java.lang.String getContentPath()
public static java.lang.String getInitialContentPath()
public static java.lang.String formFilename(java.lang.String dirPath,
java.lang.String filePath)
dirPath - the directory path.filePath - the file path.public static void handleRequestForRawFile(java.lang.String path,
javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
throws java.io.IOException
path - the requested pathservlet - the servlet handling the requestreq - the HttpServletRequestres - the HttpServletResponsejava.io.IOException - if can't complete request due to IO problems.public static void handleRequestForContentFile(java.lang.String path,
javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
throws java.io.IOException
path - the requested path (must start with "/content/")servlet - the servlet handling the requestreq - the HttpServletRequestres - the HttpServletResponsejava.io.IOException - if can't complete request due to IO problems.public static void handleRequestForRootFile(java.lang.String path,
javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
throws java.io.IOException
path - the requested path (must start with "/root/")servlet - the servlet handling the requestreq - the HttpServletRequestres - the HttpServletResponsejava.io.IOException - if can't complete request due to IO problems.public static void sendPermanentRedirect(java.lang.String targetPath,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
throws java.io.IOException
targetPath - the path to which the client is redirected.req - the HttpServletRequestres - the HttpServletResponsejava.io.IOException - if can't write the response.public static void returnFile(javax.servlet.http.HttpServlet servlet,
java.lang.String contentPath,
java.lang.String path,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String contentType)
throws java.io.IOException
servlet - called from this servlet, may be nullcontentPath - file root pathpath - file path reletive to the rootreq - the requestres - the responsecontentType - content type, or nulljava.io.IOException - on write errorpublic static void returnFile(javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.io.File file,
java.lang.String contentType)
throws java.io.IOException
servlet - called from this servlet, may be nullreq - the requestres - the responsefile - to servecontentType - content type, if null, will try to guessjava.io.IOException - on write errorpublic static void returnFile(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.io.File file,
java.lang.String contentType)
throws java.io.IOException
req - requestres - responsefile - must exist and not be a directorycontentType - must not be nulljava.io.IOException - or errorpublic static void returnString(java.lang.String contents,
javax.servlet.http.HttpServletResponse res)
throws java.io.IOException
contents - the string to return as the HTTP response.res - the HttpServletResponsejava.io.IOException - if an I/O error occurs while writing the response.public static int setResponseContentLength(javax.servlet.http.HttpServletResponse response,
java.lang.String s)
throws java.io.UnsupportedEncodingException
response - the HttpServletResponse to act upons - the string that will be returnedjava.io.UnsupportedEncodingException - on bad character encodingpublic static java.lang.String getReletiveURL(javax.servlet.http.HttpServletRequest req)
req - requestpublic static void forwardToCatalogServices(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
throws java.io.IOException,
javax.servlet.ServletException
req - requestres - responsejava.io.IOException - on IO errorjavax.servlet.ServletException - other errorpublic static boolean saveFile(javax.servlet.http.HttpServlet servlet,
java.lang.String contentPath,
java.lang.String path,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
public static boolean copyDir(java.lang.String fromDir,
java.lang.String toDir)
throws java.io.IOException
java.io.IOExceptionpublic static void handleException(java.lang.Throwable t,
javax.servlet.http.HttpServletResponse res)
t - The exception that caused the problem.res - The HttpServletResponse for the client.public static void showServerInfo(java.io.PrintStream out)
public static void showServletInfo(javax.servlet.http.HttpServlet servlet,
java.io.PrintStream out)
public static java.lang.String getRequestParsed(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static java.lang.String getRequestServer(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static java.lang.String getRequestBase(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static java.net.URI getRequestURI(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static java.lang.String getRequestPath(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static java.lang.String getRequest(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static java.lang.String getParameterIgnoreCase(javax.servlet.http.HttpServletRequest req,
java.lang.String paramName)
req - the HttpServletRequestparamName - the name of the parameter to find.public static java.lang.String[] getParameterValuesIgnoreCase(javax.servlet.http.HttpServletRequest req,
java.lang.String paramName)
req - the HttpServletRequestparamName - the name of the parameter to find.public static java.lang.String getFileURL(java.lang.String filename)
public static java.lang.String showRequestDetail(javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req)
servlet - used to get teh servlet context, may be nullreq - the requestpublic static java.lang.String showRequestHeaders(javax.servlet.http.HttpServletRequest req)
public static void showSession(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.io.PrintStream out)
public static void showSession(javax.servlet.http.HttpServletRequest req,
java.io.PrintStream out)
public static java.lang.String showSecurity(javax.servlet.http.HttpServletRequest req,
java.lang.String role)
public static void showThreads(java.io.PrintStream pw)