Package org.bedework.util.servlet
Class MethodBase
- java.lang.Object
-
- org.bedework.util.servlet.MethodBase
-
- All Implemented Interfaces:
org.bedework.util.logging.Logged
public abstract class MethodBase extends Object implements org.bedework.util.logging.Logged
Base class for servlet methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMethodBase.MethodInfoAllow servlet to create method.
-
Field Summary
Fields Modifier and Type Field Description protected booleandumpContent
-
Constructor Summary
Constructors Constructor Description MethodBase()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddHeaders(javax.servlet.http.HttpServletResponse resp)abstract voiddoMethod(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)static List<String>fixPath(String path)Return a path, broken into its elements, after "." and ".." are removed.protected StringformatHTTPDate(Timestamp val)abstract com.fasterxml.jackson.databind.ObjectMappergetMapper()List<String>getResourceUri(javax.servlet.http.HttpServletRequest req)Get the decoded and fixed resource URI.protected StringhrefFromPath(List<String> path, int start)abstract voidinit()Called at each requestprotected ObjectreadJson(InputStream is, com.fasterxml.jackson.core.type.TypeReference tr, javax.servlet.http.HttpServletResponse resp)Parse the request body, and return the object.protected ObjectreadJson(InputStream is, Class cl, javax.servlet.http.HttpServletResponse resp)Parse the request body, and return the object.protected voidsendJsonError(javax.servlet.http.HttpServletResponse resp, String msg)protected voidsendOkJsonData(javax.servlet.http.HttpServletResponse resp)protected voidsendOkJsonData(javax.servlet.http.HttpServletResponse resp, String data)protected voidwrite(String s, javax.servlet.http.HttpServletResponse resp)protected voidwriteJson(Object o, javax.servlet.http.HttpServletResponse resp)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.bedework.util.logging.Logged
audit, debug, debug, enableAuditLogger, enableErrorLogger, enableMetricsLogger, error, error, error, getLogger, getLogLevel, info, isAuditLoggerEnabled, isErrorLoggerEnabled, isMetricsDebugEnabled, isMetricsLoggerEnabled, metrics, setLoggerClass, setLoggerClass, setLogLevel, trace, trace, warn
-
-
-
-
Method Detail
-
init
public abstract void init() throws javax.servlet.ServletExceptionCalled at each request- Throws:
javax.servlet.ServletException
-
getMapper
public abstract com.fasterxml.jackson.databind.ObjectMapper getMapper()
- Returns:
- mapper used to handle json content
-
doMethod
public abstract void doMethod(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException- Parameters:
req- the requestresp- and response- Throws:
javax.servlet.ServletException
-
write
protected void write(String s, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException
- Throws:
javax.servlet.ServletException
-
writeJson
protected void writeJson(Object o, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException
- Throws:
javax.servlet.ServletException
-
getResourceUri
public List<String> getResourceUri(javax.servlet.http.HttpServletRequest req) throws javax.servlet.ServletException
Get the decoded and fixed resource URI. This calls getServletPath() to obtain the path information. The description of that method is a little obscure in it's meaning. In a request of this form:
"GET /ucaldav/user/douglm/calendar/1302064354993-g.ics HTTP/1.1[\r][\n]"
getServletPath() will return
/user/douglm/calendar/1302064354993-g.ics
that is the context has been removed. In addition this method will URL decode the path. getRequestUrl() does neither.- Parameters:
req- Servlet request object- Returns:
- List Path elements of fixed up uri
- Throws:
javax.servlet.ServletException
-
fixPath
public static List<String> fixPath(String path) throws javax.servlet.ServletException
Return a path, broken into its elements, after "." and ".." are removed. If the parameter path attempts to go above the root we return null. Other than the backslash thing why not use URI?- Parameters:
path- String path to be fixed- Returns:
- String[] fixed path broken into elements
- Throws:
javax.servlet.ServletException
-
addHeaders
protected void addHeaders(javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException- Throws:
javax.servlet.ServletException
-
readJson
protected Object readJson(InputStream is, Class cl, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException
Parse the request body, and return the object.- Parameters:
is- Input stream for contentcl- The class we expectresp- for status- Returns:
- Object Parsed body or null for no body
- Throws:
javax.servlet.ServletException- Some error occurred.
-
readJson
protected Object readJson(InputStream is, com.fasterxml.jackson.core.type.TypeReference tr, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException
Parse the request body, and return the object.- Parameters:
is- Input stream for contenttr- For the class we expectresp- for status- Returns:
- Object Parsed body or null for no body
- Throws:
javax.servlet.ServletException- Some error occurred.
-
sendJsonError
protected void sendJsonError(javax.servlet.http.HttpServletResponse resp, String msg)
-
sendOkJsonData
protected void sendOkJsonData(javax.servlet.http.HttpServletResponse resp)
-
sendOkJsonData
protected void sendOkJsonData(javax.servlet.http.HttpServletResponse resp, String data)
-
-