GoodData Java HTTP Client

You can implement a functionality on the top of the GoodData API using Java (Groovy or Scala).

For example, you can use the GoodData API to list all your workspaces. To do so, you must authenticate. You can use a "raw format” handling authentication token in cookies (we have two of them), or you can use the GoodData HTTP Client to handle the complete authentication process.

The following example shows how to get a list of your workspace using the GoodData HTTP Client.

How it Works

Download the HTTP Client and install it with all dependencies.

If you use Maven, use the 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. You can use:

  • Credentials, or
  • SST token.

The following code example uses credentials for the 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()));

You can use the code with any API resource that is available using Java GET or POST methods. See the API Reference for other available API calls.

In GoodData, project is synonymous with workspace.



Powered by Atlassian Confluence and Scroll Viewport.