Skip to content

Commit

Permalink
#176: Moved requestControls before seach and nullify in try-catch-fin…
Browse files Browse the repository at this point in the history
…ally.
  • Loading branch information
abpai94 committed Nov 12, 2024
1 parent 64e3dac commit 00c6653
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/lsc/jndi/JndiServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ private void initConnection()
throw new NamingException(e.getMessage());
}

// Setting global pageSize and sortedBy variable
contextRequestControls();

String recursiveDeleteStr = (String) ctx.getEnvironment().get("java.naming.recursivedelete");
if (recursiveDeleteStr != null) {
recursiveDelete = Boolean.parseBoolean(recursiveDeleteStr);
Expand Down Expand Up @@ -741,6 +738,7 @@ private List<String> doGetDnList(final String base, final String filter,
NamingEnumeration<SearchResult> ne = null;
List<String> list = new ArrayList<String>();
try {
contextRequestControls();
SearchControls sc = new SearchControls();
sc.setDerefLinkFlag(false);
sc.setReturningAttributes(new String[]{"1.1"});
Expand All @@ -758,14 +756,15 @@ private List<String> doGetDnList(final String base, final String filter,
}
pagedResultsResponse = pagination();
} while (pagedResultsResponse != null);
contextRequestControls();
} catch (NamingException e) {
LOGGER.error(e.toString());
LOGGER.debug(e.toString(), e);
throw e;
} catch (IOException e) {
LOGGER.error(e.toString());
LOGGER.debug(e.toString(), e);
} finally {
ctx.setRequestControls(null);
}
return list;
}
Expand Down Expand Up @@ -1138,6 +1137,7 @@ public Map<String, LscDatasets> doGetAttrsList(final String base,
constraints.setReturningObjFlag(true);
try {
byte[] pagedResultsResponse;
contextRequestControls();
do {
NamingEnumeration<SearchResult> results = ctx.search(searchBase, searchFilter, constraints);

Expand All @@ -1162,18 +1162,18 @@ public Map<String, LscDatasets> doGetAttrsList(final String base,

pagedResultsResponse = pagination();
} while (pagedResultsResponse != null);
contextRequestControls();
} catch (CommunicationException e) {
}
catch (CommunicationException e) {
// Avoid handling the communication exception as a generic one
throw e;
} catch (ServiceUnavailableException e) {
// Avoid handling the service unavailable exception as a generic one
throw e;
} catch (NamingException | IOException e) {
// clear requestControls for future use of the JNDI context
contextRequestControls();
LOGGER.error(e.toString());
LOGGER.debug(e.toString(), e);
} finally {
ctx.setRequestControls(null);
}
return res;
}
Expand Down

0 comments on commit 00c6653

Please sign in to comment.