View Javadoc

1   package com.atlassian.asap.api.exception;
2   
3   import com.atlassian.asap.core.validator.ValidatedKeyId;
4   
5   import javax.annotation.Nonnull;
6   import javax.annotation.Nullable;
7   import java.net.URI;
8   import java.util.Optional;
9   
10  /**
11   * Thrown when a cryptographic key is not available.
12   */
13  public class CannotRetrieveKeyException extends Exception {
14      /**
15       * The validated key ID used to try to retrieve the key. May be {@code null}
16       */
17      @Nullable
18      private final transient ValidatedKeyId keyId;
19  
20      @Nullable
21      private final URI keyUri;
22  
23      public CannotRetrieveKeyException(String reason) {
24          this(reason, (URI) null);
25      }
26  
27      public CannotRetrieveKeyException(String reason, URI keyUri) {
28          this(reason, (ValidatedKeyId) null, keyUri);
29      }
30  
31      public CannotRetrieveKeyException(String reason, ValidatedKeyId keyId, URI keyUri) {
32          super(reason);
33          this.keyId = keyId;
34          this.keyUri = keyUri;
35      }
36  
37      public CannotRetrieveKeyException(String message, Throwable cause) {
38          this(message, cause, null);
39      }
40  
41      public CannotRetrieveKeyException(String message, Throwable cause, URI keyUri) {
42          this(message, cause, null, keyUri);
43      }
44  
45      protected CannotRetrieveKeyException(String message, Throwable cause, ValidatedKeyId keyId, URI keyUri) {
46          super(message, cause);
47          this.keyId = keyId;
48          this.keyUri = keyUri;
49      }
50  
51      @Nonnull
52      public final Optional<ValidatedKeyId> getKeyId() {
53          return Optional.ofNullable(keyId);
54      }
55  
56      @Nonnull
57      public final Optional<URI> getKeyUri() {
58          return Optional.ofNullable(keyUri);
59      }
60  }