cloudfoundry/cf-java-client — pull request #188 by scottfrederick (2014-06-06 17:56:05+00:00)
Title: Refactored token management into OauthClient.

This change moves all the responsibility of Oauth token management from `CloudControllerClientImpl` to `OauthClient`. This makes it possible for code other than `CloudControllerClientImpl` to access the token and build an authorization header for a REST request, at the expense of adding state to `OauthClient`.

This change also makes it possible to construct a `CloudFoundryClient` in such a way that it is possible to re-use the `RestTemplate` and `OauthClient` used by `CloudFoundryClient` in other code. To take advantage of this, you would replace code like this:

CloudFoundryClient client = new CloudFoundryClient(credentials, cloudControllerUrl, orgName, spaceName, httpProxyConfiguration, trustSelfSignedCerts);

with code like this:

CloudControllerClientFactory clientFactory =
new CloudControllerClientFactory(httpProxyConfiguration, trustSelfSignedCerts);
CloudControllerClient cc = clientFactory.newCloudController(cloudControllerUrl, credentials, orgName, spaceName);

CloudFoundryClient client = new CloudFoundryClient(cc);

// access the same RestTemplate and OauthClient that CloudControllerClient will use
RestTemplate restTemplate = clientFactory.getRestTemplate();
OauthClient oauthClient = clientFactory.getOauthClient();