Search in sources :

Example 11 with HTTPException

use of org.hyperledger.fabric_ca.sdk.exception.HTTPException in project fabric-sdk-java by hyperledger.

the class HFCAIdentity method update.

/**
 * update an identity
 *
 * @param registrar The identity of the registrar (i.e. who is performing the registration).
 * @return statusCode The HTTP status code in the response
 * @throws IdentityException    if adding an identity fails.
 * @throws InvalidArgumentException Invalid (null) argument specified
 */
public int update(User registrar) throws IdentityException, InvalidArgumentException {
    if (this.deleted) {
        throw new IdentityException("Identity has been deleted");
    }
    if (registrar == null) {
        throw new InvalidArgumentException("Registrar should be a valid member");
    }
    String updateURL = "";
    try {
        updateURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId());
        logger.debug(format("identity  url: %s, registrar: %s", updateURL, registrar.getName()));
        String body = client.toJson(idToJsonObject());
        JsonObject result = client.httpPut(updateURL, body, registrar);
        statusCode = result.getInt("statusCode");
        if (statusCode < 400) {
            getHFCAIdentity(result);
            logger.debug(format("identity  url: %s, registrar: %s done.", updateURL, registrar));
        }
        return statusCode;
    } catch (HTTPException e) {
        String msg = format("[Code: %d] - Error while updating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), updateURL, e.getMessage());
        IdentityException identityException = new IdentityException(msg, e);
        logger.error(msg);
        throw identityException;
    } catch (Exception e) {
        String msg = format("Error while updating user '%s' from url '%s':  %s", getEnrollmentId(), updateURL, e.getMessage());
        IdentityException identityException = new IdentityException(msg, e);
        logger.error(msg);
        throw identityException;
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) JsonObject(javax.json.JsonObject) IdentityException(org.hyperledger.fabric_ca.sdk.exception.IdentityException) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) IdentityException(org.hyperledger.fabric_ca.sdk.exception.IdentityException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException)

Aggregations

JsonObject (javax.json.JsonObject)11 HTTPException (org.hyperledger.fabric_ca.sdk.exception.HTTPException)11 AffiliationException (org.hyperledger.fabric_ca.sdk.exception.AffiliationException)10 InvalidArgumentException (org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException)10 IdentityException (org.hyperledger.fabric_ca.sdk.exception.IdentityException)6 HashMap (java.util.HashMap)3 JsonArray (javax.json.JsonArray)3 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2 ArrayList (java.util.ArrayList)2 ParseException (org.apache.http.ParseException)2 EnrollmentException (org.hyperledger.fabric_ca.sdk.exception.EnrollmentException)2 GenerateCRLException (org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException)2