From 19bebf4019d918fb01fb2b5acefc860bd32b649b Mon Sep 17 00:00:00 2001 From: Rohan Chougule Date: Fri, 18 Dec 2020 02:46:01 +0530 Subject: [PATCH 1/6] fix: non-mandatory proxy auth params --- pom.xml | 2 +- .../client/BrowserStackClient.java | 25 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 72f61e5..1974197 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.browserstack automate-client-java automate-client - 0.6 + 0.7 jar Java bindings for BrowserStack Automate REST API https://www.browserstack.com diff --git a/src/main/java/com/browserstack/client/BrowserStackClient.java b/src/main/java/com/browserstack/client/BrowserStackClient.java index 1da8817..575c918 100644 --- a/src/main/java/com/browserstack/client/BrowserStackClient.java +++ b/src/main/java/com/browserstack/client/BrowserStackClient.java @@ -33,6 +33,7 @@ import org.apache.http.impl.client.HttpClientBuilder; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -155,20 +156,26 @@ static HttpRequest newRequest(final HttpRequestFactory requestFactory, final Met * @param proxyPassword password of the proxy */ - public void setProxy(final String proxyHost, final int proxyPort, final String proxyUsername, final String proxyPassword) { + public void setProxy(@Nonnull final String proxyHost, @Nonnull final int proxyPort, @Nullable final String proxyUsername, @Nullable 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(); + 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 = clientBuilder.setDefaultCredentialsProvider(basicCredentialsProvider); + } + + final HttpClient client = clientBuilder.build(); final ApacheHttpTransport transport = new ApacheHttpTransport(client); this.HTTP_TRANSPORT = transport; this.requestFactory = newRequestFactory(); From fb091fb28c981609b4f462e865922cd782a44993 Mon Sep 17 00:00:00 2001 From: Rohan Chougule Date: Fri, 18 Dec 2020 02:53:19 +0530 Subject: [PATCH 2/6] update: README --- README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5527748..a78c36e 100644 --- a/README.md +++ b/README.md @@ -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. +

+ BrowserStack Logo +

+ +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 + From 9672f9afc438eba3d8144dc4a716b3e129ae57f0 Mon Sep 17 00:00:00 2001 From: Rohan Chougule Date: Fri, 18 Dec 2020 14:12:41 +0530 Subject: [PATCH 3/6] refactor: stale local variables --- .../java/com/browserstack/client/BrowserStackClient.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/browserstack/client/BrowserStackClient.java b/src/main/java/com/browserstack/client/BrowserStackClient.java index 575c918..2418534 100644 --- a/src/main/java/com/browserstack/client/BrowserStackClient.java +++ b/src/main/java/com/browserstack/client/BrowserStackClient.java @@ -172,12 +172,11 @@ public void setProxy(@Nonnull final String proxyHost, @Nonnull final int proxyPo new UsernamePasswordCredentials(proxyUsername, proxyPassword); basicCredentialsProvider.setCredentials(proxyAuthScope, proxyAuthentication); - clientBuilder = clientBuilder.setDefaultCredentialsProvider(basicCredentialsProvider); + clientBuilder.setDefaultCredentialsProvider(basicCredentialsProvider); } final HttpClient client = clientBuilder.build(); - final ApacheHttpTransport transport = new ApacheHttpTransport(client); - this.HTTP_TRANSPORT = transport; + this.HTTP_TRANSPORT = new ApacheHttpTransport(client); this.requestFactory = newRequestFactory(); } From 60e19b156adca67d71abc3040f79d8f912bccfad Mon Sep 17 00:00:00 2001 From: Rohan Chougule Date: Fri, 18 Dec 2020 14:18:24 +0530 Subject: [PATCH 4/6] remove: annotations for manual handling of null values --- src/main/java/com/browserstack/client/BrowserStackClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/browserstack/client/BrowserStackClient.java b/src/main/java/com/browserstack/client/BrowserStackClient.java index 2418534..ef65cf5 100644 --- a/src/main/java/com/browserstack/client/BrowserStackClient.java +++ b/src/main/java/com/browserstack/client/BrowserStackClient.java @@ -156,7 +156,7 @@ static HttpRequest newRequest(final HttpRequestFactory requestFactory, final Met * @param proxyPassword password of the proxy */ - public void setProxy(@Nonnull final String proxyHost, @Nonnull final int proxyPort, @Nullable final String proxyUsername, @Nullable final String proxyPassword) { + public void setProxy(final String proxyHost, final int proxyPort, final String proxyUsername, final String proxyPassword) { if (proxyHost == null || proxyPort == 0) { return; From 10c0c3da7d60e38e28c0965480509326885585f5 Mon Sep 17 00:00:00 2001 From: Rohan Chougule Date: Fri, 18 Dec 2020 14:20:48 +0530 Subject: [PATCH 5/6] fix: accessing static variable using 'this' in instance method --- src/main/java/com/browserstack/client/BrowserStackClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/browserstack/client/BrowserStackClient.java b/src/main/java/com/browserstack/client/BrowserStackClient.java index ef65cf5..5c5ce94 100644 --- a/src/main/java/com/browserstack/client/BrowserStackClient.java +++ b/src/main/java/com/browserstack/client/BrowserStackClient.java @@ -176,7 +176,7 @@ public void setProxy(final String proxyHost, final int proxyPort, final String p } final HttpClient client = clientBuilder.build(); - this.HTTP_TRANSPORT = new ApacheHttpTransport(client); + HTTP_TRANSPORT = new ApacheHttpTransport(client); this.requestFactory = newRequestFactory(); } From 7f5ce9e1fe0d34005ad4d99989b24d0cf160fccc Mon Sep 17 00:00:00 2001 From: Rohan Chougule Date: Fri, 18 Dec 2020 14:22:35 +0530 Subject: [PATCH 6/6] stale: removed stale import --- src/main/java/com/browserstack/client/BrowserStackClient.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/browserstack/client/BrowserStackClient.java b/src/main/java/com/browserstack/client/BrowserStackClient.java index 5c5ce94..cc0ff7d 100644 --- a/src/main/java/com/browserstack/client/BrowserStackClient.java +++ b/src/main/java/com/browserstack/client/BrowserStackClient.java @@ -33,7 +33,6 @@ import org.apache.http.impl.client.HttpClientBuilder; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.IOException; import java.io.InputStream; import java.io.Reader;