0

I've added my custom code as follows

public class StatusUpdateHook implements Hook {

    private static final Logger LOGGER = LoggerFactory.getLogger(StatusUpdateHook.class);

    @Override
    public boolean hook(HttpServerExchange exchange, RequestContext context, BsonValue args, BsonDocument confArgs) {
        LOGGER.info("Hook is Called");
        return true;
    }

    @Override
    public boolean doesSupportRequests(RequestContext rc) {
        return true;
    }

}

added the following line in my config as well,

- group: hooks
      interface: org.restheart.metadata.hooks.Hook
      singletons:
        - name: snooper
          class: org.restheart.metadata.hooks.SnooperHook
        - name: statusChecker
          class: com.techmaddy.rh.hook.StatuspdateHook

But still i'm not able to get this printed in the log, i'm sure i'm missing the part of adding hooks to collection. How do we add that i.e How do we do this "The collection metadata property hooks allows to declare the hooks to be applied to the requests involving the collection and its documents", which is from the document.

1 Answers1

1

you have created the hook class, given it a name in the config file. In order to have it applying to your collection, you need to define the hooks collection property.

PATCH /db/coll { "hooks" : [ { "name": "statusChecker", "args": null } ]}

Now that the collection coll has the hooks array with your hook, RESTHeart will invoke it on requests involving that collection.

Note that the default logging configuration, only prints out the messages of classed in child packages of org.restheart. So either you change the configuration (defining the system property logback.configurationFile, see https://logback.qos.ch/manual/configuration.html) or you instantiate your logger as follows:

private static final Logger LOGGER = LoggerFactory.getLogger("org.restheart.custom.StatuspdateHook");

Andrea Di Cesare
  • 1,125
  • 6
  • 11