> On 24 Jul 2018, at 17:00, Steinar Bang <[email protected]> wrote: > >>>>>> Tim Ward <[email protected]>: > >> Would it not be easier to: >> Use the Http Service Whiteboard support for resource serving, rather than >> having the ReactServlet? That’s a big bit of boilerplate for serving some >> static content. It should be much simpler using component >> properties/annotations - see >> https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#d0e121459 >> >> <https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#d0e121459> > > Yes it might be... There are after all, just two files that needs to be > served: the initial index.html file and the bundle.js file it references > (the react app and everything is needs, CSS, fonts, images etc. are > packed into bundle.js using webpack). > > However, there is a bit of special-casing, such as this: > https://github.com/steinarb/ukelonn/blob/using-react/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnServlet.java#L48 > that needs to match this > https://github.com/steinarb/ukelonn/blob/using-react/ukelonn.bundle/src/main/frontend/components/App.js#L30 > so that it is actually possible to enter or reload the URLs created by > the react router into a browser and not get 404. > > I haven't found any way to achive single point of change for these > values, and react needs to include the servlet context (in this case, > "/ukelonn") while the servlets' URLs, are relative to the servlet > context.
That is a little bit yucky, and does mean that you probably can’t do it without code :(. I do think that it would be better to solve it with a ServletContextHelper than in the servlet though. See https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard.servletcontext <https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard.servletcontext> This would move your mime-type handling and routing out of the servlet, and you could put the resource properties on the same component so that the whole thing is encapsulated You could force the servlet to require the context by using the context selection property (see https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard.common.properties <https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard.common.properties>) if you wanted. This separation would be quite a lot cleaner, even if it isn’t smaller. > >> Use the JAX-RS whiteboard to directly register a JAX-RS resource, avoiding >> the need to teach people about launching Jersey (something that they >> probably care very little about). It’s really very simple to do - see >> https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html#service.jaxrs.resource.services >> >> <https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html#service.jaxrs.resource.services> >> > > Hm... is this available in some form in OSGi 6 as well? Or is this OSGi > 7 only? The specification is part of R7, but the implementation will run on R6. There should be no issue deploying it on Karaf, assuming that the PAX Web whiteboard support has the correct capabilities advertised for the Http Service Whiteboard (V 1.0 from R6 is sufficient). > > As I've mentioned elsewhere in this thread I ran into some strange > issues when I tried karaf 4.2.0, and I haven't spent time figuring them > out yet. > >> Using those features should be able to make the example more concise and >> compelling. > > Indeed. > > Seems like there is lots of interesting stuff in OSGi 7, so I should > probably get there as soon as possible. It’s awesome - once you’ve tried using Component Property Annotations and Bundle annotations you will never want to go back! >
