use of org.opencastproject.util.JsonVal in project opencast by opencast.
the class OaiPmhRepositoryTest method validate.
private static boolean validate(String verb, XmlGen xmlgen, OaiPmhResponseStatus status) {
logger.info("--- TALKING TO EXTERNAL OAI-PMH VALIDATION SERVICE ---");
logger.info("--- " + VALIDATOR_SERVICE);
final CloseableHttpClient client = HttpClients.createDefault();
final String xml = xmlgen.generateAsString();
final HttpPost post = HttpUtil.post(VALIDATOR_SERVICE, HttpUtil.param("xml", xml));
logger.info("--- REQUEST ---");
logger.info(xml);
try {
final HttpResponse res = client.execute(post);
final String json = withResource(res.getEntity().getContent(), IoSupport.readToString);
logger.info("--- RESPONSE ---");
logger.info(json);
boolean ok = true;
for (JsonVal message : JsonObj.jsonObj(json).obj("json").arr("messages")) {
if (message.isObj()) {
final JsonObj messageObj = message.as(JsonVal.asJsonObj);
if (messageObj.has("className")) {
final String className = messageObj.val("className").as(JsonVal.asString).trim();
final String text = messageObj.val("text").as(JsonVal.asString).trim();
logger.info(format("[%s] %s", className, text));
ok = ok && (eq(className, "correct") || // since the validator does not validate everything correctly here are some exclusions
(status == IsError && eq(text, "Could not find a valid OAI-PMH command."))) || (eq(verb, OaiPmhConstants.VERB_IDENTIFY) && eq(text, "Invalid OAI-PMH protocol version .")) || (eq(verb, OaiPmhConstants.VERB_IDENTIFY) && eq(text, "Invalid adminEmail ."));
}
}
}
return ok;
} catch (Exception e) {
return (Boolean) chuck(e);
} finally {
IoSupport.closeQuietly(client);
}
}
Aggregations