You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2021/05/17 19:12:00 UTC
Trying to use the OSGi 7 web whiteboard annotations
Platform: debian 10.9 "buster", amd64, openjdk 11, karaf 4.3.0,
maven-bundle-plugin 5.1.2
I'm trying to replace the OSGi 6 web whiteboard annotations with OSGi 7
web whiteboard annotations.
For the ServletContextHelper, I've replaced this:
@Component(
property= {
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME+"=handlereg",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH+"=/handlereg"},
service=ServletContextHelper.class,
immediate=true
)
with this:
@Component(service=ServletContextHelper.class, immediate=true)
@HttpWhiteboardContext(name = "handlereg", path = "/handlereg")
That worked fine.
The OSGI-INF/no.priv.bang.handlereg.web.security.HandleregServletContextHelper.xml
file is, AFAICT, identical for the two cases.
Then I've tried to change the annotations with one of the servlets.
I've replaced this:
@Component(
property= {
HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN+"=/*",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +"=handlereg)",
HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME+"=handlereg"},
service=Servlet.class,
immediate=true
)
with this:
@Component(service=Servlet.class, immediate=true)
@HttpWhiteboardContextSelect("(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=handlereg")
@HttpWhiteboardServletName("handlereg")
@HttpWhiteboardServletPattern("/*")
(Note: I've also done a static import of the constants of HttpWhiteboardConstants)
But I get 404 for the servlet.
Does anyone know what I'm doing wrong?
I've looked at the OSGI-INF/no.priv.bang.handlereg.web.frontend.HandleregServlet.xml
file created with both OSGi 6 annotations and OSGi 7 annotations.
With OSGi 6 annotations, the file looks like this
https://gist.github.com/steinarb/fea05dfd8f89990218bc2eacbe7ce953
With OSGi 7 annotations, the file looks like this
https://gist.github.com/steinarb/3472c385755cc76c1d7875bb5e8aad4c
There is a difference in osgi.http.whiteboard.servlet.pattern in the
two.
OSGi 6:
<property name="osgi.http.whiteboard.servlet.pattern" type="String" value="/*"/>
OSGi 7:
<property name="osgi.http.whiteboard.servlet.pattern" type="String">/*</property>
Is that the problem?
If so, how can I fix it?
Here's the maven-bundle-config fron the effective POM:
https://gist.github.com/steinarb/e170c56b13ac49135859490f02b28421
Thanks!
- Steinar
Re: Trying to use the OSGi 7 web whiteboard annotations
Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:
> But I get 404 for the servlet.
> Does anyone know what I'm doing wrong?
> I've looked at the OSGI-INF/no.priv.bang.handlereg.web.frontend.HandleregServlet.xml
> file created with both OSGi 6 annotations and OSGi 7 annotations.
> With OSGi 6 annotations, the file looks like this
> https://gist.github.com/steinarb/fea05dfd8f89990218bc2eacbe7ce953
> With OSGi 7 annotations, the file looks like this
> https://gist.github.com/steinarb/3472c385755cc76c1d7875bb5e8aad4c
> There is a difference in osgi.http.whiteboard.servlet.pattern in the
> two.
> OSGi 6:
> <property name="osgi.http.whiteboard.servlet.pattern" type="String" value="/*"/>
> OSGi 7:
> <property name="osgi.http.whiteboard.servlet.pattern" type="String">/*</property>
> Is that the problem?
Nope! I spotted it. The problem was in
<property name="osgi.http.whiteboard.context.select" type="String" value="(osgi.http.whiteboard.context.name=handlereg"/>
The paranthesis at the end was missing.
With the parantheisis at the end of the
@HttpWhiteboardContextSelect("(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=handlereg)")
the servlet popped into place.
And my first OSGi 7 web whiteboard servlet is flying! Yay! :-)