I have written two servlets that simplifies js frontend delivery and
implementing jersey REST APIs in karaf.

The servlets are deployed to maven central and have been released under
the Apache v2 license.

The servlets are intended as base classes for DS (Declarative Services)
components implementing javax.Servlet OSGi services that will plug into
the web whiteboard.

The FrontendServlet[1] does the following:
 1. Loads and serves up resources from the bundle classpath of the DS
    component (typically index.html and bundle.js, but also CSS, font
    files and images) 
 2. Sets Content-Type for the resources it serves
 3. Has a list of paths that will serve up index.html to bootstrap the
    web application, this is used to be able to reload URLs navigated to
    by the react router[3] 

The JerseyServlet[2] does the following
 1. Set a default package to where Jersey should scan for classes
    implementing REST endpoints (subpackage ".resources" of the package
    the DS component resides in) 
 2. Provides a registration mechanism that can be used to pass injected
    OSGi services to the HK2 dependency injection, so that the OSGi
    services can be injected into the classes implementing REST
    endpoints 

My demo applications have been updated to use these servlets:
 
https://github.com/steinarb/frontend-karaf-demo/blob/master/src/main/java/no/priv/bang/demos/frontendkarafdemo/ReactServlet.java#L14
 
https://github.com/steinarb/jersey-demo/blob/master/jerseyinkaraf.webapi/src/main/java/no/priv/bang/demos/jerseyinkaraf/webapi/CounterServiceServlet.java#L27

I've also written blog posts describing how to use the new servlets.
 
https://steinar.bang.priv.no/2020/03/16/simplified-delivery-of-react-js-from-apache-karaf/
 
https://steinar.bang.priv.no/2020/03/20/simplified-rest-apis-from-karaf-using-jersey/

References:
[1] <https://github.com/steinarb/servlet#frontend>
[2] <https://github.com/steinarb/servlet#jersey>
[3] <https://reacttraining.com/react-router/web/guides/quick-start>

Reply via email to