ServiceCall.java [src/java/m/comet/utils] Revision: default  Date:
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API, and application suite.
 *
 * 2012-2017, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package m.comet.utils;

import org.codehaus.jettison.json.JSONObject;

/**
 *
 * @author rumpal
 */
public class ServiceCall {

    private final csip.Client newClient;
    private String error_msg;

    public ServiceCall() {
        this.newClient = new csip.Client();
    }

    public JSONObject getResult(String URI, JSONObject request) {
        JSONObject result = null;

        try {
            result = this.newClient.doPOST(URI, request);
            if ((null == result) || (result.length() <= 0)) {
                this.error_msg += " No data was returned from " + URI + " for this request. ";
            }
        } catch (Exception ex) {
            this.error_msg += " Cannot make a connection to that location: " + URI + ".  " + ex.getMessage();
        }

        return result;
    }

    public String getErrorMsg() {
        return this.error_msg;
    }

    public Boolean isError() {
        return !this.error_msg.isEmpty();
    }
}