1212import com .gooddata .md .maintenance .ExportImportService ;
1313import com .gooddata .notification .NotificationService ;
1414import com .gooddata .util .ResponseErrorHandler ;
15+ import com .gooddata .authentication .LoginPasswordAuthentication ;
1516import com .gooddata .warehouse .WarehouseService ;
1617import com .gooddata .dataset .DatasetService ;
1718import com .gooddata .gdc .DataStoreService ;
1819import com .gooddata .gdc .GdcService ;
19- import com .gooddata .http .client .GoodDataHttpClient ;
20- import com .gooddata .http .client .LoginSSTRetrievalStrategy ;
21- import com .gooddata .http .client .SSTRetrievalStrategy ;
2220import com .gooddata .md .MetadataService ;
2321import com .gooddata .model .ModelService ;
2422import com .gooddata .project .ProjectService ;
2523import com .gooddata .report .ReportService ;
26- import org .apache .http .HttpHost ;
2724import org .apache .http .client .HttpClient ;
2825import org .apache .http .client .config .RequestConfig ;
2926import org .apache .http .config .SocketConfig ;
3734
3835import java .util .Arrays ;
3936
40- import static com .gooddata .util .Validate .notEmpty ;
37+ import static com .gooddata .util .Validate .notNull ;
4138import static java .util .Collections .singletonMap ;
4239import static org .apache .http .util .VersionInfo .loadVersionInfo ;
4340
@@ -58,9 +55,9 @@ public class GoodData {
5855
5956 public static final String GDC_REQUEST_ID_HEADER = "X-GDC-REQUEST" ;
6057
61- protected static final String PROTOCOL = "https" ;
62- protected static final int PORT = 443 ;
63- protected static final String HOSTNAME = "secure.gooddata.com" ;
58+ protected static final String PROTOCOL = GoodDataEndpoint . PROTOCOL ;
59+ protected static final int PORT = GoodDataEndpoint . PORT ;
60+ protected static final String HOSTNAME = GoodDataEndpoint . HOSTNAME ;
6461 private static final String UNKNOWN_VERSION = "UNKNOWN" ;
6562
6663 private static final int RESTAPI_VERSION = 1 ;
@@ -167,21 +164,43 @@ public GoodData(String hostname, String login, String password, int port, GoodDa
167164 * @param settings additional settings
168165 */
169166 protected GoodData (String hostname , String login , String password , int port , String protocol , GoodDataSettings settings ) {
170- notEmpty ( hostname , "hostname" );
171- notEmpty ( login , "login" );
172- notEmpty ( password , " password" );
173- notEmpty ( protocol , "protocol" );
174- httpClient = createHttpClient ( login , password , hostname , port , protocol ,
175- createHttpClientBuilder ( settings ));
167+ this (
168+ new GoodDataEndpoint ( hostname , port , protocol ),
169+ new LoginPasswordAuthentication ( login , password ),
170+ settings
171+ );
172+ }
176173
177- restTemplate = createRestTemplate (hostname , httpClient , port , protocol );
174+ /**
175+ * Create instance configured to communicate with GoodData Platform running on given endpoint and using
176+ * given http client factory.
177+ *
178+ * @param endpoint GoodData Platform's endpoint
179+ * @param authentication authentication
180+ */
181+ protected GoodData (GoodDataEndpoint endpoint , Authentication authentication ) {
182+ this (endpoint , authentication , new GoodDataSettings ());
183+ }
184+
185+ /**
186+ * Create instance configured to communicate with GoodData Platform running on given endpoint and using
187+ * given http client factory.
188+ *
189+ * @param endpoint GoodData Platform's endpoint
190+ * @param authentication authentication
191+ * @param settings additional settings
192+ */
193+ protected GoodData (GoodDataEndpoint endpoint , Authentication authentication , GoodDataSettings settings ) {
194+ httpClient = authentication .createHttpClient (endpoint , createHttpClientBuilder (settings ));
195+
196+ restTemplate = createRestTemplate (endpoint , httpClient );
178197
179198 accountService = new AccountService (getRestTemplate ());
180199 projectService = new ProjectService (getRestTemplate (), accountService );
181200 metadataService = new MetadataService (getRestTemplate ());
182201 modelService = new ModelService (getRestTemplate ());
183202 gdcService = new GdcService (getRestTemplate ());
184- dataStoreService = new DataStoreService (getHttpClient (), getRestTemplate (), gdcService , new HttpHost ( hostname , port , protocol ). toURI ());
203+ dataStoreService = new DataStoreService (getHttpClient (), getRestTemplate (), gdcService , endpoint . toUri ());
185204 datasetService = new DatasetService (getRestTemplate (), dataStoreService );
186205 reportService = new ReportService (getRestTemplate ());
187206 processService = new ProcessService (getRestTemplate (), accountService , dataStoreService );
@@ -192,10 +211,16 @@ protected GoodData(String hostname, String login, String password, int port, Str
192211 featureFlagService = new FeatureFlagService (restTemplate );
193212 }
194213
195- private RestTemplate createRestTemplate (String hostname , HttpClient httpClient , int port , String protocol ) {
214+ static RestTemplate createRestTemplate (GoodDataEndpoint endpoint , HttpClient httpClient ) {
215+ notNull (endpoint , "endpoint" );
216+ notNull (httpClient , "httpClient" );
196217
197218 final UriPrefixingClientHttpRequestFactory factory = new UriPrefixingClientHttpRequestFactory (
198- new HttpComponentsClientHttpRequestFactory (httpClient ), hostname , port , protocol );
219+ new HttpComponentsClientHttpRequestFactory (httpClient ),
220+ endpoint .getHostname (),
221+ endpoint .getPort (),
222+ endpoint .getProtocol ()
223+ );
199224 final RestTemplate restTemplate = new RestTemplate (factory );
200225 restTemplate .setInterceptors (Arrays .<ClientHttpRequestInterceptor >asList (
201226 new HeaderSettingRequestInterceptor (singletonMap ("Accept" , getAcceptHeaderValue ()))));
@@ -229,18 +254,10 @@ private HttpClientBuilder createHttpClientBuilder(final GoodDataSettings setting
229254 * Set accept header (application/json by default) and append rest api versioning information which is mandatory
230255 * for some resources.
231256 */
232- private String getAcceptHeaderValue (){
257+ private static String getAcceptHeaderValue (){
233258 return MediaType .APPLICATION_JSON_VALUE + ";version=" + RESTAPI_VERSION ;
234259 }
235260
236- protected HttpClient createHttpClient (final String login , final String password , final String hostname ,
237- final int port , final String protocol , final HttpClientBuilder builder ) {
238- final HttpHost host = new HttpHost (hostname , port , protocol );
239- final HttpClient httpClient = builder .build ();
240- final SSTRetrievalStrategy strategy = new LoginSSTRetrievalStrategy (login , password );
241- return new GoodDataHttpClient (httpClient , host , strategy );
242- }
243-
244261 private String getUserAgent () {
245262 final Package pkg = Package .getPackage ("com.gooddata" );
246263 final String clientVersion = pkg != null && pkg .getImplementationVersion () != null
0 commit comments