org.eclipse.smila.taskmanager.httphandler
Class TaskHandler
java.lang.Object
org.eclipse.smila.http.server.util.ARequestHandler
org.eclipse.smila.http.server.json.JsonRequestHandler
org.eclipse.smila.taskmanager.httphandler.TaskHandler
- All Implemented Interfaces:
- HttpHandler, RequestHandler
public class TaskHandler
- extends JsonRequestHandler
Implements the handling of HTTP requests on a single task.
URL pattern: taskmanager/-workername-/-taskid-
Currently a task can be finished by POSTing a result description at the task URI or a keepalive can be sent by
POSTing without data.
|
Method Summary |
protected int |
getErrorStatus(java.lang.String method,
java.lang.String requestUri,
java.lang.Throwable ex)
Adds HTTP result code 400 ("BAD_REQUEST") for IllegalArgumentException to the exception handling of
JsonRequestHandler.getErrorStatus(String, String, Throwable). |
protected int |
getSuccessStatus(java.lang.String requestMethod,
java.lang.String requestUri,
Record inputRecord,
java.lang.Object resultObject)
Returns the success code. |
protected boolean |
isValidMethod(java.lang.String method,
java.lang.String requestUri)
Checks if the handler allows the HTTP method. |
java.lang.Object |
process(java.lang.String method,
java.lang.String requestUri,
Record inputRecord)
process input record and return result object. |
void |
setTaskManager(TaskManager taskManager)
|
void |
unsetTaskManager(TaskManager taskManager)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TaskHandler
public TaskHandler()
process
public java.lang.Object process(java.lang.String method,
java.lang.String requestUri,
Record inputRecord)
throws java.lang.Exception
- process input record and return result object.
Override this method in your handler if you do not need access to HttpExchange object, e.g. to read http header
fields. Otherwise use overloaded method with HttpExchange parameter.
- Overrides:
process in class JsonRequestHandler
- Parameters:
method - HTTP methodrequestUri - request URI.inputRecord - input record parsed either from request body, if it has content, or from request URI parameters.
- Returns:
- result object, may be null. If this is not a
Record, you have to provide a
JsonRequestHandler.writeResultObject(OutputStream, Object) method, too.
- Throws:
java.lang.Exception - any failure during processing.
getErrorStatus
protected int getErrorStatus(java.lang.String method,
java.lang.String requestUri,
java.lang.Throwable ex)
- Adds HTTP result code 400 ("BAD_REQUEST") for IllegalArgumentException to the exception handling of
JsonRequestHandler.getErrorStatus(String, String, Throwable).
- Overrides:
getErrorStatus in class JsonRequestHandler
- Parameters:
method - HTTP methodrequestUri - request URIex - an exception
- Returns:
- error status code.
- See Also:
HTTP_UTILS#getErrorStatus(String, String, Throwable)
getSuccessStatus
protected int getSuccessStatus(java.lang.String requestMethod,
java.lang.String requestUri,
Record inputRecord,
java.lang.Object resultObject)
- Returns the success code.
- Overrides:
getSuccessStatus in class JsonRequestHandler
- Parameters:
requestMethod - HTTP methodrequestUri - request URIinputRecord - input recordresultObject - result object returned from process
- Returns:
- the status code to return for successful requests using the method and request URI.
isValidMethod
protected boolean isValidMethod(java.lang.String method,
java.lang.String requestUri)
- Checks if the handler allows the HTTP method.
GET and DELETE are currently the only valid methods.
- Overrides:
isValidMethod in class JsonRequestHandler
- Parameters:
method - HTTP methodrequestUri - request URI
- Returns:
- true if the method can be used for the URI, else false.
setTaskManager
public void setTaskManager(TaskManager taskManager)
- Parameters:
taskManager - the reference to the JobManager service.
unsetTaskManager
public void unsetTaskManager(TaskManager taskManager)
- Parameters:
taskManager - the reference to the current JobManager service.