Commit 556909f2 authored by Brian Long's avatar Brian Long
Browse files

caching underlying client

parent 6fd42a8d
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -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,9 +81,13 @@ public abstract class Client {
	 * @return A pre-configured JAX-RS target (client w/ base URL) with the specified authorization.
	 */
	public WebTarget getTarget(AuthorizationFilter authFilter) {
		if (authFilter == null) {
			return this.getTarget();
		} else {
			return this.getClient(authFilter)
					.target(this.getConfig().getBaseUrl());
		}
	}
	
	/**
	 * This method retrieves a JAX-RS implementation of the specified API.