public class ServletUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static 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(String fromDir,
String toDir) |
static String |
formFilename(String dirPath,
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 String |
getContentPath()
Return the content path for the given servlet.
|
static String |
getContextPath()
Return the context path for the given servlet.
|
static FileCache |
getFileCache() |
static String |
getFileURL(String filename) |
static String |
getInitialContentPath()
Return the default/initial content path for the given servlet.
|
static String |
getParameterIgnoreCase(javax.servlet.http.HttpServletRequest req,
String paramName)
Return the value of the given parameter for the given request.
|
static String[] |
getParameterValuesIgnoreCase(javax.servlet.http.HttpServletRequest req,
String paramName)
Return the values of the given parameter (ignoring case) for the given request.
|
static String |
getReletiveURL(javax.servlet.http.HttpServletRequest req)
Return the request URL relative to the server (i.e., starting with the context path).
|
static String |
getRequest(javax.servlet.http.HttpServletRequest req)
The entire request including query string
|
static String |
getRequestBase(javax.servlet.http.HttpServletRequest req)
This is everything except the query string
|
static String |
getRequestParsed(javax.servlet.http.HttpServletRequest req)
Show the pieces of the request, for debugging
|
static String |
getRequestPath(javax.servlet.http.HttpServletRequest req)
servletPath + pathInfo
|
static String |
getRequestServer(javax.servlet.http.HttpServletRequest req)
This is the server part, eg http://motherlode:8080
|
static URI |
getRequestURI(javax.servlet.http.HttpServletRequest req)
The request base as a URI
|
static String |
getRootPath()
Return the real path on the servers file system that corresponds to the root document ("/") on the given servlet.
|
static void |
handleException(Throwable t,
javax.servlet.http.HttpServletResponse res)
************************************************************************
Sends an error to the client.
|
static void |
handleRequestForContentFile(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(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(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,
File file,
String contentType)
Write a file to the response stream.
|
static void |
returnFile(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
File file,
String contentType)
Write a file to the response stream.
|
static void |
returnFile(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 void |
returnString(String contents,
javax.servlet.http.HttpServletResponse res)
Send given content string as the HTTP response.
|
static boolean |
saveFile(javax.servlet.http.HttpServlet servlet,
String contentPath,
String path,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res) |
static void |
sendPermanentRedirect(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(String newContentPath) |
static void |
setContextPath(String newContextPath) |
static void |
setFileCache(FileCache fileCache) |
static void |
setRootPath(String newRootPath) |
static String |
showRequestDetail(javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req)
Show details about the request
|
static String |
showRequestHeaders(javax.servlet.http.HttpServletRequest req) |
static String |
showSecurity(javax.servlet.http.HttpServletRequest req,
String role) |
static void |
showServerInfo(PrintStream out) |
static void |
showServletInfo(javax.servlet.http.HttpServlet servlet,
PrintStream out) |
static void |
showSession(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
PrintStream out) |
static void |
showSession(javax.servlet.http.HttpServletRequest req,
PrintStream out) |
static void |
showThreads(PrintStream pw) |
public static final org.slf4j.Logger logServerStartup
public static final 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(String newContextPath)
public static void setRootPath(String newRootPath)
public static void setContentPath(String newContentPath)
public static void initDebugging(javax.servlet.ServletContext webapp)
public static String getRootPath()
public static String getContextPath()
public static String getContentPath()
public static String getInitialContentPath()
public static String formFilename(String dirPath, String filePath)
dirPath - the directory path.filePath - the file path.public static void handleRequestForRawFile(String path, javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException
path - the requested pathservlet - the servlet handling the requestreq - the HttpServletRequestres - the HttpServletResponseIOException - if can't complete request due to IO problems.public static void handleRequestForContentFile(String path, javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException
path - the requested path (must start with "/content/")servlet - the servlet handling the requestreq - the HttpServletRequestres - the HttpServletResponseIOException - if can't complete request due to IO problems.public static void handleRequestForRootFile(String path, javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException
path - the requested path (must start with "/root/")servlet - the servlet handling the requestreq - the HttpServletRequestres - the HttpServletResponseIOException - if can't complete request due to IO problems.public static void sendPermanentRedirect(String targetPath, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException
targetPath - the path to which the client is redirected.req - the HttpServletRequestres - the HttpServletResponseIOException - if can't write the response.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 IOException
servlet - called from herecontentPath - file root pathpath - file path reletive to the rootreq - the requestres - the responsecontentType - content type, or nullIOException - on write errorpublic static void setFileCache(FileCache fileCache)
public static FileCache getFileCache()
public static void returnFile(javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
File file,
String contentType)
throws IOException
servlet - called from herereq - the requestres - the responsefile - to servecontentType - content type, if null, will try to guessIOException - on write errorpublic static void returnFile(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
File file,
String contentType)
throws IOException
req - requestres - responsefile - must exist and not be a directorycontentType - must not be nullIOException - or errorpublic static void returnString(String contents, javax.servlet.http.HttpServletResponse res) throws IOException
contents - the string to return as the HTTP response.res - the HttpServletResponseIOException - if an I/O error occurs while writing the response.public static String getReletiveURL(javax.servlet.http.HttpServletRequest req)
req - requestpublic static void forwardToCatalogServices(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
throws IOException,
javax.servlet.ServletException
req - requestres - responseIOException - on IO errorjavax.servlet.ServletException - other errorpublic static boolean saveFile(javax.servlet.http.HttpServlet servlet,
String contentPath,
String path,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
public static boolean copyDir(String fromDir, String toDir) throws IOException
IOExceptionpublic static void handleException(Throwable t, javax.servlet.http.HttpServletResponse res)
t - The exception that caused the problem.res - The HttpServletResponse for the client.public static void showServerInfo(PrintStream out)
public static void showServletInfo(javax.servlet.http.HttpServlet servlet,
PrintStream out)
public static String getRequestParsed(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static String getRequestServer(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static String getRequestBase(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static URI getRequestURI(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static String getRequestPath(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static String getRequest(javax.servlet.http.HttpServletRequest req)
req - the HttpServletRequestpublic static String getParameterIgnoreCase(javax.servlet.http.HttpServletRequest req, String paramName)
req - the HttpServletRequestparamName - the name of the parameter to find.public static String[] getParameterValuesIgnoreCase(javax.servlet.http.HttpServletRequest req, String paramName)
req - the HttpServletRequestparamName - the name of the parameter to find.public static 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 String showRequestHeaders(javax.servlet.http.HttpServletRequest req)
public static void showSession(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
PrintStream out)
public static void showSession(javax.servlet.http.HttpServletRequest req,
PrintStream out)
public static String showSecurity(javax.servlet.http.HttpServletRequest req, String role)
public static void showThreads(PrintStream pw)
Copyright © 1999-2013 UCAR/Unidata. All Rights Reserved.