Package com.smartgwt.client.rpc

# Class RPCResponse

java.lang.Object
com.smartgwt.client.core.JsObject
com.smartgwt.client.core.DataClass
com.smartgwt.client.core.RefDataClass
com.smartgwt.client.rpc.RPCResponse

All Implemented Interfaces:
  `HasHandlers`

Direct Known Subclasses:
  `DSResponse`

public class RPCResponse extends RefDataClass
Encapsulates an RPC response from the server. Instances of this class are automatically created and optionally passed to you in the callback you specify as part of your RPCRequest.

See Also:
  - `RPCRequest`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `INVALID_RESPONSE_FORMAT`
  Indicates that a response with invalid format has been received from server.
  `static final int`
  `STATUS_AUTHORIZATION_FAILURE`
  Indicates a `Declarative Security` failure on the server.
  `static final int`
  `STATUS_CONNECTION_RESET_ERROR`
  This response code only occurs when using the HTTP proxy.
  `static final int`
  `STATUS_CRITERIA_REQUIRED_ERROR`
  `static final int`
  `STATUS_FAILURE`
  Indicates a generic failure on the server.
  `static final int`
  `STATUS_FILE_REQUIRED_ERROR`
  Indicates that an empty file was uploaded for a required 'binary' field.
  `static final int`
  `STATUS_LOGIN_INCORRECT`
  Indicates that the RPC has been intercepted by an authenticator that requires the user to log in.
  `static final int`
  `STATUS_LOGIN_REQUIRED`
  Indicates that a login is required before this RPCRequest can proceed.
  `static final int`
  `STATUS_LOGIN_SUCCESS`
  Indicates that the login succeeded.
  `static final int`
  `STATUS_MAX_FILE_SIZE_EXCEEDED`
  Indicates that an uploaded file's size exceeded the maximum file size allowed.
  `static final int`
  `STATUS_MAX_LOGIN_ATTEMPTS_EXCEEDED`
  Indicates that too many authentication attempts have been made and the server refuses to accept any more login attempts.
  `static final int`
  `STATUS_MAX_POST_SIZE_EXCEEDED`
  Indicates that the total size of the data sent to the server was more than the server is configured to allow.
  `static final int`
  `STATUS_OFFLINE`
  Indicates that the browser is currently offline, and that we do not hold a cached response for the request.
  `static final int`
  `STATUS_REQUIRED_CRITERIA_MISSING`
  Indicates that an operation binding configured to require `OperationBinding.requiredCriterion` has received none.
  `static final int`
  `STATUS_SERVER_TIMEOUT`
  Indicates a request timed out with no server response.
  `static final int`
  `STATUS_SUCCESS`
  Indicates successful completion of the request.
  `static final int`
  `STATUS_TRANSACTION_FAILED`
  Indicates that the request was either never attempted or was rolled back, because automatic or user transactions are in force and another request in the same transaction failed.
  `static final int`
  `STATUS_TRANSPORT_ERROR`
  This response code is usable only with the XMLHttpRequest transport and indicates that the server returned an HTTP response code outside the range 200-299 (all of these statuses indicate success, but ordinarily only 200 is used).
  `static final int`
  `STATUS_UNKNOWN_HOST_ERROR`
  This response code only occurs when using the HTTP proxy.
  `static final int`
  `STATUS_UPDATE_WITHOUT_PK_ERROR`
  Indicates that the client attempted an update or remove operation without providing primary key field(s)
  `static final int`
  `STATUS_VALIDATION_ERROR`
  Indicates a validation failure on the server.

  ### Fields inherited from class com.smartgwt.client.core.RefDataClass

  `id`

  ### Fields inherited from class com.smartgwt.client.core.DataClass

  `factoryCreated, factoryProperties`

  ### Fields inherited from class com.smartgwt.client.core.JsObject

  `jsObj`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RPCResponse()`
  `RPCResponse(JavaScriptObject jsObj)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `create()`
  RPCResponses shouldn't be created directly.
  `Map`
  `getDataAsMap()`
  The data sent by the server.
  `JavaScriptObject`
  `getDataAsObject()`
  The data sent by the server.
  `String`
  `getDataAsString()`
  The data sent by the server.
  `Map`
  `getHttpHeaders()`
  HTTP headers returned by the server as a map from header name to header value.
  `Integer`
  `getHttpResponseCode()`
  This attribute (available when using the the `xmlHttpRequest` transport) contains the HTTP response code sent by the server.
  `String`
  `getHttpResponseText()`
  The actual text of the HTTP response.
  `static RPCResponse`
  `getOrCreateRef(JavaScriptObject jsObj)`
  `int`
  `getStatus()`
  Status code for this response.
  `Integer`
  `getTransactionNum()`
  ID of the transaction sent to the server via `RPCManager.sendQueue()` containing the `RPCRequest` associated with this response.
  `protected static boolean`
  `isDSResponse(JavaScriptObject jsObj)`
  `RPCResponse`
  `setStatus(int status)`
  Status code for this response.

  ### Methods inherited from class com.smartgwt.client.core.RefDataClass

  `getRef, getRef, internalSetID`

  ### Methods inherited from class com.smartgwt.client.core.DataClass

  `applyFactoryProperties, doAddHandler, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsDoubleArray, getAttributeAsElement, getAttributeAsFloat, getAttributeAsInt, getAttributeAsIntArray, getAttributeAsJavaScriptObject, getAttributeAsLong, getAttributeAsMap, getAttributeAsObject, getAttributeAsRecord, getAttributeAsString, getAttributeAsStringArray, getAttributes, getHandlerCount, isFactoryCreated, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttributeAsJavaObject, setFactoryCreated`

  ### Methods inherited from class com.smartgwt.client.core.JsObject

  `equals, getJsObj, hashCode, isCreated, setJavaScriptObject, setJsObj`

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

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

- ## Field Details

  - ### INVALID_RESPONSE_FORMAT

    public static final int INVALID_RESPONSE_FORMAT
    Indicates that a response with invalid format has been received from server. If the datasource is using "iscServer" dataFormat, this means that the response is not recognized as a valid ISC frame.

    One possible cause for this error can be the reception of a RestDataSource JSON response that lacks a valid `RestDataSource.jsonPrefix` and/or `RestDataSource.jsonSuffix`

    If it is using "xml" or "json" dataFormat, the response could not be parsed as XML or JSON.

    See Also:
      - Constant Field Values

  - ### STATUS_AUTHORIZATION_FAILURE

    public static final int STATUS_AUTHORIZATION_FAILURE
    Indicates a `Declarative Security` failure on the server. See the error handling section in `RPCManager documentation` for more information.
    See Also:
      - Constant Field Values

  - ### STATUS_CONNECTION_RESET_ERROR

    public static final int STATUS_CONNECTION_RESET_ERROR
    This response code only occurs when using the HTTP proxy. It is issued by the proxy servlet when the attempt to contact the target server results in a Java SocketException. This response probably indicates that the target server is currently down.
    See Also:
      - Constant Field Values

  - ### STATUS_CRITERIA_REQUIRED_ERROR

    public static final int STATUS_CRITERIA_REQUIRED_ERROR
    See Also:
      - Constant Field Values

  - ### STATUS_FAILURE

    public static final int STATUS_FAILURE
    Indicates a generic failure on the server. See the error handling section in `RPCManager documentation` for more information.
    See Also:
      - Constant Field Values

  - ### STATUS_FILE_REQUIRED_ERROR

    public static final int STATUS_FILE_REQUIRED_ERROR
    Indicates that an empty file was uploaded for a required 'binary' field.
    See Also:
      - Constant Field Values

  - ### STATUS_LOGIN_INCORRECT

    public static final int STATUS_LOGIN_INCORRECT
    Indicates that the RPC has been intercepted by an authenticator that requires the user to log in.
    See Also:
      - Constant Field Values

  - ### STATUS_LOGIN_REQUIRED

    public static final int STATUS_LOGIN_REQUIRED
    Indicates that a login is required before this RPCRequest can proceed.

    Applications do not directly set this status code, instead, to trigger the relogin flow, return the loginRequiredMarker in the response sent by your server when login is required. See the `Relogin Overview` for details.

    See Also:
      - Constant Field Values

  - ### STATUS_LOGIN_SUCCESS

    public static final int STATUS_LOGIN_SUCCESS
    Indicates that the login succeeded.
    See Also:
      - Constant Field Values

  - ### STATUS_MAX_FILE_SIZE_EXCEEDED

    public static final int STATUS_MAX_FILE_SIZE_EXCEEDED
    Indicates that an uploaded file's size exceeded the maximum file size allowed.
    See Also:
      - Constant Field Values

  - ### STATUS_MAX_LOGIN_ATTEMPTS_EXCEEDED

    public static final int STATUS_MAX_LOGIN_ATTEMPTS_EXCEEDED
    Indicates that too many authentication attempts have been made and the server refuses to accept any more login attempts.
    See Also:
      - Constant Field Values

  - ### STATUS_MAX_POST_SIZE_EXCEEDED

    public static final int STATUS_MAX_POST_SIZE_EXCEEDED
    Indicates that the total size of the data sent to the server was more than the server is configured to allow. Most servers limit the post size to prevent out of memory style attack vectors that push a bunch of data at the server. Apache Tomcat, for example, is pre-configured to limit post size to 2mb, where the default max post-size in Jetty, used by default in Eclipse, is just 200k.

    On internal networks, these limits can typically be safely raised or removed. With Tomcat, for example, you can remove the post limit by specifying the following attribute on the <Connector> element in conf/server.xml:

          maxPostSize="-1"

    In Jetty, you can update or create war/WEB-INF/jetty-web.xml, adding a section like this

          <Configure class="org.eclipse.jetty.webapp.WebAppContext"/>
              <Set name="maxFormContentSize">2000000</Set>
          </Configure>

    NOTE: this status code is used whenever the server framework receives a request where the POST data has been removed, however, there are other possible causes, including:
    - security software installed on the server or network that erroneously detects some kind of exploit attempt, if its behavior is to just strip the POST data but allow the rest of the request through (SiteMinder is one product known to do this)
    - incorrectly written filter servlets that drop POST'd data
    See Also:
      - Constant Field Values

  - ### STATUS_OFFLINE

    public static final int STATUS_OFFLINE
    Indicates that the browser is currently offline, and that we do not hold a cached response for the request.
    See Also:
      - Constant Field Values

  - ### STATUS_REQUIRED_CRITERIA_MISSING

    public static final int STATUS_REQUIRED_CRITERIA_MISSING
    Indicates that an operation binding configured to require `OperationBinding.requiredCriterion` has received none.
    See Also:
      - Constant Field Values

  - ### STATUS_SERVER_TIMEOUT

    public static final int STATUS_SERVER_TIMEOUT
    Indicates a request timed out with no server response.

    This is a client-only error code - never sent by the server (since it's the server that times out).

    NOTE that if using `hiddenFrame` as the transport (not the default), a malformed response such as a "500 Server Error" or 404 errors will be reported as a timeout.

    See Also:
      - Constant Field Values

  - ### STATUS_SUCCESS

    public static final int STATUS_SUCCESS
    Indicates successful completion of the request. This is the default status and is automatically used by the RPCResponse on the server unless you override it with setStatus().
    See the error handling section in `RPCManager documentation` for more information.
    See Also:
      - Constant Field Values

  - ### STATUS_TRANSACTION_FAILED

    public static final int STATUS_TRANSACTION_FAILED
    Indicates that the request was either never attempted or was rolled back, because automatic or user transactions are in force and another request in the same transaction failed. Note that the request(s) that actually failed will have a code specific to the failure; it is only the requests that would otherwise have succeeded that are marked with this failure code.
    See Also:
      - Constant Field Values

  - ### STATUS_TRANSPORT_ERROR

    public static final int STATUS_TRANSPORT_ERROR
    This response code is usable only with the XMLHttpRequest transport and indicates that the server returned an HTTP response code outside the range 200-299 (all of these statuses indicate success, but ordinarily only 200 is used). To get the actual response code, you can query rpcResponse.httpResponseCode in your callback.

    Note that currently this error code will never occur for the `hiddenFrame` transport - instead, use `STATUS_SERVER_TIMEOUT` to detect `hiddenFrame` transport errors.

    See Also:
      - Constant Field Values

  - ### STATUS_UNKNOWN_HOST_ERROR

    public static final int STATUS_UNKNOWN_HOST_ERROR
    This response code only occurs when using the HTTP proxy. It is issued by the proxy servlet when the target host is unknown (ie, cannot be resolved through DNS). This response probably indicates that you are attempting to contact a nonexistent server (though it might mean that you have DNS problems).
    See Also:
      - Constant Field Values

  - ### STATUS_UPDATE_WITHOUT_PK_ERROR

    public static final int STATUS_UPDATE_WITHOUT_PK_ERROR
    Indicates that the client attempted an update or remove operation without providing primary key field(s)
    See Also:
      - Constant Field Values

  - ### STATUS_VALIDATION_ERROR

    public static final int STATUS_VALIDATION_ERROR
    Indicates a validation failure on the server. See the error handling section in `RPCManager documentation` for more information.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### RPCResponse

    public RPCResponse()

  - ### RPCResponse

    public RPCResponse(JavaScriptObject jsObj)

- ## Method Details

  - ### getOrCreateRef

    public static RPCResponse getOrCreateRef(JavaScriptObject jsObj)

  - ### getHttpHeaders

    public Map getHttpHeaders()
    HTTP headers returned by the server as a map from header name to header value.

    Headers are available only when the default `RPCTransport` "xmlHttpRequest" is in use, and browsers may limit access to headers for cross-domain requests or in other security-sensitive scenarios.

    Returns:
      Current httpHeaders value. Default value is null

  - ### getHttpResponseCode

    public Integer getHttpResponseCode()
    This attribute (available when using the the `xmlHttpRequest` transport) contains the HTTP response code sent by the server.

    Note that this is different from `status` - that attribute is used to indicate a status code for the RPC itself whereas httpResponseCode is the raw HTTP response code for the HTTP request that contained the RPCRequest.

    This feature relies on the XMLHttpRequest object which can be disabled by end-users in some supported browsers. See `PlatformDependencies` for more information.

    If you're using this attribute, you'll typically want to avoid the default error handling response of RPCManager. To do so, set `RPCRequest.willHandleError` to `true`.

    Returns:
      Current httpResponseCode value. Default value is null

  - ### getHttpResponseText

    public String getHttpResponseText()
    The actual text of the HTTP response. Only available when the default `RPCTransport` "xmlHttpRequest" transport is in use,
    Returns:
      Current httpResponseText value. Default value is null

  - ### setStatus

    public RPCResponse setStatus(int status)
    Status code for this response. Status codes less than zero are considered errors by the RPCManager, those greater than or equal to zero are considered successes. Please see the error handling section the `RPCManager docs` for more information on what the RPCManager does with the status code and how you can override this behavior.

    When using the Smart GWT server you can set the rpcResponse.status by calling the server-side method RPCResponse.setStatus().

    When not using the Smart GWT server, the RPCManager makes no assumptions about the structure of the response, so the status code just reflects the `httpResponseCode`: status will be `STATUS_TRANSPORT_ERROR` if an HTTP-level error occurred such as "500 server error". If you have a status code you need to transmit you can simply embed it in the response (as part of `data`) and interpret it from the callback.

    With or without the Smart GWT server, the `Relogin` status codes (such as `STATUS_LOGIN_REQUIRED`) are triggered whenever special markers, such as the loginRequiredMarker, appear in the body of the response. See the `Relogin\n Overview` for details.

    Parameters:
      `status` - New status value. Default value is 0
    Returns:
      `RPCResponse` instance, for chaining setter calls
    See Also:
      - `RPCRequest.setReportDownloadErrorsAsDocuments(java.lang.Boolean)`

  - ### getStatus

    public int getStatus()
    Status code for this response. Status codes less than zero are considered errors by the RPCManager, those greater than or equal to zero are considered successes. Please see the error handling section the `RPCManager docs` for more information on what the RPCManager does with the status code and how you can override this behavior.

    When using the Smart GWT server you can set the rpcResponse.status by calling the server-side method RPCResponse.setStatus().

    When not using the Smart GWT server, the RPCManager makes no assumptions about the structure of the response, so the status code just reflects the `httpResponseCode`: status will be `STATUS_TRANSPORT_ERROR` if an HTTP-level error occurred such as "500 server error". If you have a status code you need to transmit you can simply embed it in the response (as part of `data`) and interpret it from the callback.

    With or without the Smart GWT server, the `Relogin` status codes (such as `STATUS_LOGIN_REQUIRED`) are triggered whenever special markers, such as the loginRequiredMarker, appear in the body of the response. See the `Relogin\n Overview` for details.

    Returns:
      Current status value. Default value is 0
    See Also:
      - `RPCRequest.getReportDownloadErrorsAsDocuments()`

  - ### getTransactionNum

    public Integer getTransactionNum()
    ID of the transaction sent to the server via `RPCManager.sendQueue()` containing the `RPCRequest` associated with this response.
    Returns:
      Current transactionNum value. Default value is null

  - ### create

    public static void create()
    RPCResponses shouldn't be created directly. Instances of this class are automatically created and optionally passed to you in the callback you specify as part of your `RPCRequest`.

  - ### getDataAsMap

    public Map getDataAsMap()
    The data sent by the server.

    When communicating with the SmartClient server, `rpcResponse.data` is the data passed to the server-side method `RPCResponse.setData()` by your Java code. This data is translated into JavaScript objects by the rules described under `rpcRequest.data` in the SmartClient Reference. Simple types (Numeric values, Strings, Dates, Booleans) will be available as their equivalent Java types in your client side GWT code. Complex objects (such as serialized `Map`s or `List`s from the server) will not be automatically translated back into Java on the client - they will arrive as `JavaScriptObject` instances. You can easily convert to the appropriate type yourself using the `JSOHelper` class. The `JSOHelper.convertToJava(JavaScriptObject, boolean)` method performs a recursive conversion of `JavaScriptObject`s returning a `List` (or array) for JavaScript arrays or a `Map` for simple JavaScript objects (key:value pairs).

    When not communicating with the SmartClient server `rpcResponse.data` contains the raw HTTP response body. See `rpcRequest.useSimpleHttp`, rpcRequest.serverOutputAsString, `rpcRequest.evalResult` in the SmartClient Reference for details.

    Returns:
      the data in the RPC response, as a Map
    See Also:
      - `RPCRequest.setData(JavaScriptObject)`
      - `RPCRequest.setData(Map)`
      - `RPCRequest.setData(com.smartgwt.client.data.Record)`
      - `RPCRequest.setData(String)`

  - ### getDataAsString

    public String getDataAsString()
    The data sent by the server.

    When communicating with the SmartClient server, `rpcResponse.data` is the data passed to the server-side method `RPCResponse.setData()` by your Java code. This data is translated into JavaScript objects by the rules described under `rpcRequest.data` in the SmartClient Reference. Simple types (Numeric values, Strings, Dates, Booleans) will be available as their equivalent Java types in your client side GWT code. Complex objects (such as serialized `Map`s or `List`s from the server) will not be automatically translated back into Java on the client - they will arrive as `JavaScriptObject` instances. You can easily convert to the appropriate type yourself using the `JSOHelper` class. The `JSOHelper.convertToJava(JavaScriptObject, boolean)` method performs a recursive conversion of `JavaScriptObject`s returning a `List` (or array) for JavaScript arrays or a `Map` for simple JavaScript objects (key:value pairs).

    When not communicating with the SmartClient server `rpcResponse.data` contains the raw HTTP response body. See `rpcRequest.useSimpleHttp`, rpcRequest.serverOutputAsString, `rpcRequest.evalResult` in the SmartClient Reference for details.

    Returns:
      the data in the RPC response, as a String
    See Also:
      - `RPCRequest.setData(JavaScriptObject)`
      - `RPCRequest.setData(Map)`
      - `RPCRequest.setData(com.smartgwt.client.data.Record)`
      - `RPCRequest.setData(String)`

  - ### getDataAsObject

    public JavaScriptObject getDataAsObject()
    The data sent by the server.

    When communicating with the SmartClient server, `rpcResponse.data` is the data passed to the server-side method `RPCResponse.setData()` by your Java code. This data is translated into JavaScript objects by the rules described under `rpcRequest.data` in the SmartClient Reference. Simple types (Numeric values, Strings, Dates, Booleans) will be available as their equivalent Java types in your client side GWT code. Complex objects (such as serialized `Map`s or `List`s from the server) will not be automatically translated back into Java on the client - they will arrive as `JavaScriptObject` instances. You can easily convert to the appropriate type yourself using the `JSOHelper` class. The `JSOHelper.convertToJava(JavaScriptObject, boolean)` method performs a recursive conversion of `JavaScriptObject`s returning a `List` (or array) for JavaScript arrays or a `Map` for simple JavaScript objects (key:value pairs).

    When not communicating with the SmartClient server `rpcResponse.data` contains the raw HTTP response body. See `rpcRequest.useSimpleHttp`, rpcRequest.serverOutputAsString, `rpcRequest.evalResult` in the SmartClient Reference for details.

    Returns:
      the data in the RPC response, as a JavaScriptObject
    See Also:
      - `RPCRequest.setData(JavaScriptObject)`
      - `RPCRequest.setData(Map)`
      - `RPCRequest.setData(com.smartgwt.client.data.Record)`
      - `RPCRequest.setData(String)`

  - ### isDSResponse

    protected static boolean isDSResponse(JavaScriptObject jsObj)