All outgoing requests should go through the configured proxy (#14427)

Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
This commit is contained in:
Shrikant Sharat Kandula 2022-09-01 11:16:45 +05:30 committed by GitHub
parent 6bed5a3b7a
commit 8a0838505a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 138 additions and 131 deletions

View File

@ -32,11 +32,6 @@
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
@ -129,11 +124,25 @@
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-http</artifactId>
<version>1.0.17</version>
<exclusions>
<exclusion>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,45 @@
package com.appsmith.util;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;
public class WebClientUtils {
private WebClientUtils() {
}
public static WebClient create() {
return builder()
.build();
}
public static WebClient create(String baseUrl) {
return builder()
.baseUrl(baseUrl)
.build();
}
private static boolean shouldUseSystemProxy() {
return "true".equals(System.getProperty("java.net.useSystemProxies"))
&& (!System.getProperty("http.proxyHost", "").isEmpty() || !System.getProperty("https.proxyHost", "").isEmpty());
}
public static WebClient.Builder builder() {
return builder(HttpClient.create());
}
public static WebClient.Builder builder(HttpClient httpClient) {
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(applyProxyIfConfigured(httpClient)));
}
private static HttpClient applyProxyIfConfigured(HttpClient httpClient) {
if (shouldUseSystemProxy()) {
httpClient = httpClient.proxyWithSystemProperties();
}
return httpClient;
}
}

View File

