Bug/rest api
This commit is contained in:
parent
023ef93969
commit
daeba007a1
|
|
@ -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<Property> headers = resourceConfiguration.getHeaders();
|
||||
for (Property header : headers) {
|
||||
|
||||
webClientBuilder.defaultHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
addHeadersToRequest(webClientBuilder, resourceConfiguration.getHeaders());
|
||||
}
|
||||
|
||||
if (actionConfiguration.getHeaders() != null) {
|
||||
List<Property> 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<Property> headers) {
|
||||
for (Property header : headers) {
|
||||
if (header.getKey() != null && !header.getKey().isEmpty()) {
|
||||
webClientBuilder.defaultHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -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<ActionRepository, Action, Str
|
|||
public Mono<ActionExecutionResult> 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<Param> 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<Action> 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<Plugin> 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<ActionRepository, Action, Str
|
|||
);
|
||||
|
||||
|
||||
// 3. Execute the query
|
||||
// 4. Execute the query
|
||||
return actionMono
|
||||
.flatMap(action -> resourceMono.zipWith(pluginExecutorMono, (resource, pluginExecutor) -> {
|
||||
ResourceConfiguration resourceConfiguration;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user