org.labkey.remoteapi

## Class PostCommand<ResponseType extends CommandResponse>

- java.lang.Object
- - org.labkey.remoteapi.Command<ResponseType>
  - - org.labkey.remoteapi.PostCommand<ResponseType>

- Direct Known Subclasses:
    BaseTransformCommand, CreateContainerCommand, CreateGroupCommand, CreateUserCommand, DeleteContainerCommand, DeleteGroupCommand, DeleteUserCommand, ExecuteSqlCommand, GroupMembersCommand, ImportRunCommand, RenameGroupCommand, SaveAssayBatchCommand, SaveRowsCommand, UpdateParticipantGroupCommand

      public class PostCommand<ResponseType extends CommandResponse>
      extends Command<ResponseType>

  Base class for all commands that needs to post data to the server, rather than providing parameters in the query string.

  Client code will not typically use this class directly, but will instead use one of the classes that extend this class (e.g., `UpdateRowsCommand`).

  However, if future versions of the LabKey Server expose new HTTP APIs requiring a POST that are not yet supported with a specialized class in this library, the developer may still invoke these APIs by creating an instance of the PostCommand object directly, providing the controller and action name for the new API. The post body may then be supplied by overriding the `getJsonObject()` method, returning the JSON object to post.

  Version:
    1.0
  Author:
    Dave Stearns, LabKey Corporation

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.labkey.remoteapi.Command

      `Command.CommonParameters, Command.Response`

  - ### Field Summary

    - ### Fields inherited from class org.labkey.remoteapi.Command

      `CONTENT_TYPE_JSON`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PostCommand(PostCommand source)`
    `PostCommand(java.lang.String controllerName, java.lang.String actionName)` Constructs a new PostCommand given a controller and action name.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `PostCommand` | `copy()` Returns a copy of this object.
    `protected org.apache.http.client.methods.HttpUriRequest` | `createRequest(java.net.URI uri)` Overrides `Command.createRequest(URI)` to create an `HttpPost` object.
    `org.json.simple.JSONObject` | `getJsonObject()` Returns the JSON object to post, or null if the JSON object has not yet been set.
    `void` | `setJsonObject(org.json.simple.JSONObject jsonObject)` Sets the JSON object to post.

    - ### Methods inherited from class org.labkey.remoteapi.Command

      `_execute, createResponse, execute, getActionName, getActionUrl, getControllerName, getHttpRequest, getParameters, getParamValueAsString, getQueryString, getRequiredVersion, getTimeout, setParameters, setRequiredVersion, setTimeout`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PostCommand

          public PostCommand(java.lang.String controllerName,
                             java.lang.String actionName)

      Constructs a new PostCommand given a controller and action name.
      Parameters:
        `controllerName` - The controller name.
        `actionName` - The action name.

    - #### PostCommand

          public PostCommand(PostCommand source)

  - ### Method Detail

    - #### getJsonObject

          public org.json.simple.JSONObject getJsonObject()

      Returns the JSON object to post, or null if the JSON object has not yet been set. Override this method to provide the JSON object dynamically.
      Returns:
        The JSON object to post.

    - #### setJsonObject

          public void setJsonObject(org.json.simple.JSONObject jsonObject)

      Sets the JSON object to post.
      Parameters:
        `jsonObject` - The JSON object to post

    - #### createRequest

          protected org.apache.http.client.methods.HttpUriRequest createRequest(java.net.URI uri)

      Overrides `Command.createRequest(URI)` to create an `HttpPost` object.

      Override this method if your post command sends something other than JSON in the post body. In your override, create the PostMethod and set the RequestEntity appropriately.

      Overrides:
        `createRequest` in class `Command<ResponseType extends CommandResponse>`
      Returns:
        The PostMethod object.

    - #### copy

          public PostCommand copy()

      Description copied from class: `Command`
      Returns a copy of this object. Derived classes should override this to copy their own data members
      Overrides:
        `copy` in class `Command<ResponseType extends CommandResponse>`
      Returns:
        A copy of this object