Hello First, the most important line in your code is:
WebContainer webContainer = (WebContainer) context.getService(reference); And especially "context" you're using. pax-web in general and "registerFilter()" method in particular is an attempt to implement concepts from javax.servlet specification (concepts from WEB-INF/web.xml) in OSGi. Short - you're registering filter in different context than the one you have your servlets you want to filter. Even in JavaEE you can't have a filter that's filtering servlets in different contexts. You can however grab a BundleContext from different bundle - just get the single (or even more) Bundle from context.getBundles() by symbolic name for example and get its context - then grab WebContainer service from this context instead of the context you're given in BundleActivator.start(). regards Grzegorz Grzybek wt., 16 paź 2018 o 15:05 Lukasz Lech <[email protected]> napisał(a): > Hello, > > > > I’m trying to register io.prometheus.client.filter.MetricsFilter for > Prometheus metrics. > > > > I’m trying to call registerFilter() with many possible url patterns, but > none seem to have any affect: > > > > @Override > > public void start(BundleContext context) throws Exception > > { > > webContainerTracker = new WebContainerTracker(context); > > webContainerTracker.open(); > > } > > > > @Override > > public Object addingService(ServiceReference reference) > > { > > WebContainer webContainer = (WebContainer) > context.getService(reference); > > this.metricsFilter = new MetricsFilter(); > > webContainer.registerFilter(metricsFilter, new String[]{"/", "*", > "/*"}, null, null, false, null); > > return webContainer; > > } > > > > Expected behavior: > > Any request to Karaf, including opening WebConsole, would land me in > MetricsFilter.doFilter breakpoint > > Observed behavior: > > Nothing, even init() method is not called. > > > > Do wildcards are supported by WebContainer for registering filters? Or not > every request goes through that filters, and I’d need to register filter on > jetty directly? (how?, Jetty seems not to be exposed in OSGi context). > > > > I’m using JaxRS-Publisher that registers servlets using > HttpService.addServlet() (and WebContainer is the only available > implementation). > > > > WebConsole also uses WebContainer, so I assume, it must register servlets > also using that method. > > > > Where is the problem? What I’m doing wrong? > > > > Best regards, > > Lukasz Lech > > > > -- > -- > ------------------ > OPS4J - http://www.ops4j.org - [email protected] > > --- > You received this message because you are subscribed to the Google Groups > "OPS4J" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- ------------------ OPS4J - http://www.ops4j.org - [email protected] --- You received this message because you are subscribed to the Google Groups "OPS4J" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
