Page tree
Skip to end of metadata
Go to start of metadata

This article describes the tools that will help you to implement a functionality on the top of the GoodData API using Java (Groovy or Scala).

You are starting with integration implementation and would need to list all your projects. You can use our API capability. But once you start there is authentication to overcome. You can do it in "raw format” handling authentication token (we have two of them) in cookies, or you can use the GoodData HTTP Client that will handle the complete authentication process.

To understand the process better, see the following example. We already mentioned the goal - to get a list of your Projects. This should be pretty easy task.

How it Works

First of all, download the HTTP Client and install it with all dependencies. If you use Maven, use following:

<dependency>
<groupId>com.gooddata</groupId>
<artifactId>gooddata-http-client</artifactId>
<version>${gdc.http.client.version}</version>
<dependency>

There are two types of authentication options. The first one is to use credentials, the second one is to use SST token for authentication. Check out the following code example using credentials authentication:

import com.gooddata.http.client.*
import java.io.IOException;
import org.apache.http.*;

HttpHost hostGoodData = new HttpHost("secure.gooddata.com", 443, "https");

// create login strategy, which will obtain SST via credentials
SSTRetrievalStrategy sstStrategy = 
new LoginSSTRetrievalStrategy(new DefaultHttpClient(),hostGoodData login, password);

HttpClient client = new GoodDataHttpClient(new DefaultHttpClient(), sstStrategy);

// use HTTP client with transparent GoodData authentication
HttpGet getProject = new HttpGet("/gdc/md/");
getProject.addHeader("Accept", ContentType.APPLICATION_JSON.getMimeType());
HttpResponse getProjectResponse = client.execute(hostGoodData, getProject);

System.out.println(EntityUtils.toString(getProjectResponse.getEntity()));

Run the code and see the printed result. You can use it with whatever API resource that is available using Java GET or POST methods. See the API documentation for other available API calls.