Skip to content

Commit

Permalink
fix: inject failed
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Mar 3, 2023
1 parent 9166706 commit 81e83a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;
import java.util.Set;

import jakarta.inject.Singleton;
import jakarta.ws.rs.NameBinding;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
Expand All @@ -44,6 +45,8 @@
import org.apache.hugegraph.election.GlobalMasterInfo;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import org.glassfish.hk2.api.IterableProvider;
import org.glassfish.hk2.api.ServiceHandle;
import org.glassfish.jersey.message.internal.HeaderUtils;
import org.slf4j.Logger;

Expand All @@ -56,7 +59,7 @@ public class RedirectFilter implements ContainerRequestFilter {
private static volatile Client client = null;

@Context
private jakarta.inject.Provider<GraphManager> managerProvider;
private IterableProvider<GraphManager> managerProvider;

private static final Set<String> MUST_BE_NULL = new HashSet<>();

Expand All @@ -69,7 +72,9 @@ public class RedirectFilter implements ContainerRequestFilter {

@Override
public void filter(ContainerRequestContext context) throws IOException {
GraphManager manager = managerProvider.get();
ServiceHandle<GraphManager> handle = managerProvider.getHandle();
E.checkState(handle != null, "Context GraphManager is absent");
GraphManager manager = handle.getService();
E.checkState(manager != null, "Context GraphManager is absent");
GlobalMasterInfo globalMasterInfo = manager.globalMasterInfo();
if (globalMasterInfo == null || !globalMasterInfo.isFeatureSupport()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import jakarta.ws.rs.core.SecurityContext;

import org.apache.commons.lang3.StringUtils;
import org.apache.hugegraph.api.filter.RedirectFilter;
import org.apache.hugegraph.core.GraphManager;
import org.slf4j.Logger;

Expand Down Expand Up @@ -70,6 +71,7 @@ public class GraphsAPI extends API {
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin", "$dynamic"})
@RedirectFilter.RedirectMasterRole
public Object list(@Context GraphManager manager,
@Context SecurityContext sc) {
Set<String> graphs = manager.graphs();
Expand All @@ -94,6 +96,7 @@ public Object list(@Context GraphManager manager,
@Path("{name}")
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin", "$owner=$name"})
@RedirectFilter.RedirectMasterRole
public Object get(@Context GraphManager manager,
@PathParam("name") String name) {
LOG.debug("Get graph by name '{}'", name);
Expand Down

0 comments on commit 81e83a1

Please sign in to comment.