MoSIG/ACS

Homeworks of the ACS module (MoSIG Master)

=WSDL= Inspect the Web service
 * http://www.webservicex.net/New/
 * http://www.webservicex.net/New/Home/ServiceDetail/56
 * http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry
 * http://www.webservicex.net/globalweather.asmx?WSDL

=UPnP=

Kody Media Server
Install Kody Media Server https://kodi.tv/ (and activate DLNA/UPnP)

UPnP inspect
Discover UPnP devices and associated services with Node UPnP Client https://www.npmjs.com/package/node-upnp-client

Edit and save upnp-sniffer.js

var upnpClient = require('node-upnp-client'); var cli = new upnpClient;

//start search

cli.searchDevices;

// listen for search terminated

cli.on('searchDevicesEnd', function {	console.log('Servers'+ JSON.stringify(cli._servers)) });

// listen for added / removed devices

cli.on('updateUpnpDevice', function {	console.log('Servers'+ JSON.stringify(cli._servers)) });

node install node-upnp-client node upnp-sniffer.js

UPnP node for Node-RED
Design a UPnP node for Node-RED platform

Choose the configurable properties

Choose the payload

Implement it (optional)

Try it (optional)

Contribute it (optional)

=OSGi=


 * http://www.openhab.org/getting-started/downloads.html


 * http://felix.apache.org/downloads.cgi


 * http://karaf.apache.org/download.html


 * https://maven.apache.org/download.cgi

Install and test Felix
Download the latest distribution of Felix

unzip org.apache.felix.main.distribution-5.6.1.zip cd felix-framework-5.6.1/ java -jar bin/felix.jar

help lb stop 1 lb help

start 1 lb help

What's happen ?

Install and test OpenHAB

 * Install and run Eclipse Smarthome demo https://www.eclipse.org/smarthome
 * Launch the OSGi console
 * Inspect bundles
 * Inspect services
 * Listen to events (Event Admin)

Install and test Glassfish
wget http://download.java.net/glassfish/4.1.1/release/glassfish-4.1.1.zip unzip glassfish-4.1.1*zip cd glassfish4 ./bin/asadmin start-domain

Browse http://localhost:4848

Enable Gogo shell through telnet ./bin/asadmin create-jvm-options --target server -Dglassfish.osgi.start.level.final=3 ./bin/asadmin restart-domain

Edit the Felix config file vi glassfish/osgi/felix/conf/config.properties

TBC

telnet localhost 6666

Getting started
=iPOJO=

Tutorial
Follow the tutorial http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-hello-word-maven-based-tutorial.html

Source code : http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo.distribution.maventutorial/1.12.1/org.apache.felix.ipojo.distribution.maventutorial-1.12.1.zip

0) Create a directory for the project
(install Felix, Maven 3, Java 8 before) mkdir ipojo_training cd ipojo_training

1) Create 1 bundle containing a server component
Generating the bundle skeleton with the iPOJO archetrype http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-maven-plug-in.html

mvn archetype:generate -DarchetypeGroupId=org.apache.felix -DarchetypeArtifactId=maven-ipojo-plugin -DarchetypeVersion=1.12.1

Define value for property 'groupId': : hello Define value for property 'artifactId': : hello_server Define value for property 'version': 1.0-SNAPSHOT: : 0.1.0-SNAPSHOT Define value for property 'package': hello: : hello.server

cd hello_server mvn clean install more bundle.properties more src/main/java/hello/server/HelloComponent.java

2) Deploy the bundle on the running Felix framework
Start Felix

cd felix-framework-5.6.1/ java -jar bin/felix.jar

First commands help lb

Install the bundle jarfile (Note: install file://C:... on Windows) help install install /Users/YOUR_USERNAME/.m2/repository/hello/hello_server/0.1.0/hello_server-0.1.0.jar lb start BUNDLE_ID

What's happen ? headers BUNDLE_ID

Deploy the required package dependencies (ie Import-Package) obr:deploy "OSGi R4 Compendium Bundle" start http://central.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo/1.12.1/org.apache.felix.ipojo-1.12.1.jar

Start the bundle start BUNDLE_ID inspect capability service BUNDLE_ID inspect requirement service BUNDLE_ID

Install and start the bundle start http://central.maven.org/maven2/org/apache/felix/org.apache.felix.gogo.runtime/1.0.0/org.apache.felix.gogo.runtime-1.0.0.jar

Install and start the iPOJO-related commands start http://central.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo.gogo/1.12.1/org.apache.felix.ipojo.gogo-1.12.1.jar help

... ipojo:component ipojo:components ipojo:extensions ipojo:factories ipojo:factory ipojo:handlers ipojo:instance ipojo:instances ... ipojo:components ipojo:component hello.server.HelloComponent ipojo:instances ipojo:instance hello.server.HelloComponent-0

Change the name of the instance of the component by "hello-english" in the @Instanciate annotation in src/main/java/hello/server/HelloComponent.java

Rebuild and update the bundle ipojo:instances ipojo:instance hello-english

For the exam : What is the role of a handler in the iPOJO component model ? (link)

List the deployed handlers ipojo:handlers

Deploy more handlers start http://central.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo.handler.eventadmin/1.8.0/org.apache.felix.ipojo.handler.eventadmin-1.8.0.jar start http://central.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo.handler.whiteboard/1.6.0/org.apache.felix.ipojo.handler.whiteboard-1.6.0.jar

ipojo:handlers

3) Add a HelloService service to the component
Add a HelloService interface in the package hello.service with one public method String sayHello(String name) { ... } in src/main/java/hello/service/HelloService.java

(You can see an example here)

package hello.service;

