|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwater.api.RequestBuilders.Response
public static final class RequestBuilders.Response
This is a response class for the JSON. Instead of simply returning a JsonObject, each request returns a new response object that it must create. This is (a) cleaner (b) more explicit and (c) allows to specify response states used for proper error reporting, stateless and statefull processed and so on, and (d) allows specification of HTML builder hooks in a nice clean interface. The work pattern should be that in the serve() method, a JsonObject is created and populated with the variables. Then if any error occurs, an error response should be returned. Otherwise a correct state response should be created at the end from the json object and returned. JSON response structure: response -> status = (done,error,redirect, ...) h2o = name of the cloud node = answering node time = time in MS it took to process the request serve() other fields as per the response type other fields that should go to the user if error: error -> error reported
Nested Class Summary | |
---|---|
static class |
RequestBuilders.Response.Status
Status of the response. |
Field Summary | |
---|---|
protected java.util.HashMap<java.lang.String,RequestBuilders.Builder> |
_builders
Custom builders for JSON elements when converting to HTML automatically. |
protected java.util.List<java.lang.String> |
_headers
Custom headers to show in the html. |
protected int |
_pollProgress
Poll progress in terms of finished elements. |
protected int |
_pollProgressElements
Total elements to be finished before the poll will be done. |
protected java.lang.Object[] |
_redirArgs
|
protected com.google.gson.JsonObject |
_redirectArgs
Arguments of the redirect object. |
protected java.lang.String |
_redirectName
Name of the redirected request. |
protected Request |
_req
|
protected com.google.gson.JsonObject |
_response
Response object for JSON requests. |
protected RequestBuilders.Response.Status |
_status
Status of the request. |
protected boolean |
_strictJsonCompliance
|
protected long |
_time
Time it took the request to finish. |
static RequestBuilders.Response |
EMPTY_RESPONSE
A unique empty response which carries an empty JSON object |
Constructor Summary | |
---|---|
RequestBuilders.Response(RequestBuilders.Response.Status status,
Request req,
int progress,
int total,
java.lang.String redirTo,
java.lang.Object... args)
|
Method Summary | |
---|---|
void |
addHeader(java.lang.String h)
|
static RequestBuilders.Response |
done(com.google.gson.JsonObject response)
Returns new done response with given JSON response object. |
static RequestBuilders.Response |
doneEmpty()
Returns new done empty done response. |
java.lang.String |
error()
Returns the error of the request object if any. |
static RequestBuilders.Response |
error(java.lang.String message)
Returns new error response with given error message. |
void |
escapeIllegalJsonElements()
|
protected RequestBuilders.Builder |
getBuilderFor(java.lang.String contextName)
Returns the builder for given JSON context element. |
java.util.List<java.lang.String> |
getHeaders()
|
static RequestBuilders.Response |
poll(com.google.gson.JsonObject response,
float progress)
Returns the poll response object initialized by percents completed. |
static RequestBuilders.Response |
poll(com.google.gson.JsonObject response,
int progress,
int total)
Returns the poll response object. |
static RequestBuilders.Response |
poll(com.google.gson.JsonObject response,
int progress,
int total,
com.google.gson.JsonObject pollArgs)
returns the poll response object with different arguments that was this call. |
static RequestBuilders.Response |
redirect(com.google.gson.JsonObject response,
java.lang.Class<? extends Request> req,
com.google.gson.JsonObject args)
Creates the new response with status redirect. |
protected com.google.gson.JsonObject |
responseToJson()
Returns the response system json. |
RequestBuilders.Response |
setBuilder(java.lang.String contextName,
RequestBuilders.Builder builder)
Associates a given builder with the specified JSON context. |
void |
setTimeStart(long timeStart)
Sets the time of the response as a difference between the given time and now. |
com.google.gson.JsonObject |
toJson()
Returns the JSONified version of the request. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected long _time
protected final RequestBuilders.Response.Status _status
protected final java.lang.String _redirectName
protected final com.google.gson.JsonObject _redirectArgs
protected final java.lang.Object[] _redirArgs
protected final int _pollProgress
protected final int _pollProgressElements
protected final com.google.gson.JsonObject _response
protected final Request _req
protected boolean _strictJsonCompliance
protected final java.util.HashMap<java.lang.String,RequestBuilders.Builder> _builders
protected final java.util.List<java.lang.String> _headers
public static final RequestBuilders.Response EMPTY_RESPONSE
Constructor Detail |
---|
public RequestBuilders.Response(RequestBuilders.Response.Status status, Request req, int progress, int total, java.lang.String redirTo, java.lang.Object... args)
Method Detail |
---|
public static RequestBuilders.Response error(java.lang.String message)
public static RequestBuilders.Response done(com.google.gson.JsonObject response)
public static RequestBuilders.Response doneEmpty()
public static RequestBuilders.Response redirect(com.google.gson.JsonObject response, java.lang.Class<? extends Request> req, com.google.gson.JsonObject args)
public static RequestBuilders.Response poll(com.google.gson.JsonObject response, int progress, int total)
public static RequestBuilders.Response poll(com.google.gson.JsonObject response, float progress)
public static RequestBuilders.Response poll(com.google.gson.JsonObject response, int progress, int total, com.google.gson.JsonObject pollArgs)
public final void setTimeStart(long timeStart)
public RequestBuilders.Response setBuilder(java.lang.String contextName, RequestBuilders.Builder builder)
protected RequestBuilders.Builder getBuilderFor(java.lang.String contextName)
public void addHeader(java.lang.String h)
public java.util.List<java.lang.String> getHeaders()
protected com.google.gson.JsonObject responseToJson()
public com.google.gson.JsonObject toJson()
public java.lang.String error()
public void escapeIllegalJsonElements()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |