Use try with resource

This commit is contained in:
Brendan Le Ny 2024-06-17 10:34:45 +02:00
parent 10ff5787f0
commit db3de0d933
2 changed files with 3 additions and 5 deletions

View file

@ -28,7 +28,7 @@ import java.util.HashMap;
import java.util.Map;
public class ScimClient {
public class ScimClient implements AutoCloseable {
private static final Logger LOGGER = Logger.getLogger(ScimClient.class);
@ -299,6 +299,7 @@ public class ScimClient {
}
}
@Override
public void close() {
scimRequestBuilder.close();
}

View file

@ -33,13 +33,10 @@ public class ScimDispatcher {
public void runOne(ComponentModel m, Consumer<ScimClient> f) {
LOGGER.infof("%s %s %s %s", m.getId(), m.getName(), m.getProviderId(), m.getProviderType());
ScimClient client = ScimClient.newScimClient(m, session);
try {
try (ScimClient client = ScimClient.newScimClient(m, session)) {
f.accept(client);
} catch (Exception e) {
LOGGER.error(e);
} finally {
client.close();
}
}
}