Skip to content

Commit 25a4049

Browse files
committed
also open make requests to absolute URLs
1 parent 8b2e9cd commit 25a4049

File tree

7 files changed

+35
-8
lines changed

7 files changed

+35
-8
lines changed

backend/src/main/java/de/learnlib/alex/data/entities/actions/rest/CallAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public enum Method {
8484
private Method method;
8585

8686
/**
87-
* The url to call. This is just the suffix which will be appended to the base url.
87+
* The url to call.
88+
* The URL can either be a path relative to the project's base URL or a absolute URL that starts with https?://
8889
*/
8990
@NotBlank
9091
private String url;

backend/src/main/java/de/learnlib/alex/data/entities/actions/web/GotoAction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public class GotoAction extends WebSymbolAction {
4545

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

48-
/** The URL of the site. */
48+
/**
49+
* The URL of the site.
50+
* The URL can either be a path relative to the project's base URL or a absolute URL that starts with https?://
51+
*/
4952
@NotBlank
5053
private String url;
5154

backend/src/main/java/de/learnlib/alex/learning/services/BaseUrlManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ public String getAbsoluteUrl(String path) {
7878
*/
7979
public String getAbsoluteUrl(String path, Credentials credentials) {
8080
String url = combineUrls(baseUrl, path);
81+
return BaseUrlManager.getUrlWithCredentials(url, credentials);
82+
}
83+
84+
public static String getUrlWithCredentials(String url, Credentials credentials) {
8185
if (credentials != null && credentials.areValid()) {
82-
url = url.replaceFirst("^(http[s]?://)", "$1"
86+
return url.replaceFirst("^(http[s]?://)", "$1"
8387
+ credentials.getName() + ":"
8488
+ credentials.getPassword() + "@");
89+
} else {
90+
return url;
8591
}
86-
return url;
8792
}
8893

8994
/**

backend/src/main/java/de/learnlib/alex/learning/services/connectors/WebServiceConnector.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import javax.ws.rs.core.MultivaluedMap;
2828
import javax.ws.rs.core.NewCookie;
2929
import javax.ws.rs.core.Response;
30+
import java.net.MalformedURLException;
31+
import java.net.URL;
3032
import java.util.Map;
3133
import java.util.Set;
3234

@@ -281,7 +283,14 @@ private void followRedirects(Response response) {
281283
private Invocation.Builder getRequestObject(String path, Map<String, String> requestHeaders,
282284
Set<Cookie> requestCookies, int timeout) {
283285
final String[] splitPath = path.split("\\?");
284-
WebTarget tmpTarget = target.path(splitPath[0]);
286+
287+
WebTarget tmpTarget;
288+
try {
289+
new URL(path);
290+
tmpTarget = client.target(splitPath[0]);
291+
} catch (MalformedURLException e) {
292+
tmpTarget = target.path(splitPath[0]);
293+
}
285294

286295
if (splitPath.length > 1) {
287296
for (final String queryParam : splitPath[1].split("&")) {

backend/src/main/java/de/learnlib/alex/learning/services/connectors/WebSiteConnector.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.openqa.selenium.WebDriver;
3131
import org.openqa.selenium.WebElement;
3232

33+
import java.net.MalformedURLException;
34+
import java.net.URL;
3335
import java.util.List;
3436
import java.util.concurrent.TimeUnit;
3537

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

129-
final String url = baseUrl.getAbsoluteUrl(path, credentials);
131+
String url;
132+
try {
133+
new URL(path);
134+
url = BaseUrlManager.getUrlWithCredentials(path, credentials);
135+
} catch (MalformedURLException e) {
136+
url = baseUrl.getAbsoluteUrl(path, credentials);
137+
}
138+
130139
int numRetries = 0;
131140
while (numRetries < MAX_RETRIES) {
132141
try {

frontend/src/main/javascript/src/js/components/forms/actions/rest/request-action-form/request-action-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h5><strong>Make request</strong></h5>
22

3-
<p class="text-muted">Make a HTTP request to a URL (relative to your projects default URL).</p>
3+
<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>
44
<hr>
55

66
<div class="form-group">

frontend/src/main/javascript/src/js/components/forms/actions/web/open-url-action-form/open-url-action-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h5><strong>Open URL</strong></h5>
22

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

0 commit comments

Comments
 (0)