From 683176fc48a056d21f821e98b8f85e4ea31b333d Mon Sep 17 00:00:00 2001 From: Nidhi Date: Fri, 26 Mar 2021 21:34:10 +0530 Subject: [PATCH] Increased default limit for webclient payload (#3718) * Increased default limit for webclient payload --- .../docker/templates/nginx-app.conf.template | 2 +- .../external/services/SharedConfig.java | 6 +++++ .../appsmith-plugins/amazons3Plugin/pom.xml | 2 +- .../appsmith-plugins/dynamoPlugin/pom.xml | 2 +- .../elasticSearchPlugin/pom.xml | 2 +- .../appsmith-plugins/firestorePlugin/pom.xml | 2 +- .../appsmith-plugins/mongoPlugin/pom.xml | 2 +- .../mssqlPlugin/dependency-reduced-pom.xml | 2 +- .../appsmith-plugins/mssqlPlugin/pom.xml | 2 +- .../appsmith-plugins/mysqlPlugin/pom.xml | 2 +- .../appsmith-plugins/postgresPlugin/pom.xml | 2 +- .../appsmith-plugins/rapidApiPlugin/pom.xml | 2 +- .../appsmith-plugins/redisPlugin/pom.xml | 2 +- .../appsmith-plugins/redshiftPlugin/pom.xml | 2 +- .../appsmith-plugins/restApiPlugin/pom.xml | 2 +- .../connections/APIConnectionFactory.java | 1 + .../connections/OAuth2AuthorizationCode.java | 2 +- .../connections/OAuth2ClientCredentials.java | 2 +- .../com/external/plugins/RestApiPlugin.java | 26 +++++++++++++------ .../external/plugins/RestApiPluginTest.java | 2 +- app/server/appsmith-server/pom.xml | 2 +- .../configurations/SharedConfigImpl.java | 19 ++++++++++++++ .../src/main/resources/application.properties | 3 ++- app/server/envs/dev.env.example | 2 ++ 24 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 app/server/appsmith-interfaces/src/main/java/com/appsmith/external/services/SharedConfig.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SharedConfigImpl.java diff --git a/app/client/docker/templates/nginx-app.conf.template b/app/client/docker/templates/nginx-app.conf.template index b7cb502f93..07e0ed2601 100644 --- a/app/client/docker/templates/nginx-app.conf.template +++ b/app/client/docker/templates/nginx-app.conf.template @@ -8,7 +8,7 @@ server { server { listen 443 ssl http2; server_name dev.appsmith.com; - client_max_body_size 10m; + client_max_body_size 100m; ssl_certificate /etc/certificate/dev.appsmith.com.pem; ssl_certificate_key /etc/certificate/dev.appsmith.com-key.pem; diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/services/SharedConfig.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/services/SharedConfig.java new file mode 100644 index 0000000000..e00d977c14 --- /dev/null +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/services/SharedConfig.java @@ -0,0 +1,6 @@ +package com.appsmith.external.services; + +public interface SharedConfig { + + int getCodecSize(); +} diff --git a/app/server/appsmith-plugins/amazons3Plugin/pom.xml b/app/server/appsmith-plugins/amazons3Plugin/pom.xml index 86b0a95c1a..c20790999a 100644 --- a/app/server/appsmith-plugins/amazons3Plugin/pom.xml +++ b/app/server/appsmith-plugins/amazons3Plugin/pom.xml @@ -39,7 +39,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/dynamoPlugin/pom.xml b/app/server/appsmith-plugins/dynamoPlugin/pom.xml index 75bfe75eb3..f1e46f165a 100644 --- a/app/server/appsmith-plugins/dynamoPlugin/pom.xml +++ b/app/server/appsmith-plugins/dynamoPlugin/pom.xml @@ -27,7 +27,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/elasticSearchPlugin/pom.xml b/app/server/appsmith-plugins/elasticSearchPlugin/pom.xml index 6edd487022..e1f5b23f63 100644 --- a/app/server/appsmith-plugins/elasticSearchPlugin/pom.xml +++ b/app/server/appsmith-plugins/elasticSearchPlugin/pom.xml @@ -27,7 +27,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/firestorePlugin/pom.xml b/app/server/appsmith-plugins/firestorePlugin/pom.xml index 44304a65a8..3c7146dcdf 100644 --- a/app/server/appsmith-plugins/firestorePlugin/pom.xml +++ b/app/server/appsmith-plugins/firestorePlugin/pom.xml @@ -27,7 +27,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/mongoPlugin/pom.xml b/app/server/appsmith-plugins/mongoPlugin/pom.xml index fcb6b212c4..157183fc74 100644 --- a/app/server/appsmith-plugins/mongoPlugin/pom.xml +++ b/app/server/appsmith-plugins/mongoPlugin/pom.xml @@ -27,7 +27,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/mssqlPlugin/dependency-reduced-pom.xml b/app/server/appsmith-plugins/mssqlPlugin/dependency-reduced-pom.xml index f62f7e0f96..0083fef9e0 100644 --- a/app/server/appsmith-plugins/mssqlPlugin/dependency-reduced-pom.xml +++ b/app/server/appsmith-plugins/mssqlPlugin/dependency-reduced-pom.xml @@ -64,7 +64,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/mssqlPlugin/pom.xml b/app/server/appsmith-plugins/mssqlPlugin/pom.xml index fedeaa4eb7..ca322c1218 100644 --- a/app/server/appsmith-plugins/mssqlPlugin/pom.xml +++ b/app/server/appsmith-plugins/mssqlPlugin/pom.xml @@ -27,7 +27,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/mysqlPlugin/pom.xml b/app/server/appsmith-plugins/mysqlPlugin/pom.xml index eab38834f9..f65a57865f 100644 --- a/app/server/appsmith-plugins/mysqlPlugin/pom.xml +++ b/app/server/appsmith-plugins/mysqlPlugin/pom.xml @@ -26,7 +26,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/postgresPlugin/pom.xml b/app/server/appsmith-plugins/postgresPlugin/pom.xml index ce5b69e0db..2527498a0d 100644 --- a/app/server/appsmith-plugins/postgresPlugin/pom.xml +++ b/app/server/appsmith-plugins/postgresPlugin/pom.xml @@ -27,7 +27,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/rapidApiPlugin/pom.xml b/app/server/appsmith-plugins/rapidApiPlugin/pom.xml index fa2e1944e7..b6750e8713 100644 --- a/app/server/appsmith-plugins/rapidApiPlugin/pom.xml +++ b/app/server/appsmith-plugins/rapidApiPlugin/pom.xml @@ -34,7 +34,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/redisPlugin/pom.xml b/app/server/appsmith-plugins/redisPlugin/pom.xml index f41de124e4..fed768d6a2 100644 --- a/app/server/appsmith-plugins/redisPlugin/pom.xml +++ b/app/server/appsmith-plugins/redisPlugin/pom.xml @@ -27,7 +27,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/redshiftPlugin/pom.xml b/app/server/appsmith-plugins/redshiftPlugin/pom.xml index b1e43673bf..a1c5236e59 100644 --- a/app/server/appsmith-plugins/redshiftPlugin/pom.xml +++ b/app/server/appsmith-plugins/redshiftPlugin/pom.xml @@ -34,7 +34,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/restApiPlugin/pom.xml b/app/server/appsmith-plugins/restApiPlugin/pom.xml index ff6799cf92..c6497e4d2f 100644 --- a/app/server/appsmith-plugins/restApiPlugin/pom.xml +++ b/app/server/appsmith-plugins/restApiPlugin/pom.xml @@ -27,7 +27,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 provided diff --git a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/APIConnectionFactory.java b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/APIConnectionFactory.java index d716ce5d27..fbff1cf621 100644 --- a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/APIConnectionFactory.java +++ b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/APIConnectionFactory.java @@ -2,6 +2,7 @@ package com.external.connections; import com.appsmith.external.models.AuthenticationDTO; import com.appsmith.external.models.OAuth2; +import com.appsmith.external.services.SharedConfig; import reactor.core.publisher.Mono; diff --git a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/OAuth2AuthorizationCode.java b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/OAuth2AuthorizationCode.java index 2be2b0d170..aa28d35856 100644 --- a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/OAuth2AuthorizationCode.java +++ b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/OAuth2AuthorizationCode.java @@ -1,11 +1,11 @@ package com.external.connections; import com.appsmith.external.constants.Authentication; +import com.appsmith.external.exceptions.pluginExceptions.StaleConnectionException; import com.appsmith.external.models.AuthenticationDTO; import com.appsmith.external.models.AuthenticationResponse; import com.appsmith.external.models.OAuth2; import com.appsmith.external.models.UpdatableConnection; -import com.appsmith.external.exceptions.pluginExceptions.StaleConnectionException; import lombok.Getter; import lombok.Setter; import org.springframework.http.HttpHeaders; diff --git a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/OAuth2ClientCredentials.java b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/OAuth2ClientCredentials.java index 470b04558f..33e54ebad3 100644 --- a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/OAuth2ClientCredentials.java +++ b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/connections/OAuth2ClientCredentials.java @@ -1,11 +1,11 @@ package com.external.connections; import com.appsmith.external.constants.Authentication; +import com.appsmith.external.exceptions.pluginExceptions.StaleConnectionException; import com.appsmith.external.models.AuthenticationDTO; import com.appsmith.external.models.AuthenticationResponse; import com.appsmith.external.models.OAuth2; import com.appsmith.external.models.UpdatableConnection; -import com.appsmith.external.exceptions.pluginExceptions.StaleConnectionException; import lombok.Getter; import lombok.Setter; import org.springframework.http.HttpHeaders; diff --git a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/plugins/RestApiPlugin.java b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/plugins/RestApiPlugin.java index b294112e2b..dbab27f117 100644 --- a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/plugins/RestApiPlugin.java +++ b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/plugins/RestApiPlugin.java @@ -16,6 +16,7 @@ import com.appsmith.external.models.Property; 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.external.connections.APIConnection; import com.external.connections.APIConnectionFactory; import com.external.helpers.DatasourceValidator; @@ -75,13 +76,6 @@ public class RestApiPlugin extends BasePlugin { private static final int SMART_JSON_SUBSTITUTION_INDEX = 0; - // Setting max content length. This would've been coming from `spring.codec.max-in-memory-size` property if the - // `WebClient` instance was loaded as an auto-wired bean. - public static final ExchangeStrategies EXCHANGE_STRATEGIES = ExchangeStrategies - .builder() - .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(/* 10MB */ 10 * 1024 * 1024)) - .build(); - public RestApiPlugin(PluginWrapper wrapper) { super(wrapper); } @@ -94,6 +88,20 @@ public class RestApiPlugin extends BasePlugin { private final String SESSION_SIGNATURE_KEY_KEY = "sessionSignatureKey"; private final String SIGNATURE_HEADER_NAME = "X-APPSMITH-SIGNATURE"; + private final SharedConfig sharedConfig; + + // Setting max content length. This would've been coming from `spring.codec.max-in-memory-size` property if the + // `WebClient` instance was loaded as an auto-wired bean. + public ExchangeStrategies EXCHANGE_STRATEGIES; + + public RestApiPluginExecutor(SharedConfig sharedConfig) { + this.sharedConfig = sharedConfig; + this.EXCHANGE_STRATEGIES = ExchangeStrategies + .builder() + .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(sharedConfig.getCodecSize())) + .build(); + } + /** * Instead of using the default executeParametrized provided by pluginExecutor, this implementation affords an opportunity * also update the datasource and action configuration for pagination and some minor cleanup of the configuration before execution @@ -288,7 +296,9 @@ public class RestApiPlugin extends BasePlugin { webClientBuilder.filter(apiConnection); } - WebClient client = webClientBuilder.exchangeStrategies(EXCHANGE_STRATEGIES).filter(logRequest()).build(); + WebClient client = webClientBuilder + .exchangeStrategies(EXCHANGE_STRATEGIES) + .filter(logRequest()).build(); // Triggering the actual REST API call return httpCall(client, httpMethod, uri, requestBodyAsString, 0, reqContentType) diff --git a/app/server/appsmith-plugins/restApiPlugin/src/test/java/com/external/plugins/RestApiPluginTest.java b/app/server/appsmith-plugins/restApiPlugin/src/test/java/com/external/plugins/RestApiPluginTest.java index fad4628cde..87f6102da5 100644 --- a/app/server/appsmith-plugins/restApiPlugin/src/test/java/com/external/plugins/RestApiPluginTest.java +++ b/app/server/appsmith-plugins/restApiPlugin/src/test/java/com/external/plugins/RestApiPluginTest.java @@ -39,7 +39,7 @@ import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; public class RestApiPluginTest { - RestApiPlugin.RestApiPluginExecutor pluginExecutor = new RestApiPlugin.RestApiPluginExecutor(); + RestApiPlugin.RestApiPluginExecutor pluginExecutor = new RestApiPlugin.RestApiPluginExecutor(() -> 10 * 1024 * 1024); @Before public void setUp() { diff --git a/app/server/appsmith-server/pom.xml b/app/server/appsmith-server/pom.xml index 6b8d17dbb3..3fe7816559 100644 --- a/app/server/appsmith-server/pom.xml +++ b/app/server/appsmith-server/pom.xml @@ -144,7 +144,7 @@ org.pf4j pf4j-spring - 0.6.0 + 0.7.0 diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SharedConfigImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SharedConfigImpl.java new file mode 100644 index 0000000000..5193badf04 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SharedConfigImpl.java @@ -0,0 +1,19 @@ +package com.appsmith.server.configurations; + +import com.appsmith.external.services.SharedConfig; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +public class SharedConfigImpl implements SharedConfig { + + @Value("${appsmith.codec.max-in-memory-size:10}") + private int CODEC_SIZE; + + @Override + public int getCodecSize() { + return this.CODEC_SIZE * 1024 * 1024; + } +} diff --git a/app/server/appsmith-server/src/main/resources/application.properties b/app/server/appsmith-server/src/main/resources/application.properties index aa0771a77f..1b86904aa7 100644 --- a/app/server/appsmith-server/src/main/resources/application.properties +++ b/app/server/appsmith-server/src/main/resources/application.properties @@ -4,7 +4,8 @@ server.forward-headers-strategy=NATIVE spring.data.mongodb.auto-index-creation=false # Ensures that the size of the request object that we handle is controlled. By default it's 212KB. -spring.codec.max-in-memory-size=5MB +spring.codec.max-in-memory-size=100MB +appsmith.codec.max-in-memory-size=${APPSMITH_CODEC_SIZE:100} # MongoDB Application Database spring.data.mongodb.uri = ${APPSMITH_MONGODB_URI} diff --git a/app/server/envs/dev.env.example b/app/server/envs/dev.env.example index db3f6baef9..e7e74b6bf4 100644 --- a/app/server/envs/dev.env.example +++ b/app/server/envs/dev.env.example @@ -9,6 +9,8 @@ APPSMITH_MAIL_ENABLED=false APPSMITH_ENCRYPTION_PASSWORD=abcd APPSMITH_ENCRYPTION_SALT=abcd +APPSMITH_CODEC_SIZE=10 + #APPSMITH_OAUTH2_GOOGLE_CLIENT_ID="" #APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET=""