diff --git a/src/main/java/sh/libre/scim/core/ScimClient.java b/src/main/java/sh/libre/scim/core/ScimClient.java index 4782b1e079..5831bf3d8c 100644 --- a/src/main/java/sh/libre/scim/core/ScimClient.java +++ b/src/main/java/sh/libre/scim/core/ScimClient.java @@ -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(); } diff --git a/src/main/java/sh/libre/scim/core/ScimDispatcher.java b/src/main/java/sh/libre/scim/core/ScimDispatcher.java index bf7757d7c1..df4e220a3d 100644 --- a/src/main/java/sh/libre/scim/core/ScimDispatcher.java +++ b/src/main/java/sh/libre/scim/core/ScimDispatcher.java @@ -33,13 +33,10 @@ public class ScimDispatcher { public void runOne(ComponentModel m, Consumer 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(); } } }