@ -161,13 +161,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>0.9.4.RELEASE</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -3,6 +3,7 @@ package com.external.config;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.OAuth2;
import com.appsmith.util.WebClientUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpMethod;
@ -33,7 +34,7 @@ public class FileInfoMethod implements ExecutionMethod, TriggerMethod {
@Override
public Mono<Object> executePrerequisites(MethodConfig methodConfig, OAuth2 oauth2) {
WebClient client = WebClient.builder()
WebClient client = WebClientUtils.builder()
.exchangeStrategies(EXCHANGE_STRATEGIES)
.build();
UriComponentsBuilder uriBuilder = getBaseUriBuilder(this.BASE_SHEETS_API_URL,

View File

@ -4,6 +4,7 @@ import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.OAuth2;
import com.appsmith.util.WebClientUtils;
import com.external.constants.FieldName;
import com.external.domains.RowObject;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -82,7 +83,7 @@ public class RowsAppendMethod implements ExecutionMethod, TemplateMethod {
@Override
public Mono<Object> executePrerequisites(MethodConfig methodConfig, OAuth2 oauth2) {
WebClient client = WebClient.builder()
WebClient client = WebClientUtils.builder()
.exchangeStrategies(EXCHANGE_STRATEGIES)
.build();
final RowsGetMethod rowsGetMethod = new RowsGetMethod(this.objectMapper);

View File

@ -3,6 +3,7 @@ package com.external.config;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.OAuth2;
import com.appsmith.util.WebClientUtils;
import com.external.domains.RowObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
@ -82,7 +83,7 @@ public class RowsBulkAppendMethod implements ExecutionMethod {
*/
@Override
public Mono<Object> executePrerequisites(MethodConfig methodConfig, OAuth2 oauth2) {
WebClient client = WebClient.builder()
WebClient client = WebClientUtils.builder()
.exchangeStrategies(EXCHANGE_STRATEGIES)
.build();
final RowsGetMethod rowsGetMethod = new RowsGetMethod(this.objectMapper);

View File

@ -3,6 +3,7 @@ package com.external.config;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.OAuth2;
import com.appsmith.util.WebClientUtils;
import com.external.domains.RowObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
@ -77,7 +78,7 @@ public class RowsBulkUpdateMethod implements ExecutionMethod {
@Override
public Mono<Object> executePrerequisites(MethodConfig methodConfig, OAuth2 oauth2) {
WebClient client = WebClient.builder()
WebClient client = WebClientUtils.builder()
.exchangeStrategies(EXCHANGE_STRATEGIES)
.build();
final RowsGetMethod rowsGetMethod = new RowsGetMethod(this.objectMapper);

View File

@ -3,6 +3,7 @@ package com.external.config;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.OAuth2;
import com.appsmith.util.WebClientUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpMethod;
@ -71,7 +72,7 @@ public class RowsDeleteMethod implements ExecutionMethod, TemplateMethod {
@Override
public Mono<Object> executePrerequisites(MethodConfig methodConfig, OAuth2 oauth2) {
WebClient client = WebClient.builder()
WebClient client = WebClientUtils.builder()
.exchangeStrategies(EXCHANGE_STRATEGIES)
.build();
UriComponentsBuilder uriBuilder = getBaseUriBuilder(this.BASE_SHEETS_API_URL,

View File

@ -4,6 +4,7 @@ import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.OAuth2;
import com.appsmith.util.WebClientUtils;
import com.external.constants.FieldName;
import com.external.domains.RowObject;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -73,7 +74,7 @@ public class RowsUpdateMethod implements ExecutionMethod, TemplateMethod {
@Override
public Mono<Object> executePrerequisites(MethodConfig methodConfig, OAuth2 oauth2) {
WebClient client = WebClient.builder()
WebClient client = WebClientUtils.builder()
.exchangeStrategies(EXCHANGE_STRATEGIES)
.build();
final RowsGetMethod rowsGetMethod = new RowsGetMethod(this.objectMapper);

View File

@ -3,6 +3,7 @@ package com.external.config;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.OAuth2;
import com.appsmith.util.WebClientUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
@ -42,7 +43,7 @@ public class SheetDeleteMethod implements ExecutionMethod {
@Override
public Mono<Object> executePrerequisites(MethodConfig methodConfig, OAuth2 oauth2) {
WebClient client = WebClient.builder()
WebClient client = WebClientUtils.builder()
.exchangeStrategies(EXCHANGE_STRATEGIES)
.build();
UriComponentsBuilder uriBuilder = getBaseUriBuilder(this.BASE_SHEETS_API_URL,

View File

@ -16,6 +16,7 @@ import com.appsmith.external.models.TriggerResultDTO;
import com.appsmith.external.plugins.BasePlugin;
import com.appsmith.external.plugins.PluginExecutor;
import com.appsmith.external.plugins.SmartSubstitutionInterface;
import com.appsmith.util.WebClientUtils;
import com.external.config.ExecutionMethod;
import com.external.config.GoogleSheetsMethodStrategy;
import com.external.config.MethodConfig;
@ -157,12 +158,10 @@ public class GoogleSheetsPlugin extends BasePlugin {
// Convert unreadable map to a DTO
MethodConfig methodConfig = new MethodConfig(formData);
// Initializing webClient to be used for http call
WebClient.Builder webClientBuilder = WebClient.builder();
executionMethod.validateExecutionMethodRequest(methodConfig);
WebClient client = webClientBuilder
// Initializing webClient to be used for http call
WebClient client = WebClientUtils.builder()
.exchangeStrategies(EXCHANGE_STRATEGIES)
.build();
@ -388,4 +387,4 @@ public class GoogleSheetsPlugin extends BasePlugin {
templateMethod.replaceMethodConfigTemplate(formData, mappedColumns);
}
}
}
}

View File

@ -24,7 +24,6 @@ import java.util.Map;
import static com.appsmith.external.helpers.PluginUtils.STRING_TYPE;
import static com.appsmith.external.helpers.PluginUtils.setDataValueSafelyInFormData;
import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static com.external.plugins.constants.FieldName.AGGREGATE;
import static com.external.plugins.constants.FieldName.AGGREGATE_LIMIT;
import static com.external.plugins.constants.FieldName.AGGREGATE_PIPELINES;
@ -33,6 +32,7 @@ import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION;
import static com.external.plugins.utils.MongoPluginUtils.parseSafely;
import static org.apache.commons.lang3.StringUtils.isBlank;
@Getter
@Setter

View File

@ -22,9 +22,9 @@ import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.COUNT;
import static com.external.plugins.constants.FieldName.COUNT_QUERY;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION;
import static com.external.plugins.utils.MongoPluginUtils.parseSafely;
import static org.apache.commons.lang3.StringUtils.isBlank;
@Getter
@Setter

View File

@ -23,9 +23,9 @@ import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.DISTINCT;
import static com.external.plugins.constants.FieldName.DISTINCT_KEY;
import static com.external.plugins.constants.FieldName.DISTINCT_QUERY;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION;
import static com.external.plugins.utils.MongoPluginUtils.parseSafely;
import static org.apache.commons.lang3.StringUtils.isBlank;
@Getter
@Setter

View File

@ -27,8 +27,8 @@ import static com.external.plugins.constants.FieldName.FIND_QUERY;
import static com.external.plugins.constants.FieldName.FIND_SKIP;
import static com.external.plugins.constants.FieldName.FIND_SORT;
import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static com.external.plugins.utils.MongoPluginUtils.parseSafely;
import static org.apache.commons.lang3.StringUtils.isBlank;
@Getter
@Setter
@ -219,4 +219,4 @@ public class Find extends MongoCommand {
return sb.toString();
}
}
}

View File

@ -31,8 +31,8 @@ import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.INSERT;
import static com.external.plugins.constants.FieldName.INSERT_DOCUMENT;
import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static com.external.plugins.utils.MongoPluginUtils.parseSafely;
import static org.apache.commons.lang3.StringUtils.isBlank;
@Getter
@Setter
@ -158,4 +158,4 @@ public class Insert extends MongoCommand {
return sb.toString();
}
}
}

View File

@ -73,12 +73,6 @@
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>mysql</groupId>

View File

@ -9,6 +9,7 @@ import com.appsmith.external.models.DatasourceTestResult;
import com.appsmith.external.models.Property;
import com.appsmith.external.plugins.BasePlugin;
import com.appsmith.external.plugins.PluginExecutor;
import com.appsmith.util.WebClientUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.bson.internal.Base64;
@ -76,7 +77,7 @@ public class RapidApiPlugin extends BasePlugin {
"set."));
}
WebClient.Builder webClientBuilder = WebClient.builder();
WebClient.Builder webClientBuilder = WebClientUtils.builder();
if (datasourceConfiguration.getHeaders() != null) {
addHeadersToRequest(webClientBuilder, datasourceConfiguration.getHeaders());

View File

@ -43,26 +43,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
<version>5.3.20</version>
<exclusions>
<exclusion>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
@ -134,11 +114,6 @@
<version>5.3.20</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>

View File

@ -7,6 +7,7 @@ import com.appsmith.external.models.AuthenticationResponse;
import com.appsmith.external.models.DatasourceConfiguration;
import com.appsmith.external.models.OAuth2;
import com.appsmith.external.models.UpdatableConnection;
import com.appsmith.util.WebClientUtils;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -15,7 +16,6 @@ import org.bson.internal.Base64;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.function.BodyExtractors;
@ -109,8 +109,7 @@ public class OAuth2AuthorizationCode extends APIConnection implements UpdatableC
final HttpClient securedHttpClient = this.getSecuredHttpClient(datasourceConfiguration);
// Webclient
WebClient.Builder webClientBuilder = WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(securedHttpClient))
WebClient.Builder webClientBuilder = WebClientUtils.builder(securedHttpClient)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.exchangeStrategies(ExchangeStrategies
.builder()
@ -244,4 +243,4 @@ public class OAuth2AuthorizationCode extends APIConnection implements UpdatableC
return oAuth2;
}
}
}

View File

@ -7,6 +7,7 @@ import com.appsmith.external.models.AuthenticationResponse;
import com.appsmith.external.models.DatasourceConfiguration;
import com.appsmith.external.models.OAuth2;
import com.appsmith.external.models.UpdatableConnection;
import com.appsmith.util.WebClientUtils;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -16,7 +17,6 @@ import org.bson.internal.Base64;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.function.BodyExtractors;
@ -88,8 +88,7 @@ public class OAuth2ClientCredentials extends APIConnection implements UpdatableC
final HttpClient securedHttpClient = this.getSecuredHttpClient(datasourceConfiguration);
// Webclient
final WebClient.Builder webClientBuilder = WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(securedHttpClient))
final WebClient.Builder webClientBuilder = WebClientUtils.builder(securedHttpClient)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.exchangeStrategies(ExchangeStrategies
.builder()
@ -102,7 +101,6 @@ public class OAuth2ClientCredentials extends APIConnection implements UpdatableC
webClientBuilder.defaultHeader("Authorization", authorizationHeader);
}
// Webclient
WebClient webClient = webClientBuilder.build();
@ -223,4 +221,4 @@ public class OAuth2ClientCredentials extends APIConnection implements UpdatableC
return oAuth2;
}
}
}

View File

@ -20,6 +20,7 @@ import com.appsmith.external.plugins.BasePlugin;
import com.appsmith.external.plugins.PluginExecutor;
import com.appsmith.external.plugins.SmartSubstitutionInterface;
import com.appsmith.external.services.SharedConfig;
import com.appsmith.util.WebClientUtils;
import com.external.connections.APIConnection;
import com.external.connections.APIConnectionFactory;
import com.external.constants.ResponseDataType;
@ -43,7 +44,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.InvalidMediaTypeException;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.util.CollectionUtils;
import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.function.client.ClientResponse;
@ -299,12 +299,7 @@ public class RestApiPlugin extends BasePlugin {
.secure(SSLHelper.sslCheckForHttpClient(datasourceConfiguration))
.compress(true);
if ("true".equals(System.getProperty("java.net.useSystemProxies"))
&& (!System.getProperty("http.proxyHost", "").isEmpty() || !System.getProperty("https.proxyHost", "").isEmpty())) {
httpClient = httpClient.proxyWithSystemProperties();
}
WebClient.Builder webClientBuilder = WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient));
WebClient.Builder webClientBuilder = WebClientUtils.builder(httpClient);
// Adding headers from datasource
if (datasourceConfiguration.getHeaders() != null) {

View File

@ -12,6 +12,7 @@ import com.appsmith.external.plugins.BasePlugin;
import com.appsmith.external.plugins.PluginExecutor;
import com.appsmith.external.plugins.SmartSubstitutionInterface;
import com.appsmith.external.services.SharedConfig;
import com.appsmith.util.WebClientUtils;
import com.external.helpers.RequestCaptureFilter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -105,7 +106,7 @@ public class SaasPlugin extends BasePlugin {
// Initializing webClient to be used for http call
WebClient.Builder webClientBuilder = WebClient.builder();
WebClient.Builder webClientBuilder = WebClientUtils.builder();
webClientBuilder.defaultHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE);
final RequestCaptureFilter requestCaptureFilter = new RequestCaptureFilter(objectMapper);
webClientBuilder.filter(requestCaptureFilter);
@ -216,4 +217,4 @@ public class SaasPlugin extends BasePlugin {
return Mono.error(new AppsmithPluginException(AppsmithPluginError.UNSUPPORTED_PLUGIN_OPERATION));
}
}
}
}

