Search in sources :

Example 1 with InfoException

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;
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) EnrollmentException(org.hyperledger.fabric_ca.sdk.exception.EnrollmentException) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) JsonReader(javax.json.JsonReader) InfoException(org.hyperledger.fabric_ca.sdk.exception.InfoException) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) JsonObjectBuilder(javax.json.JsonObjectBuilder) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) URISyntaxException(java.net.URISyntaxException) RegistrationException(org.hyperledger.fabric_ca.sdk.exception.RegistrationException) KeyStoreException(java.security.KeyStoreException) AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException) GenerateCRLException(org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException) KeyManagementException(java.security.KeyManagementException) IdentityException(org.hyperledger.fabric_ca.sdk.exception.IdentityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EnrollmentException(org.hyperledger.fabric_ca.sdk.exception.EnrollmentException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) RevocationException(org.hyperledger.fabric_ca.sdk.exception.RevocationException) ParseException(org.apache.http.ParseException) MalformedURLException(java.net.MalformedURLException) InfoException(org.hyperledger.fabric_ca.sdk.exception.InfoException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException)

Aggregations

IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 JsonObject (javax.json.JsonObject)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 JsonReader (javax.json.JsonReader)1 ParseException (org.apache.http.ParseException)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 AffiliationException (org.hyperledger.fabric_ca.sdk.exception.AffiliationException)1 EnrollmentException (org.hyperledger.fabric_ca.sdk.exception.EnrollmentException)1 GenerateCRLException (org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException)1 HTTPException (org.hyperledger.fabric_ca.sdk.exception.HTTPException)1 IdentityException (org.hyperledger.fabric_ca.sdk.exception.IdentityException)1 InfoException (org.hyperledger.fabric_ca.sdk.exception.InfoException)1