public interface HelloService {

public String sayHello(String name); }

Complete src/main/java/hello/server/HelloComponent.java in order to implement the HelloService package hello.service;

public class HelloComponent implements hello.service.HelloService {

public HelloComponent { System.out.println("Hello hello_server"); }

public String sayHello(String name) { return "Hello" + name + " !"; } }

4) Deploy the server bundle and inspect the provided service
update BUNDLE_ID headers BUNDLE_ID

What is the matter ?

Modify the bundle.properties file private.packages=hello.server import.packages=* export.packages=hello.service

update BUNDLE_ID headers BUNDLE_ID

inspect capability service BUNDLE_ID inspect requirement service BUNDLE_ID

5) Complete the service interface and the implementation to the server component

 * 1) Add a @Property field for the "lang" service property (The documentation is here)
 * 2) Add @Validate and @Invalidate annotated methods (starting and stopping)

Note : iPOJO annotations are documented here

mvn clean install

update BUNDLE_ID headers BUNDLE_ID

inspect capability service BUNDLE_ID inspect requirement service BUNDLE_ID

6) Create 1 bundle containing a client component
Generate the bundle skeleton with the iPOJO archetrype

mvn archetype:generate -DarchetypeGroupId=org.apache.felix -DarchetypeArtifactId=maven-ipojo-plugin -DarchetypeVersion=1.12.1

Define value for property 'groupId': : hello Define value for property 'artifactId': : hello_client Define value for property 'version': 1.0-SNAPSHOT: : 0.1.0-SNAPSHOT Define value for property 'package': hello: : hello.client

cd hello_client mvn clean install

7) Modify the client component for invoking the sayHello of the server component
Modify the src/main/java/hello/server/HelloComponent.java for invoking the sayHello of the server component (The documentation is here)

(Hint: instanciate a thread during the @Validate method and stop the thread during the @Invalidate method)

(You can see an example here)

???

8) Modify the @Requires annotation of the client component
Modify the @Requires annotation of the client component in order to filter only french-spoken HelloService (The documentation is here)

(You can see an example here)

???

8) Create more instances of the hello server components
Create (ie instanciate) more instances of the hello server components in separate bundles. Each service had a "lang" property different for each bundle and containing a set of ISO 639-1 languages code (en, fr, en-us, en-gb, es, ... )

9) Create a new version of the HelloService interface
Create a new version of the HelloService interface (ie 0.2.0-SNAPSHOT) and its implementation.

package hello.service;

public interface HelloService {

public String sayHello(String name);

public String sayHello(String name, String lang); }

Rebuild and deploy it. update BUNDLE_ID /Users/YOUR_USERNAME/.m2/repository/hello/hello_server/0.2.0/hello_server-0.2.0.jar

10) Create a new version of the HelloService client
Create a new version of the HelloService client (ie 0.1.10-SNAPSHOT). The client component invokes the new method : sayHello(String name, String lang)

11) Solution
https://github.com/donsez/osgi/tree/master/training

=UPnP and OSGi=

Build UPnP samples
git clone https://github.com/apache/felix.git cd felix cd upnp mvn clean install cd samples ls -al

Deployment
Download the last binary distribution of Felix http://felix.apache.org/downloads.cgi unzip org.apache.felix.main.distribution-5.6.1.zip cd felix-framework-5.6.1/ java -jar bin/felix.jar

First commands help lb inspect capability service 1 inspect requirement service 1

inspect capability service 0 inspect requirement service 0

help log log info

Deployement with OBR: OBR is an OSGi service for automate the déployment of a bundle and its (explicit) dependencies. Bundles are downloaded, installed and started from repositories indexed in this document http://felix.apache.org/obr/releases.xml obr:list obr:info "Apache Felix UPnP Base Driver" obr:deploy -s "Apache Felix UPnP Base Driver" lb

How many bundles has been deployed by OBR ?

Uninstall the installed bundles with the command uninstall (argument is the bundle id/number).

Remark: Change /Users/donsez with your home directory echo $HOME. start file:/Users/donsez/.m2/repository/org/apache/felix/org.apache.felix.upnp.sample.binaryLight/0.2.0-SNAPSHOT/org.apache.felix.upnp.sample.binaryLight-0.2.0-SNAPSHOT.jar start file:/Users/donsez/.m2/repository/org/apache/felix/org.apache.felix.upnp.sample.clock/0.2.0-SNAPSHOT/org.apache.felix.upnp.sample.clock-0.2.0-SNAPSHOT.jar start file:/Users/donsez/.m2/repository/org/apache/felix/org.apache.felix.upnp.sample.tv/0.2.0-SNAPSHOT/org.apache.felix.upnp.sample.tv-0.2.0-SNAPSHOT.jar

What's happen ?

obr:list help obr:deploy obr:deploy "Servlet 2.1 API" obr:deploy "Apache Felix UPnP Extra" obr:deploy -s "Apache Felix UPnP Base Driver" obr:deploy -s "Apache Felix UPnP Tester" lb

start 6 start 7 start 8 lb

What's happen ?

Homework
Develop an iPOJO component that lists and inspects the UPnPDevice services available in the service registry.

=OpenHAB=

Install OpenHAB
TODO

Deploy the OpenHAB demo
TODO

Launch OpenHAB
TODO

OpenHAB Event Bus Sniffer
Develop an iPOJO component (using the

@Component @Instantiate public class MyOpenHABBusSniffer {

@Subscriber(     name="myBusSubscriber",      topics="foo") public void receive(Event e) { // Print the receved events } }

Deploy the bundle with the OpenHAB shell (you must deploy the iPOJO runtime).

Solution is here