use of org.olat.modules.gotomeeting.model.GoToErrorG2T in project openolat by klemens.
the class GoToJsonUtil method parseError.
/*
{"errorCode":"DuplicateRegistrant","description":"Registration failed, email address already in use.","incident":3437843380023983360,"registrantKey":3019527584166801154} ^%^ cause:n/a
*/
protected static final GoToErrorG2T parseError(String content) {
try {
JSONObject json = new JSONObject(content);
GoToErrorG2T error = new GoToErrorG2T();
error.setErrorCode(GoToErrors.valueOfOrNull(json.optString("errorCode", null)));
error.setDescription(json.optString("description", null));
error.setRegistrantKey(json.optString("registrantKey", null));
return error;
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of org.olat.modules.gotomeeting.model.GoToErrorG2T in project openolat by klemens.
the class GoToMeetingManagerImpl method logGoToError.
private void logGoToError(String method, HttpResponse response, GoToError error) throws IOException {
int status = response.getStatusLine().getStatusCode();
error.setErrorCode(status);
String responseString = EntityUtils.toString(response.getEntity());
try {
GoToErrorG2T errorVo = GoToJsonUtil.parseError(responseString);
if (errorVo != null) {
error.setError(errorVo.getErrorCode());
error.setDescription(errorVo.getDescription());
}
} catch (Exception e) {
log.error("", e);
} finally {
EntityUtils.consumeQuietly(response.getEntity());
log.error(method + " return " + status + ": " + responseString);
}
}
use of org.olat.modules.gotomeeting.model.GoToErrorG2T in project openolat by klemens.
the class GoToMeetingManagerImpl method registerTraining.
/**
* Error code: 400 (Bad Request), 403 (Forbidden), 404 (Not Found), 409 (Conflict)
*/
@Override
public GoToRegistrant registerTraining(GoToMeeting meeting, Identity trainee, GoToError error) {
GoToRegistrant registrant = registrantDao.getRegistrant(meeting, trainee);
if (registrant == null) {
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
GoToOrganizer organizer = meeting.getOrganizer();
String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey() + "/registrants";
HttpPost post = new HttpPost(url);
post.addHeader("Accept", "application/json");
post.addHeader("Authorization", "OAuth oauth_token=" + organizer.getAccessToken());
post.addHeader("Content-type", "application/json");
String traineeJson = GoToJsonUtil.registrant(trainee).toString();
post.setEntity(new StringEntity(traineeJson, ContentType.APPLICATION_JSON));
HttpResponse response = httpClient.execute(post);
int status = response.getStatusLine().getStatusCode();
if (status == 201) {
// created
String content = EntityUtils.toString(response.getEntity());
GoToRegistrantG2T registrantVo = GoToJsonUtil.parseAddRegistrant(content);
registrant = registrantDao.createRegistrant(meeting, trainee, registrantVo.getRegistrantKey(), registrantVo.getJoinUrl(), registrantVo.getConfirmationUrl());
} else if (status == 409) {
String content = EntityUtils.toString(response.getEntity());
GoToErrorG2T errorVo = GoToJsonUtil.parseError(content);
if (errorVo.getErrorCode() == GoToErrors.DuplicateRegistrant && StringHelper.containsNonWhitespace(errorVo.getRegistrantKey())) {
// already registrate but not in OpenOLAT
GoToRegistrantG2T registrantVo = getRegistrant(errorVo.getRegistrantKey(), meeting, error);
registrant = registrantDao.createRegistrant(meeting, trainee, registrantVo.getRegistrantKey(), registrantVo.getJoinUrl(), registrantVo.getConfirmationUrl());
} else {
logGoToError("registerTraining", status, content, error);
}
} else {
logGoToError("registerTraining", response, error);
}
} catch (Exception e) {
log.error("", e);
}
}
return registrant;
}
Aggregations