Skip to content

Non-Mandatory Proxy Auth Params #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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