|
SMILA 1.0 API documentation | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eclipse.smila.http.server.json.JsonHttpHandler
public abstract class JsonHttpHandler
Common base class for HTTP handlers that expect a single JSON CEO as input and produce a single CEO in case of successful processing.
| Field Summary | |
|---|---|
protected static JsonHttpUtils |
HTTP_UTILS
Utilities for JSON-Request/Response handling. |
| Constructor Summary | |
|---|---|
JsonHttpHandler()
|
|
| Method Summary | |
|---|---|
protected int |
getErrorStatus(java.lang.String method,
java.lang.String requestUri,
java.lang.Throwable ex)
Return a status code for an exception. |
protected int |
getSuccessStatus(java.lang.String method,
java.lang.String requestUri)
|
protected int |
getSuccessStatus(java.lang.String requestMethod,
java.lang.String requestUri,
Record inputRecord,
java.lang.Object resultObject)
Returns the success code. |
void |
handle(HttpExchange exchange)
reads a record from the JSON request, calls process(Record) to do processing and get a result record and
writes JSON result. |
protected boolean |
isValidMethod(java.lang.String method,
java.lang.String requestUri)
|
abstract java.lang.Object |
process(Record inputRecord)
process input record and return result record. |
protected boolean |
writeErrorResult(HttpExchange exchange,
java.lang.Throwable error,
Record inputRecord)
write an error result. |
protected void |
writeResultObject(java.io.OutputStream responseStream,
java.lang.Object resultObject)
write result object. |
protected boolean |
writeSuccessResult(HttpExchange exchange,
java.lang.Object resultObject,
Record inputRecord)
write a successful result. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.eclipse.smila.http.server.HttpHandler |
|---|
getRootContextPath |
| Field Detail |
|---|
protected static final JsonHttpUtils HTTP_UTILS
| Constructor Detail |
|---|
public JsonHttpHandler()
| Method Detail |
|---|
public abstract java.lang.Object process(Record inputRecord)
throws java.lang.Exception
inputRecord - input Record
java.lang.Exception - any failure during processing.public void handle(HttpExchange exchange)
process(Record) to do processing and get a result record and
writes JSON result.
Handles a HttpExchange containing a HttpRequest.
handle in interface HttpHandlerexchange - the HttpExchange object
protected boolean isValidMethod(java.lang.String method,
java.lang.String requestUri)
method - HTTP methodrequestUri - request URI
protected boolean writeSuccessResult(HttpExchange exchange,
java.lang.Object resultObject,
Record inputRecord)
throws java.io.IOException
exchange - HTTP exchangeresultObject - result objectinputRecord - input record parsed either from request body, if it has content, or from request URI parameters.
java.io.IOException - error writing the result.
protected int getSuccessStatus(java.lang.String method,
java.lang.String requestUri)
protected int getSuccessStatus(java.lang.String requestMethod,
java.lang.String requestUri,
Record inputRecord,
java.lang.Object resultObject)
requestMethod - HTTP methodrequestUri - request URIinputRecord - input recordresultObject - result object returned from process
protected void writeResultObject(java.io.OutputStream responseStream,
java.lang.Object resultObject)
throws java.io.IOException
Record results. Subclasses that produce
different result types must override this method.
responseStream - response streamresultObject - result object.
java.io.IOException - error writing result
protected boolean writeErrorResult(HttpExchange exchange,
java.lang.Throwable error,
Record inputRecord)
throws java.io.IOException
exchange - HTTP exchangeerror - the exception causing the error.inputRecord - the input record.
java.io.IOException - error writing the result.
protected int getErrorStatus(java.lang.String method,
java.lang.String requestUri,
java.lang.Throwable ex)
HTTP_UTILS#getErrorStatus(String, String, Throwable)
|
SMILA 1.0 API documentation | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||