Introduce RestHandler.Wrapper to help with delegate implementations (#1004)
Signed-off-by: Vlad Rozov <vrozov@users.noreply.github.com>
This commit is contained in:
parent
ee644bdc40
commit
b7cf1fae41
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Route> routes() {
|
||||
return delegate.routes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeprecatedRoute> deprecatedRoutes() {
|
||||
return delegate.deprecatedRoutes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReplacedRoute> replacedRoutes() {
|
||||
return delegate.replacedRoutes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowSystemIndexAccessByDefault() {
|
||||
return delegate.allowSystemIndexAccessByDefault();
|
||||
}
|
||||
}
|
||||
|
||||
class Route {
|
||||
|
||||
private final String path;
|
||||
|
|
Loading…
Reference in New Issue