// Path: java/src/org/drupal/project/computing/exception/DConfigException.java
// public class DConfigException extends Exception {
//     public DConfigException() {
//     }
// 
//     public DConfigException(String s) {
//         super(s);
//     }
// 
//     public DConfigException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DConfigException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: java/src/org/drupal/project/computing/exception/DSiteException.java
// public class DSiteException extends Exception {
//     public DSiteException() {
//         super();
//     }
// 
//     public DSiteException(String s) {
//         super(s);
//     }
// 
//     public DSiteException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DSiteException(Throwable throwable) {
//         super(throwable);
//     }
// 
//     /**
//      * The error code is arbitrary by the caller which sets it.
//      */
//     private int errorCode = 0;
// 
//     public int getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(int errorCode) {
//         this.errorCode = errorCode;
//     }
// 
// }


import com.google.gson.JsonParseException;
import org.apache.commons.lang3.StringUtils;
import org.drupal.project.computing.exception.DConfigException;
import org.drupal.project.computing.exception.DSiteException;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.Properties;
import java.util.logging.Logger;
     * @return the DRestfulJsonServices object.
     * @throws DConfigException
     */
    public static DRestfulJsonServices loadDefault() throws DConfigException {
        DConfig config = DConfig.loadDefault();
        String baseUrl = config.getProperty("dcomp.site.base_url", "");
        String endpoint = config.getProperty("dcomp.services.endpoint", "");
        String userName = config.getProperty("dcomp.services.user.name", "");
        String userPass = config.getProperty("dcomp.services.user.pass", "");

        if (StringUtils.isNotBlank(baseUrl) && StringUtils.isNotBlank(endpoint) && StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(userPass)) {
            return new DRestfulJsonServices(baseUrl, endpoint, userName, userPass);
        } else {
            throw new DConfigException("Access Drupal Services configuration error.");
        }
    }


    /**
     * High level API to make HTTP request and get response in JSON.
     *
     * @param directive Services command, such as CRUD, Actions, Targeted Actions, etc.
     * @param params Data to send in HTTP request.
     * @param method HTTP Request method, e.g. GET, POST, DELETE, etc.
     *
     * @return arsed JSON object, either null, or a Primitive, or a List, or a Bindings.
     * @throws IllegalArgumentException
     * @throws DSiteException
     * @see org.drupal.project.computing.DUtils.Json
     */
// Path: java/src/org/drupal/project/computing/exception/DConfigException.java
// public class DConfigException extends Exception {
//     public DConfigException() {
//     }
// 
//     public DConfigException(String s) {
//         super(s);
//     }
// 
//     public DConfigException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DConfigException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: java/src/org/drupal/project/computing/exception/DSiteException.java
// public class DSiteException extends Exception {
//     public DSiteException() {
//         super();
//     }
// 
//     public DSiteException(String s) {
//         super(s);
//     }
// 
//     public DSiteException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DSiteException(Throwable throwable) {
//         super(throwable);
//     }
// 
//     /**
//      * The error code is arbitrary by the caller which sets it.
//      */
//     private int errorCode = 0;
// 
//     public int getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(int errorCode) {
//         this.errorCode = errorCode;
//     }
// 
// }


// Path: java/src/org/drupal/project/computing/DRestfulJsonServices.java
import com.google.gson.JsonParseException;
import org.apache.commons.lang3.StringUtils;
import org.drupal.project.computing.exception.DConfigException;
import org.drupal.project.computing.exception.DSiteException;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.Properties;
import java.util.logging.Logger;

     * @return the DRestfulJsonServices object.
     * @throws DConfigException
     */
    public static DRestfulJsonServices loadDefault() throws DConfigException {
        DConfig config = DConfig.loadDefault();
        String baseUrl = config.getProperty("dcomp.site.base_url", "");
        String endpoint = config.getProperty("dcomp.services.endpoint", "");
        String userName = config.getProperty("dcomp.services.user.name", "");
        String userPass = config.getProperty("dcomp.services.user.pass", "");

        if (StringUtils.isNotBlank(baseUrl) && StringUtils.isNotBlank(endpoint) && StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(userPass)) {
            return new DRestfulJsonServices(baseUrl, endpoint, userName, userPass);
        } else {
            throw new DConfigException("Access Drupal Services configuration error.");
        }
    }


    /**
     * High level API to make HTTP request and get response in JSON.
     *
     * @param directive Services command, such as CRUD, Actions, Targeted Actions, etc.
     * @param params Data to send in HTTP request.
     * @param method HTTP Request method, e.g. GET, POST, DELETE, etc.
     *
     * @return arsed JSON object, either null, or a Primitive, or a List, or a Bindings.
     * @throws IllegalArgumentException
     * @throws DSiteException
     * @see org.drupal.project.computing.DUtils.Json
     */
    public Object request(String directive, Bindings params, String method) throws IllegalArgumentException, DSiteException {