BugFix (#944): Add HTTP prefix to URLs in RestApiPlugin and RapidApiPlugin (#1266)

Also, add null check before adding HTTP prefix. This avoids null pointer exceptions and lets the UriBuilder deal with it
This commit is contained in:
João Rafael 2020-10-19 03:49:04 -03:00 committed by GitHub
parent c085fc778d
commit 85d5477039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -58,7 +58,7 @@ Appsmith doesn't take the fun out of coding, because it treats every block as an
* **5 minute setup**: Deploy Appsmith on your servers in 5 minutes.
* **Build custom UI**: Drag & drop, resize and style widgets **without HTML / CSS**.
* **Query data**: Query & update your database directly from the UI. Connect to **PostgreSQL, MongoDB, MySQL, REST & GraphQL APIs**.
* **JS Logic**: Write snippets of business logic using JS to transform data, manipuate UI or trigger workflows. Use popular libraries like lodash & moment anywhere in the app
* **JS Logic**: Write snippets of business logic using JS to transform data, manipulate UI or trigger workflows. Use popular libraries like lodash & moment anywhere in the app
* **Data Workflows**: Simple configuration to create flows when users interact with the UI.
* **Realtime Editor**: Changes in your application reflect instantly with every edit. No need to compile!
* **Works with existing, live databases**: Connect directly to any PostgreSQL, MySQL & MongoDB

View File

@ -103,7 +103,8 @@ public class RapidApiPlugin extends BasePlugin {
URI uri;
try {
uri = createFinalUriWithQueryParams(url, actionConfiguration.getQueryParameters());
String httpUrl = addHttpToUrlWhenPrefixNotPresent(url);
uri = createFinalUriWithQueryParams(httpUrl, actionConfiguration.getQueryParameters());
log.info("Final URL is : {}", uri);
} catch (URISyntaxException e) {
e.printStackTrace();
@ -287,6 +288,13 @@ public class RapidApiPlugin extends BasePlugin {
}
}
private String addHttpToUrlWhenPrefixNotPresent(String url) {
if (url == null || url.toLowerCase().startsWith("http") || url.contains("://")) {
return url;
}
return "http://" + url;
}
private URI createFinalUriWithQueryParams(String url, List<Property> queryParams) throws URISyntaxException {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.newInstance();
uriBuilder.uri(new URI(url));

View File

@ -81,7 +81,8 @@ public class RestApiPlugin extends BasePlugin {
HttpMethod httpMethod = actionConfiguration.getHttpMethod();
URI uri;
try {
uri = createFinalUriWithQueryParams(url, actionConfiguration.getQueryParameters());
String httpUrl = addHttpToUrlWhenPrefixNotPresent(url);
uri = createFinalUriWithQueryParams(httpUrl, actionConfiguration.getQueryParameters());
} catch (URISyntaxException e) {
ActionExecutionRequest actionExecutionRequest = populateRequestFields(actionConfiguration, null);
actionExecutionRequest.setUrl(url);
@ -362,6 +363,13 @@ public class RestApiPlugin extends BasePlugin {
return contentType;
}
private String addHttpToUrlWhenPrefixNotPresent(String url) {
if (url == null || url.toLowerCase().startsWith("http") || url.contains("://")) {
return url;
}
return "http://" + url;
}
private URI createFinalUriWithQueryParams(String url, List<Property> queryParams) throws URISyntaxException {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.newInstance();
uriBuilder.uri(new URI(url));