From ce24331d1f05f9f47a684aea68ee5ce3f290cc57 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 8 Jun 2017 09:07:22 +0200 Subject: [PATCH] Add helper methods to TransportActionProxy to identify proxy actions and requests (#25124) Downstream users of out network intercept infrastructure need this information which is hidden due to member and class visibility. --- .../transport/TransportActionProxy.java | 14 ++++++++++++++ .../transport/TransportActionProxyTests.java | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/transport/TransportActionProxy.java b/core/src/main/java/org/elasticsearch/transport/TransportActionProxy.java index 502ab51e0fa..5259fca507e 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportActionProxy.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportActionProxy.java @@ -158,4 +158,18 @@ public final class TransportActionProxy { } return request; } + + /** + * Returns true iff the given action is a proxy action + */ + public static boolean isProxyAction(String action) { + return action.startsWith(PROXY_ACTION_PREFIX); + } + + /** + * Returns true iff the given request is a proxy request + */ + public static boolean isProxyRequest(TransportRequest request) { + return request instanceof ProxyRequest; + } } diff --git a/core/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java b/core/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java index bb1c70da344..e73ad8e439c 100644 --- a/core/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java +++ b/core/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java @@ -258,4 +258,16 @@ public class TransportActionProxyTests extends ESTestCase { assertTrue(transportRequest instanceof TransportActionProxy.ProxyRequest); assertSame(TransportService.HandshakeRequest.INSTANCE, TransportActionProxy.unwrapRequest(transportRequest)); } + + public void testIsProxyAction() { + String action = "foo/bar"; + String proxyAction = TransportActionProxy.getProxyAction(action); + assertTrue(TransportActionProxy.isProxyAction(proxyAction)); + assertFalse(TransportActionProxy.isProxyAction(action)); + } + + public void testIsProxyRequest() { + assertTrue(TransportActionProxy.isProxyRequest(new TransportActionProxy.ProxyRequest<>(() -> null))); + assertFalse(TransportActionProxy.isProxyRequest(TransportRequest.Empty.INSTANCE)); + } }