use of org.hyperledger.fabric_ca.sdk.exception.InfoException in project fabric-sdk-java by hyperledger.
the class HFCAClient method info.
/**
* Return information on the Fabric Certificate Authority.
* No credentials are needed for this API.
*
* @return {@link HFCAInfo}
* @throws InfoException
* @throws InvalidArgumentException
*/
public HFCAInfo info() throws InfoException, InvalidArgumentException {
logger.debug(format("info url:%s", url));
if (cryptoSuite == null) {
throw new InvalidArgumentException("Crypto primitives not set.");
}
setUpSSL();
try {
JsonObjectBuilder factory = Json.createObjectBuilder();
if (caName != null) {
factory.add(HFCAClient.FABRIC_CA_REQPROP, caName);
}
JsonObject body = factory.build();
String responseBody = httpPost(url + HFCA_INFO, body.toString(), (UsernamePasswordCredentials) null);
logger.debug("response:" + responseBody);
JsonReader reader = Json.createReader(new StringReader(responseBody));
JsonObject jsonst = (JsonObject) reader.read();
boolean success = jsonst.getBoolean("success");
logger.debug(format("[HFCAClient] enroll success:[%s]", success));
if (!success) {
throw new EnrollmentException(format("FabricCA failed info %s", url));
}
JsonObject result = jsonst.getJsonObject("result");
if (result == null) {
throw new InfoException(format("FabricCA info error - response did not contain a result url %s", url));
}
String caName = result.getString("CAName");
String caChain = result.getString("CAChain");
String version = null;
if (result.containsKey("Version")) {
version = result.getString("Version");
}
return new HFCAInfo(caName, caChain, version);
} catch (Exception e) {
InfoException ee = new InfoException(format("Url:%s, Failed to get info", url), e);
logger.error(e.getMessage(), e);
throw ee;
}
}
Aggregations