Increased default limit for webclient payload (#3718)

* Increased default limit for webclient payload
This commit is contained in:
Nidhi 2021-03-26 21:34:10 +05:30 committed by GitHub
parent e347b61e53
commit 683176fc48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 66 additions and 27 deletions

View File

@ -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;

View File

@ -0,0 +1,6 @@
package com.appsmith.external.services;
public interface SharedConfig {
int getCodecSize();
}

View File

@ -39,7 +39,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -64,7 +64,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -26,7 +26,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -34,7 +34,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -34,7 +34,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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() {

View File

@ -144,7 +144,7 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
</dependency>
<!-- Appsmith dependencies -->

View File

@ -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;
}
}

View File

@ -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}

View File

@ -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=""