| 
||||||||||
| 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 String | 
AUDIT_ERROR_CODE
 | 
protected static String | 
AUDIT_ERROR_MESSAGE
 | 
protected static String | 
AUDIT_HTTP_STATUS_CODE
 | 
protected static String | 
AUDIT_OPERATION
 | 
protected static String | 
AUDIT_PARAM
 | 
static String | 
AUTH_TOKEN
Request attribute constant for the authenticatio token.  | 
protected static String | 
INSTRUMENTATION_GROUP
Name of the instrumentation group for the WS layer, value is 'webservices'.  | 
protected static String | 
TEXT_UTF8
 | 
protected static String | 
UNDEF
 | 
static String | 
USER_NAME
Request attribute constant for the user name.  | 
protected static String | 
XML_UTF8
 | 
| Constructor Summary | |
|---|---|
JsonRestServlet(String instrumentationName,
                               JsonRestServlet.ResourceInfo... resourcesInfo)
Creates a servlet with a specified instrumentation sampler name for its requests.  | 
|
| Method Summary | |
|---|---|
protected  String | 
getAuthToken(javax.servlet.http.HttpServletRequest request)
Return the authentication token of the request if any.  | 
protected  String | 
getContentType(javax.servlet.http.HttpServletRequest request)
Return the request content type, lowercase and without attributes.  | 
protected  String | 
getResourceName(javax.servlet.http.HttpServletRequest request)
Return the resource name of the request.  | 
protected  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,
                                   String error,
                                   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(String jobid,
                     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  String | 
validateContentType(javax.servlet.http.HttpServletRequest request,
                                       String expected)
Validate and return the content type of the request.  | 
protected  void | 
validateRestUrl(String method,
                               String resourceName,
                               Map<String,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 String XML_UTF8
protected static final String TEXT_UTF8
protected static final String AUDIT_OPERATION
protected static final String AUDIT_PARAM
protected static final String AUDIT_ERROR_CODE
protected static final String AUDIT_ERROR_MESSAGE
protected static final String AUDIT_HTTP_STATUS_CODE
protected static final String INSTRUMENTATION_GROUP
public static final String AUTH_TOKEN
public static final String USER_NAME
protected static final String UNDEF
| Constructor Detail | 
|---|
public JsonRestServlet(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.Servletinit in class javax.servlet.GenericServletjavax.servlet.ServletException
protected final void service(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws javax.servlet.ServletException,
                             IOException
service in class javax.servlet.http.HttpServletjavax.servlet.ServletException
IOException
protected void sendJsonResponse(javax.servlet.http.HttpServletResponse response,
                                int statusCode,
                                JsonBean bean)
                         throws IOException
response - servlet response.statusCode - HTTP status code.bean - bean to send as JSON response.
IOException - thrown if the bean could not be serialized to the response output stream.
protected void sendErrorResponse(javax.servlet.http.HttpServletResponse response,
                                 int statusCode,
                                 String error,
                                 String message)
                          throws IOException
response - servlet response.statusCode - HTTP status code.error - error code.message - error message.
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 IOException
IOException
protected void validateRestUrl(String method,
                               String resourceName,
                               Map<String,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 String getResourceName(javax.servlet.http.HttpServletRequest request)
request - request instance
null if none.protected String getContentType(javax.servlet.http.HttpServletRequest request)
request - servlet request.
null if none.
protected String validateContentType(javax.servlet.http.HttpServletRequest request,
                                     String expected)
                              throws XServletException
request - servlet request.expected - expected contentType.
XServletException - thrown if the content type is invalid.protected String getAuthToken(javax.servlet.http.HttpServletRequest request)
request - request.
null if there is none.protected String getUser(javax.servlet.http.HttpServletRequest request)
request - request.
null if there is none.
protected void setLogInfo(String jobid,
                          String actionid)
jobid - job ID.actionid - action ID.
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||