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?
--
--
------------------
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.