Java
Chilkat2 Java
SugarCRM Logout
See more SugarCRM Examples
Demonstrates how to logout of a session.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
boolean success = false;
Rest rest = new Rest();
try {
rest.connect("your.site.domain", 443, true, true);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
rest.addHeader("Cache-Control", "no-cache");
rest.addHeader("OAuth-Token", "<access_token>");
StringBuilder sbReq = new StringBuilder();
StringBuilder sbJson = new StringBuilder();
try {
rest.fullRequestSb("POST", "/rest/v10/oauth2/logout", sbReq, sbJson);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
if (rest.getResponseStatusCode() != 200) {
System.out.println("Received error response code: " + rest.getResponseStatusCode());
System.out.println("Response body:");
System.out.println(sbJson.getAsString());
return;
}
JsonObject json = new JsonObject();
json.loadSb(sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
success = json.boolOf("success");
// A sample JSON response body that is parsed by the above code:
// {
// "success": true
// }
System.out.println("Example Completed.");
}
}