Showing posts with label JBoss. Show all posts
Showing posts with label JBoss. Show all posts

Friday, January 31, 2014

iOS APNS & Android GCM Push with Apache Cordova (Phonegap)

Here are my instructions for Hello World, a tutorial with Aerogear's Unified Push Server that allows you to send iOS and Android push notifications to Apache Cordova/Phonegap/HTML5 client applications. If you need help, the best place to hang out is on irc.freenode.net #aerogear channel

The instructions can be found in the readme.txt file and the sample code, while not necessary to follow the tutorial is also available at github https://github.com/burrsutter/hellopush The primary difference between the instructions in the readme.txt and the provided solution is that I added logic to address the OS configuration. If you are an Eclipse user, JBoss is adding a plugin for Phonegap/Apache Cordova project creation - here is a video to see it in action: https://vimeo.com/82204444
https://vimeo.com/81565404

My Aerogear Unified Push Server instance is running at OpenShift - sign-up is free and it only takes a few clicks to select the Aerogear Push 0.X quickstart and you are up and running.

Aerogear Cordova Push Plugin (HelloWorld)

0. getting the Cordova command line tool installed for Mac
sudo npm install -g cordova
cordova -version
3.3.1-0.1.2
http://cordova.apache.org/blog/releases/2013/07/23/cordova-3.html

Cordova Command Line Guide
http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html

npm itself comes from Node.js http://nodejs.org/
npm -version
1.3.25
node --version
v0.10.25
You will also need the Android SDK installed for your OS and in your PATH - commands like "android" and "adb devices" should execute
You will also need "curl", if you type in "curl" and hit return
curl: try 'curl --help' or 'curl --manual' for more information

1. Cordova create has the following sequence: "cordova create folderName bundleID appName"

cordova create hellopush com.burrsutter.hellopush "Hello Push"

2. edit hellopush (bring up your editor) if you open config.xml, you should see <name>Hello Push</name> <widget id="com.burrsutter.hellopush" the widget id becomes the bundle identifier, it must unique identify your iOS app, globally when you setup your iOS provisioning profile, you will need this unique bundle ID

3. cd hellopush

4. cordova platform add android

5. cordova plugin search push

6. cordova plugin add org.jboss.aerogear.cordova.push

7. There is a console.log in the default project as well as in the suggested example code, so make sure to also add the console plugin

cordova plugin add org.apache.cordova.console

and to know the mobile OS install the device plugin

cordova plugin add org.apache.cordova.device

8. index.html - insert the following below <div id="deviceready"> but inside <div class="app"> <font size="6"> <div id="notify">notifications </div> <div id="debug">debug </div> </font>

9. index.js

   successHandler: function (message) {
            var debug = document.getElementById("debug");
            console.log(message);
            debug.innerHTML = "success: " + message;
   },
   errorHandler: function (message) {
            var debug = document.getElementById("debug");
            console.log(message);
            debug.innerHTML = "error: " + message;
   },  
   onNotification: function (e) {
            // alert(e.alert);
            var notify = document.getElementById("notify");
            notify.innerHTML = e.alert;
   },  

    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 
    // 'receivedEvent' function, we must explicity call 
    // 'app.receivedEvent(...);'
    onDeviceReady: function() {
        var config = {
                senderID: "492580885002",
                pushServerURL: "https://aerogear-html5.rhcloud.com",
                variantID: "b3852e72-92e1-4b05-a4bd-b549438d4943",
                variantSecret: "13c9daca-457e-4837-bc26-769ba572a940"
        };
        push.register(
            app.successHandler,
            app.errorHandler,
            {
            	"badge": "true",
                "sound": "true",
                "alert": "true",
                ecb: "app.onNotification",
                pushConfig: config
            });
            
        app.receivedEvent('deviceready');
   },
Note: senderID, variantID and variantSecret were all setup in the Push Console at pushServerURL

