Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<properties>
<maven.surefire.report.plugin.version>2.22.2</maven.surefire.report.plugin.version>
<maven.javadoc.plugin.version>2.10.4</maven.javadoc.plugin.version>
<jersey.version>3.1.5</jersey.version>
<jersey.version>3.1.8</jersey.version>
<xml.version>4.0.0</xml.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Expand All @@ -57,6 +57,16 @@
<artifactId>jersey-media-moxy</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.incubator</groupId>
<artifactId>jersey-injectless-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* The Class RestApiClient.
*/
public class RestApiClient {
public class RestApiClient implements AutoCloseable {

/** The rest client. */
private RestClient restClient;
Expand Down Expand Up @@ -766,4 +766,10 @@ private String adjustURL(String url) {
return url;
}

@Override
public void close()
{
this.restClient.close();
}

}
20 changes: 17 additions & 3 deletions src/main/java/org/igniterealtime/restclient/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/**
* The Class RestClient.
*/
public final class RestClient {
public final class RestClient implements AutoCloseable {

/**
* The Constant LOG.
Expand Down Expand Up @@ -84,6 +84,8 @@ public final class RestClient {
*/
private SupportedMediaType mediaType;

private Client client;

/**
* Gets the.
*
Expand Down Expand Up @@ -237,7 +239,7 @@ private WebTarget createWebTarget(String restPath, Map<String, String> queryPara
try {
URI u = new URI(this.baseURI + "/plugins/restapi/v1/" + restPath);
LOG.debug("Connecting to:" + u);
Client client = createRestClient();
Client client = getOrCreateRestClient();

webTarget = client.target(u);
if (queryParams != null && !queryParams.isEmpty()) {
Expand Down Expand Up @@ -276,7 +278,10 @@ private RestClient(RestClientBuilder builder) {
* @throws KeyManagementException the key management exception
* @throws NoSuchAlgorithmException the no such algorithm exception
*/
private Client createRestClient() throws KeyManagementException, NoSuchAlgorithmException {
private Client getOrCreateRestClient() throws KeyManagementException, NoSuchAlgorithmException {
if(this.client != null)
return this.client;

ClientConfig clientConfig = new ClientConfig();
// Set connection timeout
if (this.connectionTimeout != 0) {
Expand All @@ -296,6 +301,8 @@ private Client createRestClient() throws KeyManagementException, NoSuchAlgorithm
client = ClientBuilder.newClient(clientConfig);
}

this.client = client;

return client;
}

Expand Down Expand Up @@ -557,4 +564,11 @@ public SupportedMediaType getMediaType() {
public void setMediaType(SupportedMediaType mediaType) {
this.mediaType = mediaType;
}

@Override
public void close()
{
if(this.client != null)
this.client.close();
}
}