>>>>> Markus Rathgeb <[email protected]>:

> I assume I need to use a "Web Application" and cannot rely on servlets etc.
> https://osgi.org/specification/osgi.cmpn/7.0.0/service.war.html

> Any change to get this mixed with Declarative Service?

This is how I make webapps with apache karaf:
 1. Define a service interface for the webapp, including the beans that
    will define the REST API wire format
    Examples:
     
https://github.com/steinarb/ukelonn/blob/master/ukelonn.services/src/main/java/no/priv/bang/ukelonn/UkelonnService.java#L40
     
https://github.com/steinarb/handlereg/blob/master/handlereg.services/src/main/java/no/priv/bang/handlereg/services/HandleregService.java#L20
 2. Define an application specific database interface (for easy
    avoidance of "application interference with DS service injection" 
    Examples:
     
https://github.com/steinarb/ukelonn/blob/master/ukelonn.services/src/main/java/no/priv/bang/ukelonn/UkelonnDatabase.java#L20
     
https://github.com/steinarb/authservice/blob/master/authservice.definitions/src/main/java/no/priv/bang/authservice/definitions/AuthserviceDatabaseService.java#L30
     
https://github.com/steinarb/handlereg/blob/master/handlereg.services/src/main/java/no/priv/bang/handlereg/services/HandleregDatabase.java#L21
 3. Define a liquibase schema definition for the database
    Examples:
     
https://github.com/steinarb/ukelonn/tree/master/ukelonn.db.liquibase/src/main/resources/ukelonn-db-changelog
     
https://github.com/steinarb/authservice/tree/master/authservice.db.liquibase/src/main/resources/authservice-db-changelog
     
https://github.com/steinarb/handlereg/tree/master/handlereg.db.liquibase/src/main/resources/handlereg-db-changelog
 4. Define a DS component that exposes the application specific database
    interface for a derby database, and runs the liquibase schema in its
    activate method (and also adds some dummy data using liquibase)
    Examples:
     
https://github.com/steinarb/ukelonn/blob/master/ukelonn.db.derbytest/src/main/java/no/priv/bang/ukelonn/db/derbytest/UkelonnDatabaseProvider.java#L47
     
https://github.com/steinarb/authservice/blob/master/authservice.db.derby.test/src/main/java/no/priv/bang/authservice/db/derby/test/DerbyTestDatabase.java#L34
     
https://github.com/steinarb/handlereg/blob/master/handlereg.db.derby.test/src/main/java/no/priv/bang/handlereg/db/derby/test/HandleregDerbyTestDatabase.java#L40
 5. Create a DS component implementing the service interface, using a
    derby database in the unit tests
    Examples:
     
https://github.com/steinarb/ukelonn/blob/master/ukelonn.backend/src/main/java/no/priv/bang/ukelonn/backend/UkelonnServiceProvider.java#L58
     
https://github.com/steinarb/handlereg/blob/master/handlereg.backend/src/main/java/no/priv/bang/handlereg/backend/HandleregServiceProvider.java#L44
 6. Create a DS component adding a web context (ie. the prefix of your
    application, eg. "/authservice" in "http://localhost:8181/authservice";)
    to the web whiteboard, and another DS component adding a  shiro
    filter to the web whiteboard, using authservice to provide the Realm
    and SessionDAO (injected as OSGi services into the filter
    component).  Not much actual code, but pulls in a lot of runtime
    stuff
    Examples of contexts and filters:
     
https://github.com/steinarb/ukelonn/blob/master/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnServletContextHelper.java#L7
     
https://github.com/steinarb/ukelonn/blob/master/ukelonn.web.security/src/main/java/no/priv/bang/ukelonn/web/security/UkelonnShiroFilter.java#L41
     
https://github.com/steinarb/authservice/blob/master/authservice.web.security/src/main/java/no/priv/bang/authservice/web/security/AuthserviceServletContextHelper.java#L22
     
https://github.com/steinarb/authservice/blob/master/authservice.web.security/src/main/java/no/priv/bang/authservice/web/security/AuthserviceShiroFilter.java#L44
     
https://github.com/steinarb/handlereg/blob/master/handlereg.web.security/src/main/java/no/priv/bang/handlereg/web/security/HandleregServletContextHelper.java#L22
     
https://github.com/steinarb/handlereg/blob/master/handlereg.web.security/src/main/java/no/priv/bang/handlereg/web/security/HandleregShiroFilter.java#L38
 7. Create a DS component adding the rest API to the web context in the
    web whiteboard, accepting the service interface as an OSGi
    injection, and injecting it into the jersey  resources that serves
    the requests.  In the tests of the REST endpoints I use mocks for
    the service interface, so this component doesn't need jersey for its
    tests
    Examples:
     
https://github.com/steinarb/ukelonn/blob/master/ukelonn.web.services/src/main/java/no/priv/bang/ukelonn/api/UkelonnRestApiServlet.java#L38
     
https://github.com/steinarb/handlereg/blob/master/handlereg.web.api/src/main/java/no/priv/bang/handlereg/web/api/HandleregWebApi.java#L38
 8. Create a DS component adding a react frontend to the web context
    Examples:
     
https://github.com/steinarb/ukelonn/blob/master/ukelonn.web.frontend/src/main/java/no/priv/bang/ukelonn/web/frontend/UkelonnServlet.java#L36
     
https://github.com/steinarb/handlereg/blob/master/handlereg.web.frontend/src/main/java/no/priv/bang/handlereg/web/frontend/HandleregServlet.java#L36
 9. Create a karaf feature loading the web application with a derby
    database and with authservice to provide the user management
    Examples
     
https://github.com/steinarb/ukelonn/blob/master/karaf/src/main/filtered-resources/feature.xml#L32
     
https://github.com/steinarb/handlereg/blob/master/src/main/filtered-resources/feature.xml#L25

At this point the application can be started and tested on an apache
karaf instance.

The next step is to create a PostgreSQL database similar to th ederby
database, but more permanent.

Reply via email to