Java
Chilkat2 Java
RSAP Union API - Get Members Status
See more _Miscellaneous_ Examples
Demonstrates how to use an OAuth2 access token for the RSAP Union API. Calls the endpoint to get the statuses of all union members.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.PrivateKey;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Http http = new Http();
// Load the access token previously obtained by this example: RSAP Union OAuth2
JsonObject jToken = new JsonObject();
try {
jToken.loadFile("qa_data/tokens/rsapToken.json");
} catch (ChilkatException e) {
System.out.println("Failed to load access token JSON.");
return;
}
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.setAuthToken(jToken.stringOf("access_token"));
// For authentication, assuming both the client cert and access token are needed???
Cert cert = new Cert();
try {
cert.loadFromFile("qa_data/certs_and_keys/union_client_certificate.crt");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
PrivateKey privKey = new PrivateKey();
try {
privKey.loadAnyFormatFile("qa_data/certs_and_keys/union_client_certificate.nopass.key", "");
// Associate the private key with the cert.
// This will fail if the private key is not actually the correct one that corresponds to the public key stored within the cert.
cert.setPrivateKey(privKey);
// Tell HTTP to use the cert for client TLS certificate authentication.
http.setSslClientCert(cert);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
StringBuilder sbResponseBody = new StringBuilder();
try {
http.quickGetSb("https://api-test.rsap.ca/members/status", sbResponseBody);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
JsonObject jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.setEmitCompact(false);
System.out.println("Response Body:");
System.out.println(jResp.emit());
int respStatusCode = http.getLastStatus();
System.out.println("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
System.out.println("Response Header:");
System.out.println(http.getLastHeader());
System.out.println("Failed.");
return;
}
}
}