caching underlying client
This commit is contained in:
@@ -15,13 +15,21 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
|
||||
*/
|
||||
public abstract class Client {
|
||||
|
||||
private final Object sync = new Object();
|
||||
private javax.ws.rs.client.Client client;
|
||||
|
||||
protected abstract ClientConfiguration getConfig();
|
||||
|
||||
/**
|
||||
* @return A pre-configured JAX-RS client (no URL) with configured authorization.
|
||||
*/
|
||||
public final javax.ws.rs.client.Client getClient() {
|
||||
return this.getClient(null);
|
||||
synchronized (this.sync) {
|
||||
if (this.client == null)
|
||||
this.client = this.buildClient(null);
|
||||
}
|
||||
|
||||
return this.client;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,6 +37,18 @@ public abstract class Client {
|
||||
* @return A pre-configured JAX-RS client (no URL) with the specified authorization.
|
||||
*/
|
||||
public javax.ws.rs.client.Client getClient(AuthorizationFilter authFilter) {
|
||||
if (authFilter == null) {
|
||||
return this.getClient();
|
||||
} else {
|
||||
return this.buildClient(authFilter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authFilter A dynamic authorization filter.
|
||||
* @return A pre-configured JAX-RS client (no URL) with the specified authorization.
|
||||
*/
|
||||
public javax.ws.rs.client.Client buildClient(AuthorizationFilter authFilter) {
|
||||
JacksonJsonProvider provider = new JacksonJaxbJsonProvider();
|
||||
|
||||
if (this.getConfig().isWrapRootValueEnabled())
|
||||
@@ -52,7 +72,8 @@ public abstract class Client {
|
||||
* @return A pre-configured JAX-RS target (client w/ base URL) with configured authorization.
|
||||
*/
|
||||
public final WebTarget getTarget() {
|
||||
return this.getTarget(null);
|
||||
return this.getClient()
|
||||
.target(this.getConfig().getBaseUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,8 +81,12 @@ public abstract class Client {
|
||||
* @return A pre-configured JAX-RS target (client w/ base URL) with the specified authorization.
|
||||
*/
|
||||
public WebTarget getTarget(AuthorizationFilter authFilter) {
|
||||
return this.getClient(authFilter)
|
||||
.target(this.getConfig().getBaseUrl());
|
||||
if (authFilter == null) {
|
||||
return this.getTarget();
|
||||
} else {
|
||||
return this.getClient(authFilter)
|
||||
.target(this.getConfig().getBaseUrl());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user