com.jelastic.api.environment.response.ExecResponse Maven / Gradle / Ivy
The newest version!
/*Server class MD5: 66b58787f3b44731f5ba7e164cfe7cf4*/
package com.jelastic.api.environment.response;
import com.jelastic.api.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* @name Jelastic API Client
* @version 8.11.2
* @copyright Jelastic, Inc.
*/
public class ExecResponse extends Response {
public static final String RESULT = "result";
public static final String ERROR = "error";
public static final String RESPONSES = "responses";
private List responses = new ArrayList<>();
public ExecResponse() {
super(OK);
}
public ExecResponse(int result, String error) {
super(result, error);
}
public void addResponse(NodeSSHResponse response) {
responses.add(response);
}
public List getResponses() {
return responses;
}
@Override
public JSONObject toJSON() {
JSONObject json = super.toJSON();
try {
JSONArray jsonArray = new JSONArray();
for (NodeSSHResponse sshResponse : responses) {
jsonArray.put(sshResponse.toJSON());
}
json.put(RESPONSES, jsonArray);
} catch (JSONException e) {
try {
json = new JSONObject();
json.put(RESULT, Response.ERROR_UNKNOWN);
json.put(ERROR, e.toString());
} catch (JSONException e1) {
}
}
return json;
}
@Override
protected ExecResponse _fromJSON(JSONObject json) throws JSONException {
super._fromJSON(json);
if (json.has(RESPONSES)) {
JSONArray jsonArray = json.getJSONArray(RESPONSES);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
responses.add(new NodeSSHResponse()._fromJSON(jsonObject));
}
}
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy