All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jelastic.api.response.ScriptEvalProxyResponse Maven / Gradle / Ivy

There is a newer version: 8.12-1
Show newest version
/*Server class MD5: ddcbffc42dc7f28c5ad4f8f8e4aa91a9*/
package com.jelastic.api.response;

import com.jelastic.api.Response;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * @name Jelastic API Client
 * @version 8.11.2
 * @copyright Jelastic, Inc.
 */
public class ScriptEvalProxyResponse extends Response {

    private static final String SCRIPT_RESPONSE_KEY = "response";

    private int result = -1;

    private String error = null;

    private Object response = null;

    private Object debugTimes = null;

    public ScriptEvalProxyResponse() {
    }

    public ScriptEvalProxyResponse(int result, String error) {
        super(result, error);
    }

    public Object getResponse() {
        return response;
    }

    public void setResponse(Object response) {
        this.response = response;
    }

    public Object getDebugTimes() {
        return debugTimes;
    }

    public void setDebugTimes(Object debugTimes) {
        this.debugTimes = debugTimes;
    }

    protected JSONObject _toJSON(JSONObject json) throws JSONException {
        return json;
    }

    @Override
    public JSONObject toJSON() {
        JSONObject json = null;
        try {
            Object response = getResponse();
            if (response instanceof JSONObject) {
                json = _toJSON((JSONObject) response);
            } else {
                json = _toJSON(super.toJSON());
            }
        } catch (JSONException ex) {
            ex.printStackTrace();
            try {
                json = new JSONObject().put("result", ERROR_UNKNOWN).put("error", ex.toString());
            } catch (JSONException exc) {
            }
        }
        return json;
    }

    @Override
    public ScriptEvalProxyResponse _fromJSON(JSONObject json) throws JSONException {
        this.fromJSONObject(json);
        if (json.has(SCRIPT_RESPONSE_KEY) && !JSONObject.NULL.equals(json.get(SCRIPT_RESPONSE_KEY))) {
            Object response = json.get(SCRIPT_RESPONSE_KEY);
            setResponse(response);
            if (response instanceof JSONObject) {
                JSONObject responseJson = (JSONObject) response;
                if (responseJson.has("result")) {
                    setResult(responseJson.getInt("result"));
                }
                if (responseJson.has("error")) {
                    setError(responseJson.getString("error"));
                }
            }
        } else {
            setResponse(json);
        }
        return this;
    }

    private Response fromJSONObject(JSONObject json) throws JSONException {
        super._fromJSON(json);
        if (json.has("response")) {
            this.response = json.get("response");
        }
        if (json.has("debugTimes")) {
            this.debugTimes = json.get("debugTimes");
        }
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy