public abstract class JsonHttpHandler extends java.lang.Object implements HttpHandler
| Modifier and Type | Field and Description |
|---|---|
protected static JsonHttpUtils |
HTTP_UTILS
Utilities for JSON-Request/Response handling.
|
| Constructor and Description |
|---|
JsonHttpHandler() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetRootContextPathprotected static final JsonHttpUtils HTTP_UTILS
public abstract java.lang.Object process(Record inputRecord) throws java.lang.Exception
inputRecord - input Recordjava.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 objectprotected boolean isValidMethod(java.lang.String method,
java.lang.String requestUri)
method - HTTP methodrequestUri - request URIprotected 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 processprotected 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 resultprotected 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)