Skip to content

Introduce RestHandler.Wrapper to help with delegate implementations #1004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
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;
Expand Down Expand Up @@ -209,7 +210,7 @@ public static class Wrapper extends BaseRestHandler {
protected final BaseRestHandler delegate;

public Wrapper(BaseRestHandler delegate) {
this.delegate = delegate;
this.delegate = Objects.requireNonNull(delegate, "BaseRestHandler delegate can not be null");
}

@Override
Expand Down Expand Up @@ -256,5 +257,10 @@ public boolean supportsContentStream() {
public boolean allowsUnsafeBuffers() {
return delegate.allowsUnsafeBuffers();
}

@Override
public boolean allowSystemIndexAccessByDefault() {
return delegate.allowSystemIndexAccessByDefault();
}
}
}
58 changes: 58 additions & 0 deletions server/src/main/java/org/opensearch/rest/RestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -113,6 +114,63 @@ default boolean allowSystemIndexAccessByDefault() {
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;
Expand Down