diff --git a/server/src/main/java/org/opensearch/rest/BaseRestHandler.java b/server/src/main/java/org/opensearch/rest/BaseRestHandler.java index acd4b2011a9..c264dac8c6f 100644 --- a/server/src/main/java/org/opensearch/rest/BaseRestHandler.java +++ b/server/src/main/java/org/opensearch/rest/BaseRestHandler.java @@ -50,6 +50,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -209,7 +210,7 @@ public abstract class BaseRestHandler implements RestHandler { protected final BaseRestHandler delegate; public Wrapper(BaseRestHandler delegate) { - this.delegate = delegate; + this.delegate = Objects.requireNonNull(delegate, "BaseRestHandler delegate can not be null"); } @Override @@ -256,5 +257,10 @@ public abstract class BaseRestHandler implements RestHandler { public boolean allowsUnsafeBuffers() { return delegate.allowsUnsafeBuffers(); } + + @Override + public boolean allowSystemIndexAccessByDefault() { + return delegate.allowSystemIndexAccessByDefault(); + } } } diff --git a/server/src/main/java/org/opensearch/rest/RestHandler.java b/server/src/main/java/org/opensearch/rest/RestHandler.java index 6229dba84fb..2d605090244 100644 --- a/server/src/main/java/org/opensearch/rest/RestHandler.java +++ b/server/src/main/java/org/opensearch/rest/RestHandler.java @@ -38,6 +38,7 @@ import org.opensearch.rest.RestRequest.Method; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -113,6 +114,63 @@ public interface RestHandler { return false; } + static RestHandler wrapper(RestHandler delegate) { + return new Wrapper(delegate); + } + + class Wrapper implements RestHandler { + private final RestHandler delegate; + + public Wrapper(RestHandler delegate) { + this.delegate = Objects.requireNonNull(delegate, "RestHandler delegate can not be null"); + } + + @Override + public String toString() { + return delegate.toString(); + } + + @Override + public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { + delegate.handleRequest(request, channel, client); + } + + @Override + public boolean canTripCircuitBreaker() { + return delegate.canTripCircuitBreaker(); + } + + @Override + public boolean supportsContentStream() { + return delegate.supportsContentStream(); + } + + @Override + public boolean allowsUnsafeBuffers() { + return delegate.allowsUnsafeBuffers(); + } + + @Override + public List routes() { + return delegate.routes(); + } + + @Override + public List deprecatedRoutes() { + return delegate.deprecatedRoutes(); + } + + @Override + public List replacedRoutes() { + return delegate.replacedRoutes(); + } + + @Override + public boolean allowSystemIndexAccessByDefault() { + return delegate.allowSystemIndexAccessByDefault(); + } + } + class Route { private final String path;