Re: [PAX-WEB] WebContainer - registering ServletFilter - confusion

2018-10-19 Thread 'Achim Nierbeck' via OPS4J
Hi,

here's a sample (itest) on how to use services for the jetty handler:

https://github.com/ops4j/org.ops4j.pax.web/blob/master/pax-web-itest/pax-web-itest-container/pax-web-itest-container-jetty/src/test/java/org/ops4j/pax/web/itest/jetty/JettyHandlerServiceIntegrationTest.java

regards, Achim

Am Fr., 19. Okt. 2018 um 09:05 Uhr schrieb Grzegorz Grzybek <
gr.grzy...@gmail.com>:

> Hello
>
> if you want global filters or prometheus integration (I imagine it like
>>> single endpoint, like /health or /metrics or something) you could try doing
>>> something container (jetty/undertow/tomcat) specific. Tomcat has
>>> valves, jetty and undertow have handlers - you can look at the code to
>>> check how for example NSCA logging interceptor/handler/valve is implemented.
>>>
>>
>> What would be the right place to register my handler directly on Jetty?
>>
>> It is somewhere created internally in Pax-Web and it is not exposed to
>> OSGi context
>>
>
> I didn't check it, but you could try adding some additional handlers in
> etc/jetty.xml (in Karaf). Something like:
>
> 
>   
> 
>   
>
> I'm not sure if it will work, but jetty.xml syntax is quite powerful. You
> can add different "beans" to different objects.
> Also I see that pax-web-jetty tracks instances of OSGi services for
> org.eclipse.jetty.server.Handler - so you should be able to register your
> own. See
> org.ops4j.pax.web.service.jetty.internal.JettyServerImpl#addHandler() for
> where it's used and how - it can even be prioritized.
>
> The main handler (actually HandlerCollection) is
> org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection and
> when a handler is added to this collection, it'll be called - see here
> how pax-web-jetty calls all the handlers
> 
> .
>
> best regards
> Grzegorz Grzybek
>
>
>>
>> Best regards,
>>
>> Lukasz Lech
>>
>>
>>
>> --
>> --
>> --
>> OPS4J - http://www.ops4j.org - ops4j@googlegroups.com
>>
>> ---
>> 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 ops4j+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> --
> --
> OPS4J - http://www.ops4j.org - ops4j@googlegroups.com
>
> ---
> 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 ops4j+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 

Apache Member
Apache Karaf  Committer & PMC
OPS4J Pax Web  Committer &
Project Lead
blog 
Co-Author of Apache Karaf Cookbook 

Software Architect / Project Manager / Scrum Master

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [PAX-WEB] WebContainer - registering ServletFilter - confusion

2018-10-19 Thread Grzegorz Grzybek
Hello

if you want global filters or prometheus integration (I imagine it like
>> single endpoint, like /health or /metrics or something) you could try doing
>> something container (jetty/undertow/tomcat) specific. Tomcat has valves,
>> jetty and undertow have handlers - you can look at the code to check how
>> for example NSCA logging interceptor/handler/valve is implemented.
>>
>
> What would be the right place to register my handler directly on Jetty?
>
> It is somewhere created internally in Pax-Web and it is not exposed to
> OSGi context
>

I didn't check it, but you could try adding some additional handlers in
etc/jetty.xml (in Karaf). Something like:


  

  

I'm not sure if it will work, but jetty.xml syntax is quite powerful. You
can add different "beans" to different objects.
Also I see that pax-web-jetty tracks instances of OSGi services for
org.eclipse.jetty.server.Handler - so you should be able to register your
own. See
org.ops4j.pax.web.service.jetty.internal.JettyServerImpl#addHandler() for
where it's used and how - it can even be prioritized.

The main handler (actually HandlerCollection) is
org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection and
when a handler is added to this collection, it'll be called - see here how
pax-web-jetty calls all the handlers

.

best regards
Grzegorz Grzybek


>
> Best regards,
>
> Lukasz Lech
>
>
>
> --
> --
> --
> OPS4J - http://www.ops4j.org - ops4j@googlegroups.com
>
> ---
> 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 ops4j+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: [PAX-WEB] WebContainer - registering ServletFilter - confusion

2018-10-17 Thread Lukasz Lech

From: ops4j@googlegroups.com [mailto:ops4j@googlegroups.com] On Behalf Of 
Grzegorz Grzybek
Sent: Mittwoch, 17. Oktober 2018 09:23
To: ops4j@googlegroups.com
Subject: Re: [PAX-WEB] WebContainer - registering ServletFilter - confusion


if you want global filters or prometheus integration (I imagine it like single 
endpoint, like /health or /metrics or something) you could try doing something 
container (jetty/undertow/tomcat) specific. Tomcat has valves, jetty and 
undertow have handlers - you can look at the code to check how for example NSCA 
logging interceptor/handler/valve is implemented.


What would be the right place to register my handler directly on Jetty?
It is somewhere created internally in Pax-Web and it is not exposed to OSGi 
context

Best regards,
Lukasz Lech

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [PAX-WEB] WebContainer - registering ServletFilter - confusion

2018-10-17 Thread Grzegorz Grzybek
Hello

śr., 17 paź 2018 o 08:44 Lukasz Lech  napisał(a):

> OK thank you, I’ll try that way.
>
>
>
> So I need either to implement a bundle that will get the names of other
> bundles it should register metrics for, or I should build metrics in
> specific bundles, and in case I’d like to have karaf-wide Prometheus
> metrics collection I’d need to modify WebContainer implementation?
>

if you want global filters or prometheus integration (I imagine it like
single endpoint, like /health or /metrics or something) you could try doing
something container (jetty/undertow/tomcat) specific. Tomcat has valves,
jetty and undertow have handlers - you can look at the code to check how
for example NSCA logging interceptor/handler/valve is implemented.


>
>
> Are there any plans to provide build-in Prometheus metrics collection in
> pax-web?
>

You could even provide a solution for pax-web ;) For now pax-web isn't
prometheus-aware, but I could imagine some kind of integration.

regards
Grzegorz Grzybek


>
>
> Best regards,
>
> Lukasz Lech
>
>
>
>
>
> *From:* ops4j@googlegroups.com [mailto:ops4j@googlegroups.com] *On Behalf
> Of *Grzegorz Grzybek
> *Sent:* Mittwoch, 17. Oktober 2018 08:14
> *To:* ops4j@googlegroups.com
> *Subject:* Re: [PAX-WEB] WebContainer - registering ServletFilter -
> confusion
>
>
>
> 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  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 - ops4j@googlegroups.com
>
> ---
> 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 ops4j+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> --
> OPS4J - http://www.ops4j.org - ops4j@googlegroups.com
>
> ---
> You received this message because you are subscribed t

Re: [PAX-WEB] WebContainer - registering ServletFilter - confusion

2018-10-17 Thread Grzegorz Grzybek
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  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 - ops4j@googlegroups.com
>
> ---
> 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 ops4j+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.