Java
Chilkat2 Java
Adobe Analytics Reporting API (1.4)
See more HTTP Misc Examples
Demonstrates a simple POST of JSON to the Adobe Analytics Reporting API (v1.4)Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Crypt2;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Prng;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// In this example, replace "rsid" with your report suite id, and update the URL to use the correct endpoint
String url = "https://api.omniture.com/admin/1.4/rest/?method=Report.Queue";
JsonObject json = new JsonObject();
json.updateString("reportDescription.reportSuiteID", "rsid");
json.updateString("reportDescription.dateGranularity", "hour");
Http http = new Http();
DateTime dt = new DateTime();
dt.setFromCurrentSystemTime();
String timecreated = dt.getAsTimestamp(false);
Prng prng = new Prng();
String nonce = prng.genRandom(12, "hex");
String secret = "SECRET";
StringBuilder sb = new StringBuilder();
sb.append(nonce);
sb.append(timecreated);
sb.append(secret);
Crypt2 crypt = new Crypt2();
crypt.setHashAlgorithm("sha1");
crypt.setEncodingMode("base64");
String digest = crypt.hashStringENC(sb.getAsString());
StringBuilder sbNonce = new StringBuilder();
sbNonce.append(nonce);
sbNonce.encode("base64", "utf-8");
sb.clear();
sb.append("UsernameToken Username=\"USERNAME\", PasswordDigest=\"");
sb.append(digest);
sb.append("\", Nonce=\"");
sb.append(sbNonce.getAsString());
sb.append("\", Created=\"");
sb.append(timecreated);
sb.append("\"");
System.out.println(sb.getAsString());
http.setRequestHeader("X-WSSE", sb.getAsString());
HttpResponse resp = new HttpResponse();
try {
http.httpJson("POST", url, json, "text/json", resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Http Status code: " + resp.getStatusCode());
System.out.println("JSON response:");
System.out.println(resp.getBodyStr());
}
}