AngularJS
An AngularJS application consists of static resources (JS, CSS, images) deployed into an HTTP server. By leveraging the support of the HTTP Whiteboard service for static resources and resource mapping, we can package AngularJS applications into standard OSGi bundles and deploy them into an OSGi container.
The basic tutorial from the AngularJS home page has been copied to index.html which is placed in the top-level directory of the bundle (in a Maven project, that would be src/main/resources/index.html):
<!doctype html> <html ng-app> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.6/angular.min.js"></script> </head> <body> <div> <label>Name:</label> <input type="text" ng-model="yourName" placeholder="Enter a name here"> <hr> <h1>Hello {{yourName}}!</h1> </div> </body> </html>
The Blueprint definition for exporting the resource to the root directory of the web server is shown below:
<blueprint default-activation="eager" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <bean id="resourceMapping" class="org.ops4j.pax.web.extender.whiteboard.runtime.DefaultResourceMapping"> <property name="alias" value="/" /> <property name="path" value="" /> </bean> <bean id="welcomeFile" class="org.ops4j.pax.web.extender.whiteboard.runtime.DefaultWelcomeFileMapping"> <property name="redirect" value="true" /> <property name="welcomeFiles"> <array> <value>index.html</value> </array> </property> </bean> <service id="resources" ref="resourceMapping" interface="org.ops4j.pax.web.extender.whiteboard.ResourceMapping" /> <service id="welcomeFileService" ref="welcomeFile" interface="org.ops4j.pax.web.extender.whiteboard.WelcomeFileMapping" /> </blueprint>
The bundle depends on the http-whiteboard feature. To deploy in Apache Karaf, run the following commands:
karaf@root()> feature:install http-whiteboard karaf@root()> install -s mvn:io.modio.blog/io.modio.blog.osgi.angularjs/1.0-SNAPSHOT Bundle ID: 99
The application should now be accessible at http://host:8181/