Java client library and tools for Cloud Foundry
Java Other
Clone or download
Pull request Compare This branch is 2339 commits behind cloudfoundry:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Cloud Foundry Java Client

The cf-java-client project is a Java language binding for interacting with a Cloud Foundry instance. The project is broken up into a number of components which expose different levels of abstraction depending on need.

  • cloudfoundry-client – Interfaces, request, and response objects mapping to the Cloud Foundry REST APIs. This project has no implementation and therefore cannot connect a Cloud Foundry instance on its own.
  • cloudfoundry-client-spring – The default implementation of the cloudfoundry-client project. This implementation is based on the Spring Framework RestTemplate.
  • cloudfoundry-operations – An API and implementation that corresponds to the Cloud Foundry CLI operations. This project builds on the cloudfoundry-cli and therefore has a single implementation.
  • cloudfoundry-maven-plugin / cloudfoundry-gradle-plugin – Build plugins for Maven and Gradle. These projects build on cloudfoundry-operations and therefore have single implementations.

Most projects will need two dependencies; the Operations API and an implementation of the Client API. For Maven, the dependencies would be defined like this:


The artifacts can be found in the Spring release and snapshot repositories:

        <name>Spring Releases</name>
        <name>Spring Snapshots</name>

For Gradle, the dependencies would be defined like this:

dependencies {
    compile "org.cloudfoundry:cloudfoundry-client-spring:$cfJavaClientVersion"
    compile "org.cloudfoundry:cloudfoundry-operations:$cfJavaClientVersion"

The artifacts can be found in the Spring release and snapshot repositories:

repositories {
    maven { url "" }
repositories {
    maven { url "" }


Both the cloudfoundry-operations and cloudfoundry-client projects follow a "Reactive" design pattern and expose their responses with Reactive Streams Publishers. The choice to expose Reactive Streams Publishers gives the project interoperability with the various reactive framework implementations such as Project Reactor and RxJava. In the examples that follow, Project Reactor is used, but all reactive frameworks work similarly.

CloudFoundryClient and CloudFoundryOperations Builders

The lowest-level building block of the API is a CloudFoundryClient. This is only an interface and the default implementation of this is the SpringCloudFoundryClient. To instantiate one, you configure it with a builder:


In Spring-based applications, you'll want to encapsulate this in a bean definition:

CloudFoundryClient cloudFoundryClient(@Value("${}") String host,
                                      @Value("${cf.username}") String username,
                                      @Value("${cf.password}") String password) {
    return SpringCloudFoundryClient.builder()

The CloudFoundryClient provides direct access to the raw REST APIs. This level of abstraction provides the most detailed and powerful access to the Cloud Foundry instance, but also requires users to perform quite a lot of orchestration on their own. Most users will instead want to work at the CloudFoundryOperations layer. Once again this is only an interface and the default implementation of this is the DefaultCloudFoundryOperations. To instantiate one, you configure it with a builder:

new CloudFoundryOperationsBuilder()
    .target("example-organization", "example-space")

In Spring-based applications, you'll want to encapsulate this in a bean definition as well:

CloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient,
                                              @Value("${cf.organization}") String organization,
                                              @Value("${}") String space) {
    return new CloudFoundryOperationsBuilder()
            .target(organization, space)

CloudFoundryOperations APIs

Once you've got a reference to the CloudFoundryOperations, it's time to start making calls to the Cloud Foundry instance. One of the simplest possible operations is list all of the organizations the user is a member of. The following example does three things:

  1. Requests a list of all organizations
  2. Extracts the name of each organization
  3. Prints the name of the each organization to System.out

To relate the example to the description above the following happens:

  1. Streams.wrap(...) – Wraps the Reactive Streams Publisher (an interoperability type) in the Reactor-native Stream type
  2. .map(...) – Maps an input type to an output type. This example uses a method a reference and the equivalent lambda would look like organization -> organization.getName().
  3. consume... – The terminal operation that consumes each item in the stream. Again, this example uses a method reference and the the equivalent lambda would look like name -> System.out.println(name).

CloudFoundryClient APIs

As mentioned earlier, the cloudfoundry-operations implementation builds upon the cloudfoundry-client API. That implementation takes advantage of the same reactive style in the lower-level API. The implementation of the Organizations.list() method (which was demonstrated above) looks like the following (roughly):

ListOrganizationsRequest request = ListOrganizationsRequest.builder()

    .flatMap(response -> Streams.from(response.getResources))
    .map(resource -> {
        return Organization.builder()

The above example is more complicated:

  1. Streams.wrap(...) – Wraps the Reactive Streams Publisher in the Reactor-native Stream type
  2. .flatMap(...) – substitutes the original stream with a stream of the Resources returned by the requested page
  3. .map(...) – Maps the Resource to an Organization type

Maven Plugin

TODO: Document once implemented

Gradle Plugin

TODO: Document once implemented


The project depends on Java 8 but is built to be Java 7 compatible. To build from source and install to your local Maven cache, run the following:

$ ./mvnw clean install

To run the the integration tests, run the following:

$ ./mvnw -Pintegration-test clean test

IMPORTANT Integration tests should be run against an empty Cloud Foundry instance. The integration tests are destructive, nearly everything on an instance given the chance.

The integration tests require a running instance of Cloud Foundry to test against. We recommend using MicroPCF to start a local instance to test with. To configure the integration tests with the appropriate connection information use the following environment variables:

Name Description
TEST_HOST The host of Cloud Foundry instance. Typically something like
TEST_ORGANIZATION The default organization to use for testing
TEST_PASSWORD The test user's password
TEST_SKIPSSLVALIDATION Whether to skip SSL validation when connecting to the Cloud Foundry instance. Typically true when connecting to a MicroPCF instance.
TEST_SPACE The default space to use for testing
TEST_USERNAME The test user's username


Pull requests and Issues are welcome.


This project is released under version 2.0 of the Apache License.