>>>>> - <[email protected]>:

> This is what I used as my guide:
> https://github.com/jersey/jersey/tree/master/examples/osgi-http-service

Thanks!

What I've done so far, in my vaadin-to-react rewrite,
 https://github.com/steinarb/ukelonn/tree/using-react
is to just create a servlet for each service.
 
https://github.com/steinarb/ukelonn/tree/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/api

The servlets either handle POST or GET or both, and what's POSTed is a
JSON object that is turned into a Java bean by jackson, and what's
returned is a bean that is turned into a JSON object by Jackson.  The
beans are defined here:
 
https://github.com/steinarb/ukelonn/tree/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/api/beans
and here
 
https://github.com/steinarb/ukelonn/tree/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.api/src/main/java/no/priv/bang/ukelonn/beans

This has worked well enough and have the advantage of the servlets being
components that can have the class giving access to the database
injected.

The service definition is
 
https://github.com/steinarb/ukelonn/blob/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.api/src/main/java/no/priv/bang/ukelonn/UkelonnService.java#L36

The service implementation, is this DS component
 
https://github.com/steinarb/ukelonn/blob/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnServiceProvider.java#L42

However, with Jersey getting injection of the above service into the
resource classes isn't so easy.

The obvious first step is to make a DS component from ServletContainer
 
http://javadox.com/org.glassfish.jersey.containers/jersey-container-servlet-core/2.7/org/glassfish/jersey/servlet/ServletContainer.html

But the ServletContainer wants to find and instanciate the resource
classes, so they can't be DS components in their own right.  And there
are no backpointers from a resource to the class that instanciated it.

So that would mean I would have to resort to static access methods for
singletons, which is what I did in the JSF/Primefaces version, and in
the first versions of the vaadin version.

And going back to using singletons feels very much like a step
backwards...:-)

If someone are looking for the react/webpack stuff, it is here:
 
https://github.com/steinarb/ukelonn/tree/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.bundle/src/main/frontend

To handle the login I use apache shiro, which is enabled by creating the
servlet context "/ukelonn" with this DS component
 
https://github.com/steinarb/ukelonn/blob/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnServletContextHelper.java
and then putting this filter on the "/ukelonn" servlet context
 
https://github.com/steinarb/ukelonn/blob/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnShiroFilter.java#L42
and putting all of the servlets into this context and making their paths
relative to the context.

The UkelonnShiroFilter handles all of the cookie magic during login and
logout, and blocks access to URLs according to login state and role(s)

The shiro.ini file that defines the various accesses to the URLs
(including the API URL), is here:
 
https://github.com/steinarb/ukelonn/blob/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.bundle/src/main/resources/shiro.ini

Reply via email to