http://aerogear.org/docs/guides/aerogear-push-android/google-setup/

http://aerogear.org/docs/guides/AdminConsoleGuide/

10. Run "adb devices" to see if an android device is plugged in correctly then cordova run android

this will install and launch the app on your plugged in, developer-ready Android phone/tablet

11. then send a message

curl -3 -u \
"f07c43a6-bb0a-4bb7-a1eb-a368db272212:e2cf19c3-6636-4712-bbe8-26b7c1ac9c09" \
   -v -H "Accept: application/json" -H "Content-type: application/json" \
   -X POST -d '{"message": {"alert":"Hello AeroGear", "badge":1}}' \
   https://aerogear-html5.rhcloud.com/rest/sender
NOTE: this is not wrapping correctly here in Blogger, here is the gist and I included a send.sh to make sending in numerous messages a little easier. Usage: ./send.sh "My Message" 3

where f07c43a6-bb0a-4bb7-a1eb-a368db272212
is your Application ID from the web console
where e2cf19c3-6636-4712-bbe8-26b7c1ac9c09
is the Master Secret also from the web console

Success, send a few more messages, changing the "Hello AeroGear Unified Push!"

Note: If you wish to deploy the app to another Android device, unplug the current one and plug in the new one - use "cordova run android" again and it will deploy to the new device - the app will still function and receive push notifications without being plugged in on USB.

12. Add iOS, if on Mac OS X, with XCode installed (via Mac AppStore is easiest) and you have previously paid your $99 and know how to get around at http://developer.apple.com

cordova platform add ios
13. Setup your provisioning profile:

http://aerogear.org/docs/guides/aerogear-push-ios/app-id-ssl-certificate-apns/ and

http://aerogear.org/docs/guides/aerogear-push-ios/provisioning-profiles/ and

http://aerogear.org/docs/guides/AdminConsoleGuide/

14. Add the variant for iOS via the Unified Push Server web console - uploading the .p12 file and its associated passphrase

15. look under platforms\ios and you should see a Hello Push.xcodeproj - double click on the .xcodeproj

If you see the General tab, double check the bundle identifier of com.burrsutter.hellopush or whatever you made yours

Modify the index.js (in XCode) for the proper variantID and variantSecret from the Unified Push Server console

16. Assuming you have previously registered your plugged in iOS device with the developer.apple.com portal, you can now hit the big arrow and target your device.

When the app installs it should prompt you to accept push notifications.

17. Look for a new installation/device token under your newly added iOS variant in the UPS web console. If you see no instance/device token then something failed.

18. Finally, send a message, it should hit all the android & iOS devices that you have deployed the app to.

Thursday, July 19, 2012

JBoss Toy Store Screencast

In a previous blog, I wrote an introduction to the various components included in the JBoss Toy Store - that is the name we gave our demo application for JBoss World 2012's Keynote address. The name "toy store" was because we were allowing our "sales staff" to acquire/giveaway cool electronic gadgets or JBoss "schwag" like t-shirts and coffe mugs. I recently sat down and recorded a screencast of the demo application, making it much easier to see and hopefully easier to following than the recording of the staged event. Your feedback and comments are always welcome - plus, the JBoss Toy Store codebase is open source, I would love to see others forking it on github, making improvements, running the demo at their local JUG with a room full of attendees and then making contributions of code, videos, blogs, etc.

JBoss Toy Store Demonstration from JBoss Developer on Vimeo.


And if you are interested in JBoss technical content, we have over 150 videos hosted at Vimeo.com/jbossdeveloper

Monday, July 2, 2012

JBoss World Keynote Demo 2012

In June 2011, we focused our keynote demonstration on JBoss' AS7 and Infinispan technology which we delivered as fully supported products (Enterprise Application Platform 6 and JBoss Data Grid 6) this year.

For 2012, we wanted to make a killer demonstration that was more accessible today - leveraging a core technology that is already officially supported - jBPM 5 in JBoss BRMS 5.3.   The BPM landscape, normally only accessible by large corporations due to license costs and complex proprietary software offerings...is changing.    This blog provides a high-level overview for the various elements that went into the making of the demonstration.   We have already opensourced the codebase at JBoss Developer Framework (jdf).


Recording of the JBoss World 2012 Keynote on YouTube.  The demonstration starts at 14:33.


- BPMN2 modeling (jBPM & Drools - BRMS 5.3)
- Mobile Tasks - HTML5 based task interactions (Aerogear)
- Enterprise Application Provisioning (AppBlade)
- Real-time web-based dashboard (Errai)
- Cloud/Platform-as-a-Service (OpenShift)
- Gamification 
- Open Source - makes all of this technology more accessible to all developers



BPMN2 Web Designer

BPMN2 + Business Process, Rules & Events

With jBPM & Drools, we are able to model the core business logic via BPMN2 and a decision table using a web-based repository and modeling tool.  This means the workflow and its associated rules can easily be changed, in production, without programming and without service disruption.


HTML5 + Cordova Application

AppBlade Provisioning

HTML5, Apache Cordova & AppBlade

We then extended the business logic layer via RESTful services that were consumed by a HTML5 application wrapped with Apache Cordova and delivered via AppBlade - the application was to enable "employees" to use a simple catalog and shopping cart to order schwag (promotional items, giveaways), we had a little sales contest, encouraging audience members to pound in orders via the AppBlade provisioned application or the mobile web using their smartphone's browser.

Leaderboard - Errai-based Dashboard

Dashboard
As a live, audience-interactive demonstration, we needed a "dashboard" that could tell us, instantly, how a particular participant was performing - much like any organization would love to have to real-time analytics - we took advantage of Drools Fusion (BRMS 5.3), eventing and then leveraged Errai+GWT to push those events out to a waiting web browsers running on Linux, Mac and Windows.  Our dashboard is also an HTML5 application that can leverage the current capabilities of advanced web browsers.   This was a great risk - we had several hundred people in the audience, with a saturated WIFI and leveraging free resources at OpenShift.   Our Errai-based Leaderboard turned out to be a huge hit!  And it clearly demonstrates how the average web browser can be used for real-time process monitoring and it runs great on the iPad.


Cloud
Not only do we believe that HTML5 and the explosion of mobile devices is having a profound impact on the BPM industry, PaaS, Platform-as-a-Service, will enable many more organizations who could not afford a large IT capital expenditure to roll-out a new system to leverage business rule and business process systems.  We also needed to leverage the cloud for a purely practical reason - we were enabling random individuals using their 3G/4G (or conference WIFI) mobile devices - this meant the system had to have a public IP address - OpenShift was the answer.

Gamification
We were doing a live, in-person event, where we required audience participation for the software to even function properly.  No volunteers, software that was too hard to use or simply the lack of motivation, would have completely changed the dynamic of the demonstration.   The leaderboard was the secret ingredient - players were able to see their name on the board and instantly see how their activities on their phones were impacting the business scenario.   The concepts of gamification for BPM can obviously get much more sophisticated than what you see in our demo, however, the core concepts are there - make it competitive, recognize and reward the winner, build a team to play along and acknowledge and reward as many random players as possible - encouragement & motivation.  Perhaps in a future version we would offer badges!

Open Source
Not only is are the key products behind this demonstration open source, the actual demo code is itself also open source - we hope that many of you grab the codebase and run this same presentation at your local JUG - run it on OpenShift - have your audience break out their phones and give it a try!

A huge thank you to Kevin Conner who served as a our overall architect and engineering lead for the project.   All of us took this project on knowing that the actual products upon which the demonstration was based was also being delivered in the same month.  It was an exciting challenge and we had a fantastic team - now we get a weekend off and it is time to start planning our next crazy demo - bring on the robots and gesture UI.  ;-)



Wednesday, February 23, 2011

HTML5 WebSockets Adventure

I just recently spent a few days exploring the jungle that is WebSocket support in browsers and servers and I lived to tell about it. I say that it is a jungle because it is obvious to me that with the specification (IETF) not yet finalized this technology is still on the "bleeding edge".

I think it is important to note my particular frame of reference, my world view...I normally do not wish to pull the sources, build my own binary, hack on the default app server jar files, etc. My preference is to find a solution, download a binary version, install/unzip, run and load an out-of-the-box example. In addition, I am looking for a Java-based server, one I can extend with my own custom Java components - ideally a Java EE Servlet container.

My WebSockets Use Case
Thinking like the average Java web developer, I wish extend pieces of my server-side enterprise infrastructure out to the client browser application. One of the reasons that I am excited about HTML5 is that feels like client-server development of the mid-90s - back in the dark ages of PowerBuilder and Delphi. :-) Today, you primarily have to use Adobe Flash Flex for those ultra-rich, real-time capable browser-based UIs but that could change with HTML5. Note: I do not consider Silverlight nor JavaFX to be a real competitor to Flash-based applications at this time.

So, I want to build "dashboards", in jQuery, where the client-side browser is pushed data in real-time. Where my server-side Java architecture is likely a distributed fabric/grid or messaging and where particular data of interest can flow easily to my end-users just as it does around the average datacenter. OK, that might not be the average web app use case, but it is the one I am most interested in.


Step 1: Find a Browser

First thing to point out is that I am not one of the cool kids - I am still running Windows (v7 64-bit). I haven't joined the rush of hardcore techies who are sporting sexy MacBook Pros or big iron Linux workstations.
* Chrome 9.0.597.98 - supports WebSockets out of the box
* Safari 5.0.3 (7533.19.4) - supports WebSockets out of the box
* Opera 11.01 build 1190 - needs to be enabled by end-user
http://my.opera.com/ODIN/blog/2010/12/17/new-html5-features-in-opera-11
* Firefox 4.0b11 - needs to be enabled by end-user
https://developer.mozilla.org/en/WebSockets
* iOS 4.2.1 (8C148) on my iPhone 3G (wifi only supported, killed AT&T service plan)
* Android 2.2 on my Motorola DroidX - no - I also looked at Opera Mobile for the Android but that did not seem to support WebSockets

Testing browsers for WebSockets support
http://websocket.org/echo.html
http://jimbergman.net/websocket-web-browser-test/ - however, this one malfunctioned with my FireFox4

Step 2: Learn

Learn enough to be dangerous, never enough to be great. I am just getting started with a new capability and only had a couple of days to invest so far - needed to get moving as fast as possible. How does every technology explorer get moving these days? Google. Not only is Google your secret weapon for trivia night at the local pizza joint/bar, it can become your lifeline. I found many examples and several of those are now outdated, they just do not work. A few examples are provided by Aditya Yadav for the book Deploying HTML5. One using Netty and another using Jetty - I could not get either one to work - could be user error or could be they are based on the older version of the spec.

One thing that I noticed that demonstrates the relative immaturity of this space, when things do fail, you often do not receive error messages on the servers, nor in the browsers. If you are using a browser-based debugger (e.g. Firebug, Dragonfly), at least you will receive JavaScript error messages, but nothing specific to WebSockets malfunction. In the vast majority of my tests there was only silent (but deadly) failure.

Step 3: Find a Server
My "short-list" of solutions to explore included:
Kaazing
Resin
Jetty
Atmosphere (with JBoss, Spade, Tomcat and Jetty)
Infinispan

Kaazing
Obviously a commercial product with a professional grade website, cited in the html5rocks.com presentation for WebSockets and hosts a really cool online demo at Kaazing.me.

Download, installation, running example in mere moments, it just works. I did not spend more time on Kaazing because I am looking for something that is more Java EE server like.

Resin by Caucho
The Resin team provides a nice write-up on WebSockets at caucho.com/resin-4.0/examples/websocket-java/index.xtp
This particular tutorial broke down for me when I noticed that the client portion of the example was written in PHP. I just do not have the patience to translate the PHP into JSP - call me lazy.

Jetty by Webtide
While Jetty is very popular amongst Java developers who use it as a solution for localhost automated testing (JUnit, TestNG, Selenium, etc), it is not a server that I have spent a lot of time on. The Jetty world is a bit confusing on its own - there are many, many versions, from multiple download sites and multiple Eclipse plug-ins. Just google for "Jetty Download" or "Jetty Eclipse plugin" and you will see what I mean. It can take you several attempts to find the right combination to get everything working.

Then, if you google for "Jetty WebSockets" you end up with a lot of results, but no tutorial, no documented "getting started" that I could find.

Atmosphere
Atmosphere is not specifically a server, it is an open source library/framework that can be added to your favorite Java server (e.g. Tomcat, JBoss, etc). Atmosphere is where I spent the largest portion of my exploratory time - I really wanted to make this one work. It has many examples, including pub-sub with jQuery, my specific area of interest. This one certainly looked the most promising before I dove in.

Atmosphere + JBoss 6
I started with this combination because I get a paycheck from Red Hat so it tends to be my favorite Java application server. Well, that turned into a few hours of hacking away for no positive results. There was someone who wrote up his notes in the Atmosphere Users List but I was unable to follow the same path to make it work.

Atmosphere + Tomcat
I also failed to make Tomcat 6 and Atmosphere work together. Some of the setup/errors are identical to JBoss (it embeds Tomcat) like getting the right version of tc-native1.dll but I was weary after the JBoss attempt and didn't really push hard on Tomcat.

Atmosphere's Spade Server
After a few hours of frustration, I then realized that Atmosphere has an "out-of-the-box" ready to go server so I assumed THAT had to be the answer - downloaded, unzipped, started, fail! The startup looks like
java -jar atmosphere-spade-server-0.6.5.jar -a atmosphere-websocket-chat-0.6.5.war
As I said earlier in the post, you often get no error messages and this was a specific example that I remember. It even loads the page into your browser but nothing happens, clicking the buttons does not work.

At this point, I realized that I was going to need some help - Google, reviewing blog posts and digging through email list archives via Nabble was simply not getting me anywhere. So I jumped on the IRC channel and found jfarcand, the fellow who basically answers all the questions on the email list and blogs for Atmosphere. He was very kind and helpful, my basic question was...is there a setup that is just known to work? answer: Atmosphere + Jetty

Atmosphere + Jetty
Wow, it just works. After several hours of beating my head against the proverbial wall with standalone Resin, standalone Jetty and other Atmosphere combinations this was an amazingly blissful moment. I was able to get the atmosphere-websocket-chat-0.6.5.war to work immediately. And I was also able to figure out what combination of Jetty's WTP plug-in and server played nicely with each other - so I have this little demo editable inside of Eclipse Helios with drag & drop deployment to Jetty.

Infinispan
Infinispan was actually the first place I started when I begin this journey. There is a nice write-up/tutorial on using WebSockets with Infinispan and an example that ships with the distribution. Unfortunately, like almost all of my attempts, version 4.2.0.Final fails "out-of-the-box" with current browsers. The good news is that Galder Z was able to dig in immediately, figure out the specific problem and get it fixed - I have tested his patch and things look very good for 4.2.1.Final.

Conclusion
I had originally thought I could have my own custom application built using WebSockets with the weekend + two business days I had budgeted for the effort. Alas, I was only able to get some out-the-box-examples working with Atmosphere + Jetty and with Infinispan + patch. With that said, I am still very excited about the next generation of web development using the new features that fall under the HTML5 umbrella. The best part about being in the IT business is the constant change - tough to get bored - but that is obviously a double-edged sword. :-)