public class CommandResponse
extends java.lang.Object
Client code will typically use a class derived from this class that is returned from the particular command used (e.g. SelectRowsCommand returns SelectRowsResponse). However, if you are using the Command class directly to call an HTTP API that does not yet have a specialized command class, you would use this object to obtain the response details.
Constructor and Description |
---|
CommandResponse(java.lang.String text,
int statusCode,
java.lang.String contentType,
org.json.simple.JSONObject json,
Command sourceCommand)
Constructs a new CommandResponse, initialized with the provided
response text and status code.
|
Modifier and Type | Method and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.Object> |
findObject(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> objects,
java.lang.String propertyName,
java.lang.String value)
Finds, in a List of Maps, the first Map containing an entry that matches
propertyName and value
matches the value supplied. |
java.lang.String |
getContentType()
Returns the Content-Type header value from the response.
|
java.util.Map<java.lang.String,java.lang.Object> |
getParsedData()
Attempts to parse the response text and return a property Map.
|
<T> T |
getProperty(java.lang.String path)
Returns the value of a specific property in the parsed data
given a path to that property.
|
protected <T> T |
getProperty(java.lang.String[] path,
int pathIndex,
java.util.Map<java.lang.String,java.lang.Object> parent)
Called by
getProperty(String) after splitting the path into
a String[], and recursively by itself as it descends the property
hierarchy. |
double |
getRequiredVersion()
Returns the API version number required by the source command.
|
Command |
getSourceCommand()
Returns a reference to a copy of the command that created this response
|
int |
getStatusCode()
Returns the HTTP status code (typically 200).
|
java.lang.String |
getText()
Returns the raw response text.
|
public CommandResponse(java.lang.String text, int statusCode, java.lang.String contentType, org.json.simple.JSONObject json, Command sourceCommand)
text
- The response textstatusCode
- The HTTP status codecontentType
- The response content typejson
- The parsed JSONObject (or null if JSON was not returned).sourceCommand
- A copy of the command that created this responsepublic java.lang.String getText()
Use this if your command returns something other than JSON, or if you want to use a different JSON parser.
This may return null if no response body was sent by the server.
public int getStatusCode()
public java.lang.String getContentType()
public double getRequiredVersion()
public Command getSourceCommand()
public java.util.Map<java.lang.String,java.lang.Object> getParsedData()
If the response text cannot be parsed, a runtime error will be thrown.
Note that the values in the Map may be simple values, Lists, or Maps.
public <T> T getProperty(java.lang.String path)
The path is a period-delimited list of property names. For example, to obtain the 'bar' property from the Map associated with the 'foo' property, the path would be 'foo.bar'. Property names may include an array index. For example, 'foos[2].bar' will return the 'bar' property for the third item of the 'foos' array
T
- the type of the property.path
- The property path.protected <T> T getProperty(java.lang.String[] path, int pathIndex, java.util.Map<java.lang.String,java.lang.Object> parent)
getProperty(String)
after splitting the path into
a String[], and recursively by itself as it descends the property
hierarchy.T
- The type of the property.path
- The path split into a String[].pathIndex
- The current index into the path array.parent
- The current parent map.protected java.util.Map<java.lang.String,java.lang.Object> findObject(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> objects, java.lang.String propertyName, java.lang.String value)
propertyName
and value
matches the value
supplied. Returns null if not found.objects
- The list of Maps to search.propertyName
- The property name to examine in each Map.value
- The value to compare against.