0

Registering filters with whiteboard.

Hi,

I'm trying to use a Servlet filter with a servlet. I'm using Pax-Web 3.0, Declarative services and whiteboard. I have to declarative service components (one for the servlet and one for the filter), and it seems to work fine.

Looking at the documentation I see the following sentence:

For URL Patterns, the pattern registered must be already mapped, either as Resource or a Servlet alias - e.g there should already be a Resource or aServlet registered to the path /foo. For Servlet names, the names used should have been the name that has been explicitly given to the Servlet (as servlet-name), when registering.

How can I guarantee that in a whiteboard setting? I have no idea when the servlet actually gets registered. I guess I can list the servlet as a dependency of the filter, but that makes it tricky to use the filter for multiple servlets.

Is there a better way?

regards, Frank

Frank Lee
  • 2,728
  • 19
  • 30
  • 1
    Actually the way Pax-Web works, it also looks for later registered Servlets If the filter is already registered and matches those. – Achim Nierbeck May 30 '13 at 17:08
  • Great, I suggest in that we rephrase the documentation a bit, so it is clear that the order matters for the servlet registration, but if you use whiteboard, the whiteboard implementation will take care of this. – Frank Lee May 30 '13 at 21:47
  • Actually, there IS a problem. If I register a filter and a servlet using whiteboard it doesn't seem to work all the time. Both are registered as services, and the webconsole indicates that they are being used by whiteboard, only the browser gives a 404. After I restart the whiteboard bundle, it works fine. Any ideas? – Frank Lee Jun 03 '13 at 16:06
  • which version? and filing an issue at https://ops4j1.jira.com/browse/PAXWEB might be best :) – Achim Nierbeck Jun 03 '13 at 16:10
  • I'll craft a more or less minimal case to explore this. Pax Web 3.0.1, by the way. Thanks! – Frank Lee Jun 03 '13 at 16:44

1 Answers1

4

It seems highly unlikely that this is an issue. I expect that the sentence from the documentation indicates that your filter just never get called when there is no destination for the path. I.e. the filter is only called when there is a valid destination (a resource or servlet). A basic aspect of the whiteboard is that you should not care about these issues. It is the responsibility for the whiteboard to handle the http service, the filters, and the servlets in any possible registration order. If not ... it needs a serious issue raised.

I have not looked at the code but I am a heavy user of the whiteboard + filter + servlet + DS and never have seen an issue.

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
  • Ok, that is good enough for me. As I said, I've never *seen* a problem, but wasn't sure if I was just lucky and that it would bite me in the future. Thanks. – Frank Lee May 30 '13 at 16:51
  • Peter, do you have any working examples of whiteboard + filter + servlet + DS? I think I might be missing something on my end. – Yurii Rashkovskii Oct 25 '16 at 16:31
  • nope, unfortunately now. If you make one you can put it on OSGi enRoute for others to see. – Peter Kriens Oct 26 '16 at 09:36