gooddata / gooddata-http-client

Specialized Java client for handling GoodData authentication

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoodData HTTP Client

Build Status Javadocs Maven Central Release

GoodData HTTP Client is an extension of Apache HTTP Client (former Jakarta Commons). This specialized Java client transparently handles GoodData authentication so you can focus on writing logic on top of GoodData API.

Design

com.gooddata.http.client.GoodDataHttpClient central class implements org.apache.http.client.HttpClient interface It allows seamless switch for existing code base currently using org.apache.http.client.HttpClient. Business logic encapsulating access to GoodData API should use org.apache.http.client.HttpClient interface and keep com.gooddata.http.client.GoodDataHttpClient inside a factory class. com.gooddata.http.client.GoodDataHttpClient uses underlying org.apache.http.client.HttpClient. A HTTP client instance can be passed via the constructor.

Usage

Authentication to GoodData is supported by credentials or Super Secure Token.

If your project is managed by Maven you can add GoodData HTTP client as a new dependency otherwise you have to download binary and add manually.

Maven

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

Authentication using credentials

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(login, password);

HttpClient client = new GoodDataHttpClient(HttpClientBuilder.create().build(), hostGoodData, sstStrategy);

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

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

Authentication using super-secure token (SST)

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

// create HTTP client
HttpClient httpClient = HttpClientBuilder.create().build();

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

// create login strategy (you must somehow obtain SST)
SSTRetrievalStrategy sstStrategy = new SimpleSSTRetrievalStrategy("my super-secure token");

// wrap your HTTP client into GoodData HTTP client
HttpClient client = new GoodDataHttpClient(httpClient, hostGoodData, sstStrategy);

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

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

Build

mvn package

Unit tests

mvn test

Acceptance tests (with real backend)

mvn -P at clean verify -DGDC_LOGIN=user@email.com -DGDC_PASSWORD=password [-DGDC_BACKEND=<backend host>]

Test coverage

One can check test coverage report in coveralls.io.

Notice

GoodData Corporation provides this software "as-is" under conditions specified in the license.

About

Specialized Java client for handling GoodData authentication

License:Other


Languages

Language:Java 100.0%