Skip to content

Commit 07ae3d1

Browse files
committed
AUT-2511 Collect failed retry results
1 parent 0c29658 commit 07ae3d1

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/main/java/eu/webeid/resilientocsp/ResilientOcspCertificateRevocationChecker.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,20 @@ public List<RevocationInfo> validateCertificateNotRevoked(X509Certificate subjec
115115
CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker(ocspService.getAccessLocation().toASCIIString());
116116

117117
List<RevocationInfo> revocationInfoList = new ArrayList<>();
118-
circuitBreaker.getEventPublisher().onError(event -> {
119-
Throwable throwable = event.getThrowable();
120-
if (throwable instanceof ResilientUserCertificateOCSPCheckFailedException e) {
121-
revocationInfoList.addAll(e.getValidationInfo().revocationInfoList());
122-
return;
123-
}
124-
revocationInfoList.add(new RevocationInfo(null, Map.ofEntries(
125-
Map.entry(RevocationInfo.KEY_OCSP_ERROR, throwable)
126-
)));
127-
});
118+
circuitBreaker.getEventPublisher().onError(event -> createAndAddRevocationInfoToList(event.getThrowable(), revocationInfoList));
128119

129120
CheckedFunction0<RevocationInfo> primarySupplier = () -> request(ocspService, subjectCertificate, issuerCertificate, false);
130121
CheckedFunction0<RevocationInfo> fallbackSupplier = () -> request(ocspService.getFallbackService(), subjectCertificate, issuerCertificate, true);
131122
Decorators.DecorateCheckedSupplier<RevocationInfo> decorateCheckedSupplier = Decorators.ofCheckedSupplier(primarySupplier);
132123
if (retryRegistry != null) {
133124
Retry retry = retryRegistry.retry(ocspService.getAccessLocation().toASCIIString());
125+
retry.getEventPublisher().onError(event -> {
126+
Throwable throwable = event.getLastThrowable();
127+
if (throwable == null) {
128+
return;
129+
}
130+
createAndAddRevocationInfoToList(throwable, revocationInfoList);
131+
});
134132
decorateCheckedSupplier.withRetry(retry);
135133
}
136134
decorateCheckedSupplier.withCircuitBreaker(circuitBreaker)
@@ -159,6 +157,16 @@ public List<RevocationInfo> validateCertificateNotRevoked(X509Certificate subjec
159157
return revocationInfoList;
160158
}
161159

160+
private void createAndAddRevocationInfoToList(Throwable throwable, List<RevocationInfo> revocationInfoList) {
161+
if (throwable instanceof ResilientUserCertificateOCSPCheckFailedException exception) {
162+
revocationInfoList.addAll((exception.getValidationInfo().revocationInfoList()));
163+
return;
164+
}
165+
revocationInfoList.add(new RevocationInfo(null, Map.ofEntries(
166+
Map.entry(RevocationInfo.KEY_OCSP_ERROR, throwable)
167+
)));
168+
}
169+
162170
private RevocationInfo request(OcspService ocspService, X509Certificate subjectCertificate, X509Certificate issuerCertificate, boolean allowThisUpdateInPast) throws ResilientUserCertificateOCSPCheckFailedException, ResilientUserCertificateRevokedException {
163171
URI ocspResponderUri = null;
164172
OCSPResp response = null;

0 commit comments

Comments
 (0)