Thank you Raymond, I called the HttpServiceRuntim.calculateRequestInfoDTO("/token") inside my servlet and i see my filter listed as filterDTOs: {"path":"/token", "servletContextId":125, "filterDTOs":[{"name":"AuthenticationFilter", "patterns":["/*"], "servletNames":null, "regexs":null, "asyncSupported":false, "dispatcher":[], "initParams":{"component.id":"33", "component.name":"com.casto...ionFilter", "service.id":"117", "objectClass":"[Ljava.la...@5891e480", "filterRank":"10", "service.scope":"prototype", "osgi.http.whiteboard.filter.pattern":"/*", " osgi.http.whiteboard.filter.name":"AuthenticationFilter", "osgi.http.whiteboard.context.select":"(osgi.htt...xtHelper)", "service.ranking":"10", "service.bundleid":"136"}, "serviceId":117, "servletContextId":125}], "servletDTO":{"patterns":["/token"], "name":null, "servletInfo":"", "asyncSupported":false, "initParams":{}, "servletContextId":125, "serviceId":127}, "resourceDTO":null}
However, the filter is still not triggered. If i manually create a ServletContextHelper and add "osgi.http.whiteboard.context.select=( osgi.http.whiteboard.context.name=SharedServletContextHelper)" to both the filter and the servlet then i can see the filter kick in before the request hit the servlet. So I think shared servlet context is required to have the filters works across bundles. My concern is that i cannot use the SharedServletContextHelper on the resource service because it will not see the icons folder in my bundle. Here is the debug log if i use the SharedServletContextHelper with the resource service: [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - servlet |/static/icons|/bundle1.png -> /static/icons/*:/icons@d606ba18 ==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true [qtp345379538-59] DEBUG org.ops4j.pax.web.service.jetty.internal.HttpServiceContext - Handling request for [/static/icons/bundle1.png] using http context [org.ops4j.pax.web.extender.whiteboard.internal.WebApplication$1@1b9ac962] [qtp345379538-59] DEBUG org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler - handling request org.ops4j.pax.web.service.jetty.internal.HttpServiceRequestWrapper@5b1bfc6, org.ops4j.pax.web.service.jetty.internal.HttpServiceResponseWrapper@b765100 [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - chain=org.ops4j.pax.web.service.spi.model.FilterModel-13->/static/icons/*:/icons@d606ba18 ==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - call filter org.ops4j.pax.web.service.spi.model.FilterModel-13 [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - call servlet /static/icons/*:/icons@d606ba18==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true <<<<<LOOK LIKE TRYING TO FIND THE ICONS FOLDER IN ANOTHER BUNDLE [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ErrorPageErrorHandler - getErrorPage(GET /static/icons/bundle1.png) => error_page=null (from global default) So now the question really is how to hook my servlet filter to a resource service. Thai On Wed, Sep 12, 2018 at 3:01 PM, Raymond Auge <raymond.a...@liferay.com> wrote: > Hello Thai, > > I don't see anything wrong. > > It looks like they all "target" the default "ServletContextHelper" (i.e. > the same context) and so the filter should apply to each. > > You should be able to check by getting the HttpServiceRuntime [1] service > and calling the method `calculateRequestInfoDTO(String path)` to see what > the runtime thinks is wired up for that path. > > Sincerely, > - Ray > > [1] https://osgi.org/specification/osgi.cmpn/7.0.0/ > service.http.whiteboard.html#org.osgi.service.http.runtime. > HttpServiceRuntime > > On Wed, Sep 12, 2018 at 2:39 PM, Nhut Thai Le via osgi-dev < > osgi-dev@mail.osgi.org> wrote: > >> Hello, >> >> I want to have a filter at the root of my application where all http >> requests must pass through, so I make a Servlet filter: >> @Component( >> service=Filter.class, >> scope=ServiceScope.PROTOTYPE, >> property= { >> "osgi.http.whiteboard.filter.name=AuthenticationFilter", >> "osgi.http.whiteboard.filter.pattern=/*", >> "service.ranking:Integer=10" >> } >> ) >> public final class AuthenticationFilter implements Filter {...} >> ----------------------------- >> Then I have some servlets (in other bundles) defined like this: >> @Component( >> service = Servlet.class, >> property= { >> "osgi.http.whiteboard.servlet.pattern=/token" >> } >> ) >> public class AccessTokenServlet extends HttpServlet{...} >> ------------------------------- >> I also have some resource services in other bundles: >> @Component(service = IconsResourceService.class, >> property = { >> "osgi.http.whiteboard.resource.pattern=/static/icons/*", >> "osgi.http.whiteboard.resource.prefix=/icons" >> } >> ) >> public class IconsResourceService {} >> ----------------------- >> However, my filter never trigger when i request the icon (static >> resource) or token (servlet). My understanding is that the 3 components >> above reside in different bundles thus they have different servlet contexts >> so the filter wont trigger. I can created a ServletContextHelper and select >> it in the Servlet component annotation but this wont help in the case of >> the resource service. Is there other way to share filter across bundles? >> >> Thai >> >> _______________________________________________ >> OSGi Developer Mail List >> osgi-dev@mail.osgi.org >> https://mail.osgi.org/mailman/listinfo/osgi-dev >> > > > > -- > *Raymond Augé* <http://www.liferay.com/web/raymond.auge/profile> > (@rotty3000) > Senior Software Architect *Liferay, Inc.* <http://www.liferay.com> > (@Liferay) > Board Member & EEG Co-Chair, OSGi Alliance <http://osgi.org> > (@OSGiAlliance) > -- Castor Technologies Inc 460 rue St-Catherine St Ouest, Suite 613 Montréal, Québec H3B-1A7 (514) 360-7208 o (514) 798-2044 f n...@castortech.com www.castortech.com CONFIDENTIALITY NOTICE: The information contained in this e-mail is confidential and may be proprietary information intended only for the use of the individual or entity to whom it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any viewing, dissemination, distribution, disclosure, copy or use of the information contained in this e-mail message is strictly prohibited. If you have received and/or are viewing this e-mail in error, please immediately notify the sender by reply e-mail, and delete it from your system without reading, forwarding, copying or saving in any manner. Thank you. AVIS DE CONFIDENTIALITE: L’information contenue dans ce message est confidentiel, peut être protégé par le secret professionnel et est réservé à l'usage exclusif du destinataire. Toute autre personne est par les présentes avisée qu'il lui est strictement interdit de diffuser, distribuer ou reproduire ce message. Si vous avez reçu cette communication par erreur, veuillez la détruire immédiatement et en aviser l'expéditeur. Merci.
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev