Accessing ManagedTagProvider from Servlet


I’ve been looking at the Managed Tag Provider SDK example.

I’d like to add a Servlet that would write to tags in the managed tag provider. What is the correct way of accessing the ManagedTagProvider inside the Servlet’s methods? Is it to simply copy/paste the ProviderConfiguration from the ManagedProviderGatewayHook setup method and calling context.getTagManager().getOrCreateManagedProvider(configuration) again? Or is there a way to share the ManagedTagProvider between the ManagedProviderGatewayHook and the Servlet?


Servlets are instantiated with their no-args constructor by the webserver infrastructure itself. Which means the only way for your servlet to access anything else is via static methods, either on your servlet (where your managed tag provider instance is set on the servlet), or on your gateway hook, where your hook sets static fields with the appropriate information and provides a static method to read them. Or perhaps a static field to hold the one instance of the gateway hook itself. Or possibly your module context.

1 Like

I see. Thank you for the explanation!
How does the module context work?

In most of my modules, the gateway hook has a private static field named myContext and a public static method getMyContext. The field is assigned by the setup() method. Other parts of the module can get the module context from the static method any time after that.

1 Like

Interesting. Thanks for the tip!