View File

@ -64,6 +64,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -6,6 +6,7 @@ import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.services.ConfigService;
import com.appsmith.util.WebClientUtils;
import io.sentry.Sentry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -15,7 +16,6 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.util.Map;
@ -56,7 +56,7 @@ public class InstanceConfig implements ApplicationListener<ApplicationReadyEvent
return configService
.getInstanceId()
.flatMap(instanceId -> WebClient
.flatMap(instanceId -> WebClientUtils
.create(baseUrl + "/api/v1/installations")
.post()
.body(BodyInserters.fromValue(Map.of("key", instanceId)))

View File

@ -7,11 +7,11 @@ import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.services.ConfigService;
import com.appsmith.util.WebClientUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.time.Instant;
@ -42,7 +42,7 @@ public class GitCloudServicesUtils {
return Mono.just(gitLimitCache.get(key).getRepoLimit());
}
// Call the cloud service API
return WebClient
return WebClientUtils
.create(baseUrl + "/api/v1/git/limit/" + key)
.get()
.exchange()

View File

@ -1,18 +1,14 @@
package com.appsmith.server.helpers;
import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.util.WebClientUtils;
import org.eclipse.jgit.util.StringUtils;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClientRequest;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.time.Duration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -67,7 +63,7 @@ public class GitUtils {
* @throws IOException exception thrown during openConnection
*/
public static Mono<Boolean> isRepoPrivate(String remoteHttpsUrl) {
return WebClient
return WebClientUtils
.create(remoteHttpsUrl)
.get()
.httpRequest(httpRequest -> {

View File

@ -1,6 +1,6 @@
package com.appsmith.server.helpers;
import org.springframework.web.reactive.function.client.WebClient;
import com.appsmith.util.WebClientUtils;
import reactor.core.publisher.Mono;
import java.net.URI;
@ -24,7 +24,7 @@ public class NetworkUtils {
return Mono.just(cachedAddress);
}
return WebClient
return WebClientUtils
.create()
.get()
.uri(GET_IP_URI)

View File

@ -14,6 +14,7 @@ import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.UserDataService;
import com.appsmith.server.solutions.ImportExportApplicationService;
import com.appsmith.server.solutions.ReleaseNotesService;
import com.appsmith.util.WebClientUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
@ -67,7 +68,7 @@ public class ApplicationTemplateServiceCEImpl implements ApplicationTemplateServ
String apiUrl = uriComponents.toUriString();
return WebClient
return WebClientUtils
.create(apiUrl)
.get()
.exchangeToFlux(clientResponse -> {
@ -95,7 +96,7 @@ public class ApplicationTemplateServiceCEImpl implements ApplicationTemplateServ
// uriComponents will build url in format: version=version&id=id1&id=id2&id=id3
UriComponents uriComponents = uriComponentsBuilder.build();
return WebClient
return WebClientUtils
.create(baseUrl + "/api/v1/app-templates?" + uriComponents.getQuery())
.get()
.exchangeToFlux(clientResponse -> {
@ -132,7 +133,7 @@ public class ApplicationTemplateServiceCEImpl implements ApplicationTemplateServ
public Mono<ApplicationTemplate> getTemplateDetails(String templateId) {
final String baseUrl = cloudServicesConfig.getBaseUrl();
return WebClient
return WebClientUtils
.create(baseUrl + "/api/v1/app-templates/" + templateId)
.get()
.exchangeToMono(clientResponse -> {
@ -157,7 +158,7 @@ public class ApplicationTemplateServiceCEImpl implements ApplicationTemplateServ
.codecs(codecs -> codecs.defaultCodecs().maxInMemorySize(size))
.build();
WebClient webClient = WebClient.builder()
WebClient webClient = WebClientUtils.builder()
.uriBuilderFactory(new NoEncodingUriBuilderFactory(templateUrl))
.exchangeStrategies(strategies)
.build();
@ -213,7 +214,7 @@ public class ApplicationTemplateServiceCEImpl implements ApplicationTemplateServ
public Mono<ApplicationTemplate> getFilters() {
final String baseUrl = cloudServicesConfig.getBaseUrl();
return WebClient
return WebClientUtils
.create(baseUrl + "/api/v1/app-templates/filters")
.get()
.exchangeToMono(clientResponse -> {

View File

@ -1,5 +1,6 @@
package com.appsmith.server.services.ce;
import com.appsmith.external.constants.AnalyticsEvents;
import com.appsmith.external.models.Connection;
import com.appsmith.external.models.DBAuth;
import com.appsmith.external.models.Datasource;
@ -8,7 +9,6 @@ import com.appsmith.external.models.Endpoint;
import com.appsmith.external.models.Property;
import com.appsmith.external.models.SSLDetails;
import com.appsmith.server.configurations.CloudServicesConfig;
import com.appsmith.external.constants.AnalyticsEvents;
import com.appsmith.server.domains.User;
import com.appsmith.server.dtos.MockDataCredentials;
import com.appsmith.server.dtos.MockDataDTO;
@ -19,12 +19,12 @@ import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.DatasourceService;
import com.appsmith.server.services.SessionUserService;
import com.appsmith.util.WebClientUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.time.Instant;
@ -69,7 +69,7 @@ public class MockDataServiceCEImpl implements MockDataServiceCE {
return Mono.justOrEmpty(mockData);
}
return WebClient
return WebClientUtils
.create(baseUrl + "/api/v1/mocks")
.get()
.exchange()

View File

@ -2,13 +2,13 @@ package com.appsmith.server.services.ce;
import com.appsmith.external.models.Datasource;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.Workspace;
import com.appsmith.server.domains.WorkspacePlugin;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.domains.PluginType;
import com.appsmith.server.domains.Workspace;
import com.appsmith.server.domains.WorkspacePlugin;
import com.appsmith.server.dtos.InstallPluginRedisDTO;
import com.appsmith.server.dtos.WorkspacePluginStatus;
import com.appsmith.server.dtos.PluginWorkspaceDTO;
import com.appsmith.server.dtos.WorkspacePluginStatus;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.repositories.PluginRepository;

View File

@ -26,12 +26,12 @@ import com.appsmith.server.services.ConfigService;
import com.appsmith.server.services.DatasourceService;
import com.appsmith.server.services.NewPageService;
import com.appsmith.server.services.PluginService;
import com.appsmith.util.WebClientUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.bson.internal.Base64;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@ -175,8 +175,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
httpClient.secure(SSLHelper.sslCheckForHttpClient(datasource.getDatasourceConfiguration()));
}
WebClient.Builder builder = WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient))
WebClient.Builder builder = WebClientUtils.builder(httpClient)
.baseUrl(oAuth2.getAccessTokenUrl());
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
@ -346,9 +345,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
return integrationDTO;
}))
.flatMap(integrationDTO -> {
WebClient.Builder builder = WebClient.builder();
builder.baseUrl(cloudServicesConfig.getBaseUrl() + "/api/v1/integrations/oauth/appsmith");
return builder.build()
return WebClientUtils.create(cloudServicesConfig.getBaseUrl() + "/api/v1/integrations/oauth/appsmith")
.method(HttpMethod.POST)
.body(BodyInserters.fromValue(integrationDTO))
.exchange()
@ -395,7 +392,6 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.DATASOURCE, datasourceId)))
.flatMap(this::validateRequiredFieldsForGenericOAuth2)
.flatMap(datasource -> {
WebClient.Builder builder = WebClient.builder();
UriComponentsBuilder uriBuilder = UriComponentsBuilder.newInstance();
try {
uriBuilder.uri(new URI(cloudServicesConfig.getBaseUrl() + "/api/v1/integrations/oauth/token"))
@ -403,7 +399,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
} catch (URISyntaxException e) {
log.debug("Error while parsing access token URL.", e);
}
return builder.build()
return WebClientUtils.create()
.method(HttpMethod.POST)
.uri(uriBuilder.build(true).toUri())
.exchange()
@ -463,11 +459,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
integrationDTO.setPluginName(plugin.getPluginName());
integrationDTO.setPluginVersion(plugin.getVersion());
WebClient.Builder builder = WebClient
.builder()
.baseUrl(cloudServicesConfig.getBaseUrl() + "/api/v1/integrations/oauth/refresh");
return builder.build()
return WebClientUtils.create(cloudServicesConfig.getBaseUrl() + "/api/v1/integrations/oauth/refresh")
.method(HttpMethod.POST)
.body(BodyInserters.fromValue(integrationDTO))
.exchange()

View File

@ -7,9 +7,10 @@ import com.appsmith.server.repositories.ApplicationRepository;
import com.appsmith.server.repositories.DatasourceRepository;
import com.appsmith.server.repositories.NewActionRepository;
import com.appsmith.server.repositories.NewPageRepository;
import com.appsmith.server.repositories.WorkspaceRepository;
import com.appsmith.server.repositories.UserRepository;
import com.appsmith.server.repositories.WorkspaceRepository;
import com.appsmith.server.services.ConfigService;
import com.appsmith.util.WebClientUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -17,7 +18,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
@ -82,7 +82,7 @@ public class PingScheduledTaskCEImpl implements PingScheduledTaskCE {
return Mono.empty();
}
return WebClient
return WebClientUtils
.create("https://api.segment.io")
.post()
.uri("/v1/track")
@ -123,7 +123,7 @@ public class PingScheduledTaskCEImpl implements PingScheduledTaskCE {
)
.flatMap(statsData -> {
final String ipAddress = statsData.getT2();
return WebClient
return WebClientUtils
.create("https://api.segment.io")
.post()
.uri("/v1/track")

View File

@ -1,11 +1,12 @@
package com.appsmith.server.solutions.ce;
import com.appsmith.server.configurations.CloudServicesConfig;
import com.appsmith.server.domains.Workspace;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.domains.Workspace;
import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.services.ConfigService;
import com.appsmith.server.services.PluginService;
import com.appsmith.util.WebClientUtils;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@ -14,7 +15,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
@ -104,7 +104,7 @@ public class PluginScheduledTaskCEImpl implements PluginScheduledTaskCE {
}
return configService.getInstanceId()
.flatMap(instanceId -> WebClient
.flatMap(instanceId -> WebClientUtils
.create(
baseUrl + "/api/v1/plugins?instanceId=" + instanceId
+ "&lastUpdatedAt=" + lastUpdatedAt)

View File

@ -7,6 +7,7 @@ import com.appsmith.server.configurations.SegmentConfig;
import com.appsmith.server.dtos.ReleaseNode;
import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.services.ConfigService;
import com.appsmith.util.WebClientUtils;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -14,7 +15,6 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
@ -58,7 +58,7 @@ public class ReleaseNotesServiceCEImpl implements ReleaseNotesServiceCE {
}
return configService.getInstanceId()
.flatMap(instanceId -> WebClient
.flatMap(instanceId -> WebClientUtils
.create(
baseUrl + "/api/v1/releases?instanceId=" + instanceId +
// isCloudHosted should be true only for our cloud instance,

View File

@ -7,14 +7,14 @@ import com.appsmith.external.models.DatasourceStructure;
import com.appsmith.external.models.TriggerRequestDTO;
import com.appsmith.external.models.TriggerResultDTO;
import com.appsmith.external.plugins.PluginExecutor;
import com.appsmith.server.domains.Workspace;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.domains.Workspace;
import com.appsmith.server.helpers.MockPluginExecutor;
import com.appsmith.server.helpers.PluginExecutorHelper;
import com.appsmith.server.services.DatasourceService;
import com.appsmith.server.services.WorkspaceService;
import com.appsmith.server.services.PluginService;
import com.appsmith.server.services.UserService;
import com.appsmith.server.services.WorkspaceService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -45,6 +45,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
@ -70,7 +71,7 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>

View File

@ -8,12 +8,12 @@ set -o noglob
declare -a proxy_args
proxy_configured=0
if [[ ${HTTP_PROXY-} =~ ^http://(.*):(.*)$ && ${BASH_REMATCH[2]} != 0 ]]; then
if [[ ${HTTP_PROXY-} =~ ^http://(.*):([[:digit:]]*)/?$ && ${BASH_REMATCH[2]} != 0 ]]; then
proxy_args+=(-Dhttp.proxyHost="${BASH_REMATCH[1]}" -Dhttp.proxyPort="${BASH_REMATCH[2]}")
proxy_configured=1
fi
if [[ ${HTTPS_PROXY-} =~ ^https?://(.*):(.*)$ && ${BASH_REMATCH[2]} != 0 ]]; then
if [[ ${HTTPS_PROXY-} =~ ^https?://(.*):([[:digit:]]*)/?$ && ${BASH_REMATCH[2]} != 0 ]]; then
proxy_args+=(-Dhttps.proxyHost="${BASH_REMATCH[1]}" -Dhttps.proxyPort="${BASH_REMATCH[2]}")
proxy_configured=1
fi