From e9515136b5c816e0e0d17552f22f6bde809e4c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9cile=20Chemin?= Date: Thu, 7 Dec 2023 12:54:14 +0100 Subject: [PATCH] [BUG] :goal_net: Catch all LdapException when using mono connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cécile Chemin --- .../sugoi/store/ldap/LdapReaderStore.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/sugoi-api-ldap-store-provider/src/main/java/fr/insee/sugoi/store/ldap/LdapReaderStore.java b/sugoi-api-ldap-store-provider/src/main/java/fr/insee/sugoi/store/ldap/LdapReaderStore.java index 09520620..14c0591f 100644 --- a/sugoi-api-ldap-store-provider/src/main/java/fr/insee/sugoi/store/ldap/LdapReaderStore.java +++ b/sugoi-api-ldap-store-provider/src/main/java/fr/insee/sugoi/store/ldap/LdapReaderStore.java @@ -330,21 +330,18 @@ private PageResult searchOnLdap( try { searchResult = ldapMonoConnection.search(searchRequest); } catch (LDAPException e) { - if (e.getResultCode().intValue() == ResultCode.SERVER_DOWN_INT_VALUE) { - try { - if (Boolean.TRUE.equals( - Boolean.valueOf(config.get(LdapConfigKeys.READ_CONNECTION_AUTHENTICATED)))) { - ldapMonoConnection = LdapFactory.getSingleConnectionAuthenticated(config, true); - } else { - ldapMonoConnection = LdapFactory.getSingleConnection(config, true); - } - } catch (LDAPException e1) { - throw new StoreException("Search failed", e1); + try { + logger.info("Retry connection for error code " + e.getResultCode().intValue()); + if (Boolean.TRUE.equals( + Boolean.valueOf(config.get(LdapConfigKeys.READ_CONNECTION_AUTHENTICATED)))) { + ldapMonoConnection = LdapFactory.getSingleConnectionAuthenticated(config, true); + } else { + ldapMonoConnection = LdapFactory.getSingleConnection(config, true); } - searchResult = ldapMonoConnection.search(searchRequest); - } else { - throw new StoreException("search failed", e); + } catch (LDAPException e1) { + throw new StoreException("Failed to reopen connection", e1); } + searchResult = ldapMonoConnection.search(searchRequest); } PageResult pageResult = new PageResult<>(); pageResult.setResults(