osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=*) does not work for servlet filter

216 views
Skip to first unread message

Nhut Thai Le

unread,
Sep 13, 2018, 4:05:15 PM9/13/18
to OPS4J
Hello,

I have 2 bundles, one hosts a few servlets and resource services, the other hosts my servlet filters. The idea is to have the filters shared between all bundles. So, for each bundle (not the one contain the servlet filters) I create a ServletContextHelper:
@Component(
            service = ServletContextHelper.class,
          scope = ServiceScope.SINGLETON,
        property = {
                           "osgi.http.whiteboard.context.name=HomeServletContextHelper",
                          "osgi.http.whiteboard.context.path=/home"
              })
public class HomeServletContextHelper extends ServletContextHelper {
 @Override
      public URL getResource(String name) {
          BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
             Bundle bundle = bundleContext.getBundle();
             if ((name != null) && (bundle != null)) {
                      if (name.startsWith("/")) {
                            name = name.substring(1);
                      }

                        return bundle.getEntry(name);
          }
              return null;
   }
}

Then in my servlet (in the same bundle as my ServletContextHelper above) I tell it to use the ServletContextHelper:
@Component(
            service = Servlet.class,
               property= {
                            "osgi.http.whiteboard.servlet.pattern=/token",
                         "osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=HomeServletContextHelper)"
             }
)
public final class AccessTokenServlet extends HttpServlet {...}

My resource service (in the same bundle as my ServletContextHelper above) is also set to use the same ServletContextHelper:
@Component(service = IndexPageResourceService.class,
   property = {
           "osgi.http.whiteboard.resource.pattern=/",
             "osgi.http.whiteboard.resource.prefix=/index.html",
            "osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=HomeServletContextHelper)"
     }
)
public class IndexPageResourceService {}

and finally my servlet filter (in the other bundle):
@Component(
            service = Filter.class,
        scope = ServiceScope.PROTOTYPE,
        property = {
                   "osgi.http.whiteboard.filter.name=AuthenticationFilter",
                       "osgi.http.whiteboard.filter.pattern=/*",
                      "osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=*)"
            }
)
public final class AuthenticationFilter implements Filter {...}

Here the filter is configured to be used by ANY servlet context helper (*) but it never got triggered. Interestingly, if i change the context selection of this filter to: "osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=HomeServletContextHelper)" then the filter is triggered when i request for /home or /home/token.
So the problem is the * not get interpreted as ANY but rather a name that never match. Is there a work around for this?

Nhut Thai Le

unread,
Sep 18, 2018, 12:26:06 PM9/18/18
to OPS4J
Look like this is a known issue: https://ops4j1.jira.com/projects/PAXWEB/issues/PAXWEB-1123. Is there an ETA for this ?

Thai

Achim Nierbeck

unread,
Sep 19, 2018, 4:57:53 AM9/19/18
to op...@googlegroups.com
Hi Thai,

as this is an open source community, you can take control of the ETA of this fix, by providing us with a Patch for it :)

best regards, Achim

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


--

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & Project Lead
blog <http://notizblog.nierbeck.de/>
Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>

Software Architect / Project Manager / Scrum Master 

Reply all
Reply to author
Forward
0 new messages