Example usage for org.apache.thrift TDeserializer fromString

List of usage examples for org.apache.thrift TDeserializer fromString

Introduction

In this page you can find the example usage for org.apache.thrift TDeserializer fromString.

Prototype

public void fromString(TBase base, String data) throws TException 

Source Link

Document

Deserialize the Thrift object from a Java string, using the default JVM charset encoding.

Usage

From source file:com.onesite.sdk.api.ApiMethod.java

License:Apache License

/**
 * Call the API via the OnesiteClient and populate the TBase obj. A OnesiteException
 * will be returned if an error occured during deserialization of the TBase obj
 * /*from  ww  w  . ja  v  a 2s .  c o  m*/
 * @param path
 * @param params
 * @param type
 * 
 * @throws Exception
 */
protected void get(String path, Map<String, String> params, TBase obj) throws Exception {
    try {
        this.client.get(path, params);
    } catch (Exception e) {
        log.error("Error occurred during client call to " + path);
        throw e;
    }

    if (this.client.getHttpStatusCode() == HttpStatus.SC_OK) {

        try {
            TDeserializer deserializer = new TDeserializer();
            deserializer.fromString(obj, this.client.getHttpResult());

            Status status = (Status) obj.getFieldValue(obj.fieldForId(1));

            if (status.getCode() != OnesiteResultCode.OK) {
                throw new OnesiteException(status.getCode(), status.getMessage());
            }
        } catch (Exception e) {
            throw new Exception("Error deserializing result ", e);
        }
    } else {
        throw new OnesiteException(this.client.getHttpStatusCode(), this.client.getHttpStatusMessage());
    }
}