diff --git a/qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginIT.java b/qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginIT.java index aa777a2f005d5..f6c6e82888bff 100644 --- a/qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginIT.java +++ b/qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginIT.java @@ -44,6 +44,8 @@ import java.util.ArrayList; import java.util.Collection; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; /** @@ -64,16 +66,16 @@ protected Collection> nodePlugins() { return plugins; } - public void testThatSettingHeadersWorks() throws IOException { + public void testThatPluginCannotOverrideExecutionContext() throws IOException { ensureGreen(); try { Response response = getRestClient().performRequest(new Request("GET", "/_execution_context")); - System.out.println("Response body: " + new String(response.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8)); -// fail("request should have failed"); + fail("request should have failed"); } catch(ResponseException e) { Response response = e.getResponse(); - assertThat(response.getStatusLine().getStatusCode(), equalTo(401)); - assertThat(response.getHeader("Secret"), equalTo("required")); + String responseBody = new String(response.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8); + assertThat(response.getStatusLine().getStatusCode(), equalTo(400)); + assertThat(responseBody, containsString("ExecutionContext already present")); } } } diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index d10b4d38720fd..04bd31e6a5809 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -185,7 +185,6 @@ import org.opensearch.persistent.PersistentTasksExecutorRegistry; import org.opensearch.persistent.PersistentTasksService; import org.opensearch.plugins.ActionPlugin; -import org.opensearch.plugins.ActionPluginProxy; import org.opensearch.plugins.AnalysisPlugin; import org.opensearch.plugins.CachePlugin; import org.opensearch.plugins.CircuitBreakerPlugin; @@ -980,10 +979,7 @@ protected Node( settingsModule.getClusterSettings(), settingsModule.getSettingsFilter(), threadPool, - pluginsService.filterPlugins(ActionPlugin.class) - .stream() - .map(p -> ActionPluginProxy.newInstance(p, threadPool)) - .collect(Collectors.toList()), + pluginsService.filterPlugins(ActionPlugin.class), client, circuitBreakerService, usageService, diff --git a/server/src/main/java/org/opensearch/rest/RestHandlerProxy.java b/server/src/main/java/org/opensearch/rest/RestHandlerProxy.java index f1c3081214e6e..945e927c40732 100644 --- a/server/src/main/java/org/opensearch/rest/RestHandlerProxy.java +++ b/server/src/main/java/org/opensearch/rest/RestHandlerProxy.java @@ -9,7 +9,6 @@ package org.opensearch.rest; import org.opensearch.plugins.ActionPlugin; -import org.opensearch.plugins.Plugin; import org.opensearch.threadpool.ThreadPool; import java.lang.reflect.InvocationHandler; @@ -40,7 +39,7 @@ private RestHandlerProxy(RestHandler restHandler, ThreadPool threadPool, ActionP public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { Object result; try { - threadPool.getThreadContext().setExecutionContext(Proxy.getInvocationHandler(plugin).getClass().getName()); + threadPool.getThreadContext().setExecutionContext(plugin.getClass().getName()); result = m.invoke(restHandler, args); threadPool.getThreadContext().clearExecutionContext(); } catch (InvocationTargetException e) {