Skip to content

Instantly share code, notes, and snippets.

@resouer
Created May 22, 2014 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save resouer/27ba839831ca43f44c8e to your computer and use it in GitHub Desktop.
Save resouer/27ba839831ca43f44c8e to your computer and use it in GitHub Desktop.
cf-java-client usage example
import org.cloudfoundry.client.lib.CloudCredentials;
import org.cloudfoundry.client.lib.CloudFoundryClient;
import org.cloudfoundry.client.lib.domain.CloudApplication;
import org.cloudfoundry.client.lib.domain.CloudService;
import org.cloudfoundry.client.lib.domain.CloudSpace;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
public final class JavaSample {
public static void main(String[] args) {
String target = args[0];
String user = args[1];
String password = args[2];
CloudCredentials credentials = new CloudCredentials(user, password);
CloudFoundryClient client = new CloudFoundryClient(credentials, getTargetURL(target));
client.login();
System.out.printf("%nSpaces:%n");
for (CloudSpace space : client.getSpaces()) {
System.out.printf(" %s\t(%s)%n", space.getName(), space.getOrganization().getName());
}
System.out.printf("%nApplications:%n");
for (CloudApplication application : client.getApplications()) {
System.out.printf(" %s%n", application.getName());
}
System.out.printf("%nServices%n");
for (CloudService service : client.getServices()) {
System.out.printf(" %s\t(%s)%n", service.getName(), service.getLabel());
}
}
private static URL getTargetURL(String target) {
try {
return URI.create(target).toURL();
} catch (MalformedURLException e) {
throw new RuntimeException("The target URL is not valid: " + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment