Thursday, September 5, 2013

Bitmoney Demonstration with Fuse and Android

Our focus in this article is setting up and demonstrating the use of Red Hat JBoss Fuse 6 and MQTT to communicate between Fuse and Android.  Messages are routed between Fuse instances using MQTT Topics and Beans as well as utilizing Spring and Camel.  Presentation and Demonstration Videos will be published as well.

Presentation for Internet of Things/MQTT Overview - http://www.slideshare.net/opensourcementor/bitmoney-demonstration

Repository for Code - https://github.com/kpeeples/jboss-fuse-bitmoney-demo

Overview

Required Software:

Download the software necessary to run the application. Installation instructions are below.

1. Red Hat JBoss Fuse version 6.0.0 http://www.jboss.org/products/fuse
2. Red Hat JBoss Fuse IDE http://www.jboss.org/products/fuse
(Testing JBDS 7-Kepler and Tools 4.1.2)
3. Android Development Toolkit (https://developer.android.com/tools/sdk/eclipse-adt.html)
4. Maven version 3.+ (sudo yum install maven or manually at http://maven.apache.org/download.cgi)
5. MySQL

Creating an emulator

Step 1. Open a terminal

Step 2. cd to /tools (bitmoney-demo/android-sdk-linux)

Step 3. run ./android

Step 4. Select Tools, Android 4.2.2 (API 17)

Step 5. Click Install

Step 6. Click Accept License

Step 7. Click Install

Step 8. After the installation is complete, Select the Tools, Manage SDKs menu item

Step 9. Click New

Step 10. type nexus4 for the name

Step 11. Select Galaxy Nexus as the device

Step 12. Select Android 4.2.2 - API Level 17 as the device

Step 13. Click OK

Step 14. Click OK

Step 15. Hit Control-C in the terminal window

Installing m2e

Step 1. Run the FuseIDE if it is not open You can install the Android Connector for Maven via the Eclipse Marketplace.

Step 2. Select Help -> "Install New Software..."

Step 3. If Android SDK is not there "Add" other wise skip to

Step 4. Enter Name: Eclipse Software Location:

 http://download.eclipse.org/releases/juno

Step 5. Repeat for the following repositories

Name: M2E Maven Archiver Connector - Location:  
http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-mavenarchiver/0.15.0/N/0.15.0.201207090125/ .

Name: org.sonatype.tycho.update Location: http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-tycho/0.6.0/N/0.6.0.201207302152/ .

Name: Maven Integration for Android Development Tools Dependency Sites Location: http://rgladwell.github.com/m2e-android/updates/

Step 6. search for "m2e".

Step 7. Select android configurator for m2e

Step 8. Click Next

Step 9. Click Next

Step 10. Accept License

Step 11. Click Finish

Step 12. Click ok on the security warning

Step 13. Click restart now

Step 14. On restart configure the sdk

Step 15. Click use existing android sdk

Step 16. browse to sdk directory bitmoney-demo/android-linux-sdk

Step 17. Click ok

Download the project

Step 1. Open a Terminal

Step 2. cd bitmoney-demo

Step 3. If git is not installed type sudo yum install git and install

Step 4. type git clone http://github.com/kpeeples/jboss-fuse-bitmoney-demo

Import project

Step 1. In Eclipse select Import

Step 2. Select existing maven project

Step 3. Navigate to the jboss-fuse-bitmoney-demo directory

Step 4. Click "OK"

Step 5. Select the BitMoneyService and bitmoney projects

Step 6. Select OK

Step 7. Click Finish

Step 8. Click OK on the error that pops up

Step 9. Click Finish on the install

Step 10. Clock OK on the warning

Step 11. Click OK to restart

Project Setup (Follow up for this)
 *Fix SDK location issues

Step 1. Open a terminal

Step 2. cd bitmoney/android-sdk-linux/platform-tools

Step 3. run ln -s ../build-tools/17.0.0/aapt aapt

Step 4. run ln -s ../build-tools/17.0.0/lib/dx.jar dx.jar

Step 5. cd ~/bitmoney-demo/jboss-fuse-bitmoney-demo

Step 6. mvn android:generate-sources

Step 7. Inside of the Fuse IDE

Step 8. Right click on the bitmoney project and select properties

Step 9. Select android

Step 10. Check Android 4.2.2 11. Click OK

Step 12. Right Click on bitmoney

Step 13. Select Maven-->Update Project

Step 14. select bitmoney

Step 15. Click OK

Compile the BitmoneyService Project 

Step 1. cd /home/fedora/bitmoney-demo/jboss-fuse-bitmoney-demo/BitmoneyService

Step 2. mvn initialize org.apache.felix:maven-bundle-plugin:bundle install -Pna

Step 3. mvn initialize org.apache.felix:maven-bundle-plugin:bundle install -Pemea

Step 4. mvn initialize org.apache.felix:maven-bundle-plugin:bundle install -Pltam

Step 5. mvn initialize org.apache.felix:maven-bundle-plugin:bundle install -Papac

Setup Fuse

Step 1. mkdir fuse

Step 2. cd fuse/

Step 3. mkdir na

Step 4. mkdir emea

Step 5. mkdir apac

Step 6. mkdir ltam

Step 7. cd na/ unzip /home/fedora/Downloads/jboss-fuse-full-6.0.0.redhat-024.zip

Step 8. cd ..

Step 9. ls cd apac/ unzip /home/fedora/Downloads/jboss-fuse-full-6.0.0.redhat-024.zip

Step 10. cd ..

Step 11. ls

Step 12. cd emea/

Step 13. unzip /home/fedora/Downloads/jboss-fuse-full-6.0.0.redhat-024.zip

Step 14. cd ../ltam/

Step 15. unzip /home/fedora/Downloads/jboss-fuse-full-6.0.0.redhat-024.zip

Step16. download the mysql connector
(http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.25.zip/from/http://cdn.mysql.com/)

Step 17. download http://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_3/org.apache.servicemix.bundles.commons-dbcp-1.4_3.jar

Step 18. cd ~/Downloads/ unzip mysql-connector-java-5.1.25.zip

Step 19. mvn install:install-file -Dfile=org.apache.servicemix.bundles.commons-dbcp-1.4_3.jar -DgroupId=org.apache.servicemix.bundles -DartifactId=org.apache.servicemix.bundles.commons-dbcp -Dversion=1.4_3 -Dpackaging=jar -DlocalRepositoryParth=~/.m2/repository

Step 20. Installation steps for each instance Note there will be an error for mqtt-client 1.5 when installing BitcoinService, this will not happen when server is started. Ignore the error during install

NA Install (Repeat for APAC, LTAM and EMA)

Step 1. cd ~/bitmoney-demo/fuse/na/jboss-fuse-6.0.0.redhat-024/deploy/

Step 2.cp ~/Downloads/mysql-connector-java-5.1.25/mysql-connector-java-5.1.25-bin.jar .

Step 3.cd ../etc

Step 4. edit jre.properties make the modifications described in "Modify jre.properties"

Step 5. edit org.apache.karaf.management.cfg

Step 6. change rmiRegistryPort to 1093

Step 7. change rmieServerPort to 44443

Step 8.  edit system.properties change org.osgi.service.http.port to 8183

Step 9. change activemq.port activemq.port to 61613

Step 10. change activemq.jmx.url = 1093 edit jetty.xml

Step 11. change jetty.port to 8183 org.apache.karaf.features.cfg edit the featuresBoot line

featuresBoot=jasypt-encryption,config,management,fabric-boot-commands,fabric-bundle,fabric-maven-proxy,patch,activemq,mq-fabric,camel-xmlbeans,camel,camel-cxf,camel-jms,activemq-xbeans,activemq-camel,camel-blueprint,camel-csv,camel-ftp,camel-bindy,camel-jdbc,camel-exec,camel-jasypt,camel-saxon,camel-snmp,camel-ognl,camel-routebox,camel-script,camel-spring-javaconfig,camel-jaxb,camel-jetty,camel-jmx,camel-mail,camel-paxlogging,camel-rmi,camel-sql,war,camel-xmlbeans,camel-xmljson,camel-xmlsecurity

Step 12.  cd ../bin

Step 13. start the fuse application

Step 14. ./fuse type features:install wrapper wrapper

Step 15. install -n na -d na-service -D na-service

Step 16. Optional *
To install the service:
$ ln -s /home/fedora/bitmoney-demo/fuse/na/jboss-fuse-6.0.0.redhat-024/bin/na-service /etc/init.d/
$ chkconfig na-service --add
To start the service when the machine is rebooted:
$ chkconfig na-service on
End Optional *

Step 17. install dbcp (osgi:install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_3)

Step 18. install the BitmoneyService (install -s fab:file:/home/fedora/bitmoney-demo/jboss-fuse-bitmoney-demo/BitmoneyService/target/BitmoneyService-na-0.0.1-SNAPSHOT.jar) type exit

Modify jre.properties 

Step 1.Add to the beginning of the jre-1.6 section:

 javax.ejb, \ javax.jmdns, \ javax.swing, \ javax.validation, \ javax.validation.constraints, \ javax.validation.groups, \ javax.validation.metadata, \ javax.persistence.spi;version="1.0.1.Final", \ javax.persistence;version="1.0.1.Final";-split-package:=merge-first, \ javax.security.*;-split-package:=merge-first, \ javax.persistence.criteria;version="1.0.1.Final";-split-package:=merge-last, \ javax.persistence.metamodel;version="1.0.1.Final";-split-package:=merge-last, \ javax.security.jacc, \ javax.activation;version="1.1", \ javax.activity, \ javax.annotation;version="1.1", \ javax.annotation.processing;version="1.1", \ javax.ejb;version="3.0", \ javax.ejb.spi;version="3.0", \ javax.interceptor;version="3.0", \

Database Setup

If MySQL is not installed:

Step 1. sudo yum install mysql

Step 2. sudo yum install mysql-server

Step 3. sudo systemctl start mysqld.service

Step 4. sudo enable mysqld.service

Step 5. cd /home/fedora/bitmoney-demo/jboss-fuse-bitmoney-demo/BitmoneyService/sql

Step 6. mysql -u root < bitmoney.sql

Run the Android Project

Step 1. Right click on bitmoney

Step 2. Select Run As --> Android Application

Start/Stop Bitcoin Services

Step 1. cd /home/fedora/bitmoney-demo/jboss-fuse-bitmoney-demo/BitmoneyService

Step 2. start services bash startService.sh

Step 3. stop service bash stopService.sh