In OSGi enRoute there is JSON RPC support and uses the Angular service model. So in that model you can create a service in OSGi:
@Component public class MyComp implements JSONRPC { public Object getDescriptor() { // Allows you to provide meta info to your JS code return …; } public Person getPerson(int id) { security.read_people(id); return db.select(Person.class,“select * from table Person where id=%s”, id); } } In JS function myController( $scope, fn$MyComp ) { fn$MyComp.getPerson( $scope.id ).then( function(person) { $scope.person = person; }); } In JS, there is a bit of setup necessary because you need to make a roundtrip to the server to get the methods of the MyComp class. It will then add those methods to the proxy object. Since Javascript is not multithreaded you need to delay initialization and usage of the service object in Java script until this roundtrip is done. This is very well supported in angular with promises. That said, it is a bit convoluted and could be improved. One comment I often get is: Why the marker interface? Well, This is an example of the Java code: https://github.com/osgi/osgi.enroute.examples/blob/5a19fce4526dd96aae558a97ac9bccf8f369036c/osgi.enroute.examples.cm.application/src/osgi/enroute/examples/cm/application/CmFacade.java <https://github.com/osgi/osgi.enroute.examples/blob/5a19fce4526dd96aae558a97ac9bccf8f369036c/osgi.enroute.examples.cm.application/src/osgi/enroute/examples/cm/application/CmFacade.java> And the corresponding Javascript code: https://github.com/osgi/osgi.enroute.examples/blob/5a19fce4526dd96aae558a97ac9bccf8f369036c/osgi.enroute.examples.cm.application/web/main.js <https://github.com/osgi/osgi.enroute.examples/blob/5a19fce4526dd96aae558a97ac9bccf8f369036c/osgi.enroute.examples.cm.application/web/main.js> Kind regards, Peter Kriens > On 27 jul. 2015, at 10:51, Frank Langel <fr...@frankjlangel.com> wrote: > > Hello, > > I never was a big fan of Javascript due to lack of type support. With > TypeScript, things change a bit. In the future, I see two trends > Javascript (TypeScript) is moving downwards from the web client into the > server and will be responsible for server based endpoint services (REST, > calling application objects, glueing) > In 1-2 years, Java will move upwards taking the desktop with the help of > WebAssembly > For the current future, I was wondering if anyone has a sample how to nicely > and elegantly inject OSGI service in/use from Javascript. > > Thanks in advance > Frank > > _______________________________________________ > OSGi Developer Mail List > osgi-dev@mail.osgi.org > https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev