Hi Steinar,

The OSGi Http Whiteboard requires your service to be registered as a 
javax.servlet.Servlet. In your code snippet you register it as a VaadinServlet, 
which is not part of the spec. My guess is that this is either being handled by 
a Vaadin component somehow, or that the PAX Web container goes beyond the 
limits of the OSGi spec.

The next thing to comment on is that the servlet is targeting a specific 
Context. You can see what this means in the section about Common Whiteboard 
Properties 
<https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard.common.properties>,
 but in essence your servlet is ineligible to run unless a Servlet Context 
exists with the name "frontend-karaf-demo”.

You can see how to register a custom Context using Servlet Context Properties 
<https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard.servletcontext.helper.properties>,
 but my question to you is “do you actually need a custom context?”. If you 
remove the context selection filter and use a servlet pattern of 
“/frontend-karaf-demo/*” then you should get a servlet listening on the correct 
path.

Best Regards,

Tim


> On 17 Jun 2018, at 09:18, Łukasz Dywicki <[email protected]> wrote:
> 
> Hey,
> I see in your code examples servlets but I can not see HttpContext instance. 
> You specify org.osgi.service.http.HttpContext to be different than default 
> but do not register service which have such id.
> 
> Cheers,
> Łukasz
> --
> Code-House
> http://code-house.org
> 
>> On 16 Jun 2018, at 18:31, Steinar Bang <[email protected]> wrote:
>> 
>> I'm trying to replace alias with web context for a whiteboard servlet
>> started with DS.  I tried to copy-paste an example that works and edit
>> it as needed.
>> 
>> However the end result didn't work (I just got 404 on the path), and I
>> wonder where I went wrong...?
>> 
>> I have this servlet that works, ie. I get the expected results on
>> "/ukelonn/*":
>> @Component(
>>   property= {
>>       HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN+"=/*",
>>       HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=(" + 
>> HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +"=ukelonn)",
>>       HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME+"=ukelonn"},
>>   service=VaadinServlet.class,
>>   immediate=true
>> )
>> public class UkelonnServlet extends TouchKitServlet {
>> ...
>> }
>> 
>> (it sort of works if the service is Servlet.class as well, just not as
>> well)
>> 
>> So I have this:
>> @Component(service={Servlet.class}, property={"alias=/frontend-karaf-demo"} )
>> public class ReactServlet extends HttpServlet {
>>  ...
>> }
>> 
>> and tried replacing this with:
>> @Component(
>>   property= {
>>       HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN+"=/*",
>>       HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=(" + 
>> HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME 
>> +"=frontend-karaf-demo)",
>>       
>> HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME+"=frontend-karaf-demo"},
>>   service=Servlet.class,
>>   immediate=true
>> )
>> public class ReactServlet extends HttpServlet {
>>  ...
>> }
>> 
>> But that just gave me 404 on /frontend-karaf-demo and
>> /frontend-karaf-demo/
>> 
>> So where did I go wrong?
>> 
>> Thanks!
>> 

Reply via email to