Skip to content

Commit

Permalink
Merge pull request #8 from rchougule/master
Browse files Browse the repository at this point in the history
Non-Mandatory Proxy Auth Params
  • Loading branch information
francisf authored Dec 28, 2020
2 parents ef2cbd5 + 7f5ce9e commit 5a29a3b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# automate-client-java

## For Code formatting
Code style files are there in code_formatters folder (for eclipse and intellij idea) ,to import formatter instructions are as follows :
* For Eclipse : Under Window/Preferences select Java/Code Style/Formatter. Import the settings file by selecting Import.
* For IntelliJ Idea : Settings → Code Style → Java, click Manage, and import that XML file by simply clicking Import.
<p align="center">
<a href="https://browserstack.com"><img alt="BrowserStack Logo" src="https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-invoice.svg"></a>
</p>

Java Package to seamlessly connect with Automate and App-Automate.

## Features
1. Operations on Projects, Builds & Sessions
2. Upload App for App-Automate
3. Account Usage
4. Reset Key

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.browserstack</groupId>
<artifactId>automate-client-java</artifactId>
<name>automate-client</name>
<version>0.6</version>
<version>0.7</version>
<packaging>jar</packaging>
<description>Java bindings for BrowserStack Automate REST API</description>
<url>https://www.browserstack.com</url>
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/com/browserstack/client/BrowserStackClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,25 @@ static HttpRequest newRequest(final HttpRequestFactory requestFactory, final Met

public void setProxy(final String proxyHost, final int proxyPort, final String proxyUsername, final String proxyPassword) {

if (proxyHost == null || proxyUsername == null || proxyPassword == null) {
if (proxyHost == null || proxyPort == 0) {
return;
}

final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
final AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
UsernamePasswordCredentials proxyAuthentication =
new UsernamePasswordCredentials(proxyUsername, proxyPassword);
basicCredentialsProvider.setCredentials(proxyAuthScope, proxyAuthentication);

final HttpHost proxy = new HttpHost(proxyHost, proxyPort);
final HttpClient client = HttpClientBuilder.create().setProxy(proxy).setDefaultCredentialsProvider(basicCredentialsProvider).build();
final ApacheHttpTransport transport = new ApacheHttpTransport(client);
this.HTTP_TRANSPORT = transport;
HttpClientBuilder clientBuilder = HttpClientBuilder.create().setProxy(proxy);

if (proxyUsername != null && proxyUsername.length() != 0 && proxyPassword != null && proxyPassword.length() != 0) {
final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
final AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
UsernamePasswordCredentials proxyAuthentication =
new UsernamePasswordCredentials(proxyUsername, proxyPassword);
basicCredentialsProvider.setCredentials(proxyAuthScope, proxyAuthentication);

clientBuilder.setDefaultCredentialsProvider(basicCredentialsProvider);
}

final HttpClient client = clientBuilder.build();
HTTP_TRANSPORT = new ApacheHttpTransport(client);
this.requestFactory = newRequestFactory();
}

Expand Down

0 comments on commit 5a29a3b

Please sign in to comment.