Skip to content

Commit

Permalink
also open make requests to absolute URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
abainczyk committed Jul 24, 2019
1 parent 8b2e9cd commit 25a4049
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public enum Method {
private Method method;

/**
* The url to call. This is just the suffix which will be appended to the base url.
* The url to call.
* The URL can either be a path relative to the project's base URL or a absolute URL that starts with https?://
*/
@NotBlank
private String url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public class GotoAction extends WebSymbolAction {

private static final Logger LOGGER = LogManager.getLogger();

/** The URL of the site. */
/**
* The URL of the site.
* The URL can either be a path relative to the project's base URL or a absolute URL that starts with https?://
*/
@NotBlank
private String url;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ public String getAbsoluteUrl(String path) {
*/
public String getAbsoluteUrl(String path, Credentials credentials) {
String url = combineUrls(baseUrl, path);
return BaseUrlManager.getUrlWithCredentials(url, credentials);
}

public static String getUrlWithCredentials(String url, Credentials credentials) {
if (credentials != null && credentials.areValid()) {
url = url.replaceFirst("^(http[s]?://)", "$1"
return url.replaceFirst("^(http[s]?://)", "$1"
+ credentials.getName() + ":"
+ credentials.getPassword() + "@");
} else {
return url;
}
return url;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NewCookie;
import javax.ws.rs.core.Response;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -281,7 +283,14 @@ private void followRedirects(Response response) {
private Invocation.Builder getRequestObject(String path, Map<String, String> requestHeaders,
Set<Cookie> requestCookies, int timeout) {
final String[] splitPath = path.split("\\?");
WebTarget tmpTarget = target.path(splitPath[0]);

WebTarget tmpTarget;
try {
new URL(path);
tmpTarget = client.target(splitPath[0]);
} catch (MalformedURLException e) {
tmpTarget = target.path(splitPath[0]);
}

if (splitPath.length > 1) {
for (final String queryParam : splitPath[1].split("&")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -126,7 +128,14 @@ public void get(String path, Credentials credentials) throws Exception {
this.driver = driverConfig.createDriver();
}

final String url = baseUrl.getAbsoluteUrl(path, credentials);
String url;
try {
new URL(path);
url = BaseUrlManager.getUrlWithCredentials(path, credentials);
} catch (MalformedURLException e) {
url = baseUrl.getAbsoluteUrl(path, credentials);
}

int numRetries = 0;
while (numRetries < MAX_RETRIES) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h5><strong>Make request</strong></h5>

<p class="text-muted">Make a HTTP request to a URL (relative to your projects default URL).</p>
<p class="text-muted">Make a HTTP request to a URL that is either relative to your project's base URL or an absolute one.</p>
<hr>

<div class="form-group">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h5><strong>Open URL</strong></h5>

<p class="text-muted">
Open a URL that is <strong>relative</strong> to your projects' base URL
Open a URL that is either relative to your projects' base URL or an absolute one.
</p>
<hr>

Expand Down

0 comments on commit 25a4049

Please sign in to comment.