Class CommandResponse

java.lang.Object
org.labkey.remoteapi.CommandResponse
Direct Known Subclasses:
AssayListResponse, BaseTransformResponse, CreateContainerResponse, CreateGroupResponse, CreateUserResponse, DeleteContainerResponse, DomainDetailsResponse, DomainResponse, FileNotificationResponse, GetAssayRunResponse, GetContainersResponse, GetGroupPermsResponse, GetQueriesResponse, GetQueryDetailsResponse, GetSchemasResponse, GetUsersResponse, ImportDataResponse, ImportRunResponse, LineageResponse, ListDomainsResponse, LoadAssayBatchResponse, NAbRunsResponse, ProtocolResponse, RenameContainerResponse, RenameGroupResponse, SaveAssayBatchResponse, SaveAssayRunsResponse, SaveRowsResponse, SelectRowsResponse, StartSearchResponse, StorageCommandResponse, TruncateTableResponse, UpdateParticipantGroupResponse, WhoAmIResponse

public class CommandResponse extends Object
Represents the details of a response returned from the LabKey Server.

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 Details

    • CommandResponse

      public CommandResponse(String text, int statusCode, String contentType, org.json.JSONObject json)
      Constructs a new CommandResponse, initialized with the provided response text and status code.
      Parameters:
      text - The response text
      statusCode - The HTTP status code
      contentType - The response content type
      json - The parsed JSONObject (or null if JSON was not returned)
  • Method Details

    • getText

      public String getText()
      Returns the raw response text.

      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.

      Returns:
      The raw response text.
    • getStatusCode

      public int getStatusCode()
      Returns the HTTP status code (typically 200).
      Returns:
      The HTTP status code
    • getContentType

      public String getContentType()
      Returns the Content-Type header value from the response. Note that this may return null if no content type header was supplied by the server (unlikely but possible).
      Returns:
      The content type of the response.
    • getParsedData

      public Map<String,Object> getParsedData()
      Attempts to parse the response text and return a property Map.

      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.

      Returns:
      The parsed data as a property map.
    • getProperty

      public <T> T getProperty(String path)
      Returns the value of a specific property in the parsed data given a path to that property.

      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

      Type Parameters:
      T - the type of the property.
      Parameters:
      path - The property path.
      Returns:
      The property value, or null if the property was not found.
    • getProperty

      protected <T> T getProperty(String[] path, int pathIndex, Map<String,Object> parent)
      Called by getProperty(String) after splitting the path into a String[], and recursively by itself as it descends the property hierarchy.
      Type Parameters:
      T - The type of the property.
      Parameters:
      path - The path split into a String[].
      pathIndex - The current index into the path array.
      parent - The current parent map.
      Returns:
      The property value, or null if not found.
    • findObject

      protected Map<String,Object> findObject(List<Map<String,Object>> objects, String propertyName, String value)
      Finds, in a List of Maps, the first Map containing an entry that matches propertyName and value matches the value supplied. Returns null if not found.
      Parameters:
      objects - The list of Maps to search.
      propertyName - The property name to examine in each Map.
      value - The value to compare against.
      Returns:
      The Map where the value of propertyName equals value, or null if not found.