|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.apache.oozie.servlet.JsonRestServlet
public abstract class JsonRestServlet
Base class for Oozie web service API Servlets.
This class provides common instrumentation, error logging and other common functionality.
Nested Class Summary | |
---|---|
static class |
JsonRestServlet.ParameterInfo
This bean defines a query string parameter. |
static class |
JsonRestServlet.ResourceInfo
This bean defines a REST resource. |
Field Summary | |
---|---|
protected static java.lang.String |
AUDIT_ERROR_CODE
|
protected static java.lang.String |
AUDIT_ERROR_MESSAGE
|
protected static java.lang.String |
AUDIT_HTTP_STATUS_CODE
|
protected static java.lang.String |
AUDIT_OPERATION
|
protected static java.lang.String |
AUDIT_PARAM
|
static java.lang.String |
AUTH_TOKEN
Request attribute constant for the authenticatio token. |
protected static java.lang.String |
INSTRUMENTATION_GROUP
Name of the instrumentation group for the WS layer, value is 'webservices'. |
protected static java.lang.String |
TEXT_UTF8
|
protected static java.lang.String |
UNDEF
|
static java.lang.String |
USER_NAME
Request attribute constant for the user name. |
protected static java.lang.String |
XML_UTF8
|
Constructor Summary | |
---|---|
JsonRestServlet(java.lang.String instrumentationName,
JsonRestServlet.ResourceInfo... resourcesInfo)
Creates a servlet with a specified instrumentation sampler name for its requests. |
Method Summary | |
---|---|
protected java.lang.String |
getAuthToken(javax.servlet.http.HttpServletRequest request)
Return the authentication token of the request if any. |
protected java.lang.String |
getContentType(javax.servlet.http.HttpServletRequest request)
Return the request content type, lowercase and without attributes. |
protected java.lang.String |
getResourceName(javax.servlet.http.HttpServletRequest request)
Return the resource name of the request. |
protected java.lang.String |
getUser(javax.servlet.http.HttpServletRequest request)
Return the user name of the request if any. |
void |
init(javax.servlet.ServletConfig servletConfig)
Initializes total request and servlet request samplers. |
protected void |
sendErrorResponse(javax.servlet.http.HttpServletResponse response,
int statusCode,
java.lang.String error,
java.lang.String message)
Sends a error response. |
protected void |
sendJsonResponse(javax.servlet.http.HttpServletResponse response,
int statusCode,
JsonBean bean)
Sends a JSON response. |
protected void |
sendJsonResponse(javax.servlet.http.HttpServletResponse response,
int statusCode,
org.json.simple.JSONStreamAware json)
|
protected void |
service(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Dispatches to super after loginfo and intrumentation handling. |
protected void |
setAllowSafeModeChanges(boolean allow)
Enable HTTP POST/PUT/DELETE methods while in safe mode. |
protected void |
setLogInfo(java.lang.String jobid,
java.lang.String actionid)
Set the log info with the given information. |
protected void |
startCron()
Start the request instrumentation cron. |
protected void |
stopCron()
Stop the request instrumentation cron. |
protected java.lang.String |
validateContentType(javax.servlet.http.HttpServletRequest request,
java.lang.String expected)
Validate and return the content type of the request. |
protected void |
validateRestUrl(java.lang.String method,
java.lang.String resourceName,
java.util.Map<java.lang.String,java.lang.String[]> queryStringParams)
Validates REST URL using the ResourceInfos of the servlet. |
Methods inherited from class javax.servlet.http.HttpServlet |
---|
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service |
Methods inherited from class javax.servlet.GenericServlet |
---|
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String XML_UTF8
protected static final java.lang.String TEXT_UTF8
protected static final java.lang.String AUDIT_OPERATION
protected static final java.lang.String AUDIT_PARAM
protected static final java.lang.String AUDIT_ERROR_CODE
protected static final java.lang.String AUDIT_ERROR_MESSAGE
protected static final java.lang.String AUDIT_HTTP_STATUS_CODE
protected static final java.lang.String INSTRUMENTATION_GROUP
public static final java.lang.String AUTH_TOKEN
public static final java.lang.String USER_NAME
protected static final java.lang.String UNDEF
Constructor Detail |
---|
public JsonRestServlet(java.lang.String instrumentationName, JsonRestServlet.ResourceInfo... resourcesInfo)
instrumentationName
- instrumentation name for timer and samplers for the servlet.resourcesInfo
- list of resource definitions supported by the servlet, empty and wildcard resources must be
the last ones, in that order, first empty and the wildcard.Method Detail |
---|
protected void setAllowSafeModeChanges(boolean allow)
allow
- true
enabled safe mode changes, false
disable safe mode changes
(default).protected void startCron()
protected void stopCron()
public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
protected final void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
service
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
protected void sendJsonResponse(javax.servlet.http.HttpServletResponse response, int statusCode, JsonBean bean) throws java.io.IOException
response
- servlet response.statusCode
- HTTP status code.bean
- bean to send as JSON response.
java.io.IOException
- thrown if the bean could not be serialized to the response output stream.protected void sendErrorResponse(javax.servlet.http.HttpServletResponse response, int statusCode, java.lang.String error, java.lang.String message) throws java.io.IOException
response
- servlet response.statusCode
- HTTP status code.error
- error code.message
- error message.
java.io.IOException
- thrown if the error response could not be set.protected void sendJsonResponse(javax.servlet.http.HttpServletResponse response, int statusCode, org.json.simple.JSONStreamAware json) throws java.io.IOException
java.io.IOException
protected void validateRestUrl(java.lang.String method, java.lang.String resourceName, java.util.Map<java.lang.String,java.lang.String[]> queryStringParams) throws javax.servlet.ServletException
method
- HTTP method.resourceName
- resource name.queryStringParams
- query string parameters.
javax.servlet.ServletException
- thrown if the resource name or parameters are incorrect.protected java.lang.String getResourceName(javax.servlet.http.HttpServletRequest request)
request
- request instance
null
if none.protected java.lang.String getContentType(javax.servlet.http.HttpServletRequest request)
request
- servlet request.
null
if none.protected java.lang.String validateContentType(javax.servlet.http.HttpServletRequest request, java.lang.String expected) throws XServletException
request
- servlet request.expected
- expected contentType.
XServletException
- thrown if the content type is invalid.protected java.lang.String getAuthToken(javax.servlet.http.HttpServletRequest request)
request
- request.
null
if there is none.protected java.lang.String getUser(javax.servlet.http.HttpServletRequest request)
request
- request.
null
if there is none.protected void setLogInfo(java.lang.String jobid, java.lang.String actionid)
jobid
- job ID.actionid
- action ID.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |