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 0f15518af9..6216ee7651 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 @@ -2,14 +2,12 @@ package com.external.plugins; import com.appsmith.external.models.ActionConfiguration; import com.appsmith.external.models.ActionExecutionResult; -import com.appsmith.external.models.Param; import com.appsmith.external.models.Property; import com.appsmith.external.models.ResourceConfiguration; import com.appsmith.external.plugins.BasePlugin; import com.appsmith.external.plugins.PluginExecutor; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; -import org.json.JSONObject; import org.pf4j.Extension; import org.pf4j.PluginWrapper; import org.springframework.http.HttpHeaders; @@ -23,7 +21,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class RestApiPlugin extends BasePlugin { @@ -58,18 +55,11 @@ public class RestApiPlugin extends BasePlugin { WebClient.Builder webClientBuilder = WebClient.builder().baseUrl(url); if (resourceConfiguration.getHeaders() != null) { - List headers = resourceConfiguration.getHeaders(); - for (Property header : headers) { - - webClientBuilder.defaultHeader(header.getKey(), header.getValue()); - } + addHeadersToRequest(webClientBuilder, resourceConfiguration.getHeaders()); } if (actionConfiguration.getHeaders() != null) { - List headers = actionConfiguration.getHeaders(); - for (Property header : headers) { - webClientBuilder.defaultHeader(header.getKey(), header.getValue()); - } + addHeadersToRequest(webClientBuilder, actionConfiguration.getHeaders()); } return webClientBuilder @@ -113,5 +103,13 @@ public class RestApiPlugin extends BasePlugin { public void resourceDestroy(Object connection) { } + + private void addHeadersToRequest(WebClient.Builder webClientBuilder, List headers) { + for (Property header : headers) { + if (header.getKey() != null && !header.getKey().isEmpty()) { + webClientBuilder.defaultHeader(header.getKey(), header.getValue()); + } + } + } } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java index 3f5d846cb6..fb3585ea7d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java @@ -15,6 +15,7 @@ public enum AppsmithError { PAGE_ID_NOT_GIVEN(400, 4004, "Missing page id. Pleaes input correct page id"), PAGE_DOESNT_BELONG_TO_USER_ORGANIZATION(400, 4006, "Page {0} does not belong to the current user {1} organization"), UNSUPPORTED_OPERATION(400, 4007, "Unsupported operation"), + ACTION_RUN_KEY_VALUE_INVALID(400, 4008, "Invalid template param key value pair: {0}:{1}"), UNAUTHORIZED_DOMAIN(401, 4001, "Invalid email domain provided. Please sign in with a valid work email ID"), UNAUTHORIZED_ACCESS(401, 4002, "Unauthorized access"), INTERNAL_SERVER_ERROR(500, 5000, "Internal server error while processing request"), diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java index 9014963c12..68a35b69a3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java @@ -34,6 +34,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -125,11 +126,19 @@ public class ActionServiceImpl extends BaseService executeAction(ExecuteActionDTO executeActionDTO) { String actionId = executeActionDTO.getActionId(); - // 1. Fetch the query from the DB to get the type + // 1. Validate input parameters which are required for mustache replacements + List params = executeActionDTO.getParams(); + for (Param param:params) { + if (param.getValue() == null) { + return Mono.error(new AppsmithException(AppsmithError.ACTION_RUN_KEY_VALUE_INVALID, param.getKey(), param.getValue())); + } + } + + // 2. Fetch the query from the DB to get the type Mono actionMono = repository.findById(actionId) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "action", actionId))); - // 2. Instantiate the implementation class based on the query type + // 3. Instantiate the implementation class based on the query type Mono pluginMono = actionMono.flatMap(action -> pluginService.findById(action.getPluginId())) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin"))); @@ -146,7 +155,7 @@ public class ActionServiceImpl extends BaseService resourceMono.zipWith(pluginExecutorMono, (resource, pluginExecutor) -> { ResourceConfiguration resourceConfiguration;