wesleyhales.com

AeroGear - Mobile, HTML5, and Auwesome

08 February 2012

html5e | jboss | aerogear | mobile |

The AeroGear project had it's official launch last week and I want to review what we're doing and where we're headed. For starters, AeroGear is focused on:

  • Education - Screencasts, Tutorials, and Quickstarts for running any (HTML5, Hybrid, Native) mobile solution with JBoss projects and app servers.
  • Innovation - Many of AeroGear's primary goals are to provide HTML5 extensions for web applications, both mobile and desktop based.
  • Community - We already have several community members contributing examples, demos, and other useful resources. We want to hear from you! We're here for the community.'

Most front-end developers are familiar with "jQuery callbacks and RESTful services", but all developers should be familiar with how this architecture affects their end of the stack. So we put together the following diagram which explains the concept of "POH5" (Plain Old HTML5)

Poh5.Flow.Expanded

So why another acronym? Why not just call it "Plain Old Open Web"? The HTML5 revolution causes developers to think differently about their overall architecture, with more JavaScript and CSS on the client-side and RESTful endpoints on the server-side. AeroGear hopes to bridge this gap and provide the tools or "gear" you need to get started quickly with the best possible solution.

We're just getting started... For now, we have a quickstart application which fully examines each piece of the POH5 architecture. Take it for a spin with the live demo.

Join Us! or come hang out on freenode #aerogear.

Pushing CDI Events to the Browser with WebSockets

20 January 2012

html5 | websocket | jboss | jetty | cdi |

Disclaimer: Minimal load testing was performed with 10000 concurrent WebSocket connections. You can see some true performance numbers here.
Github Icon Download

Here is the demo in action. As you can see on the right, I have 2 chat windows open and on the left we have a member registration. Users are chatting across a raw WebSocket connection and when another user registers, the CDI event is fired all the way through to the browser as a JavaScript alert via the connected WebSocket clients.

With WebSockets, we have a new development model for server side applications; event based programming. There are 3 out-of-box events associated with WebSockets: onopen, onmessage, and onclose. For starters, we must wire up these three listeners to utilize the core functionality that the WebSocket specification gives us. The open event is fired when the WebSocket connection is opened successfully. The message event is fired when the server sends data. The close event is fired when the WebSocket connection is closed.

But sending messages in the form of strings over raw WebSockets isn't very appealing when we're wanting to develop advanced web applications. Obviously, we're going to be using JSON to transfer data to and from the server. But how do we propagate our CDI events which are fired on the server and have them bubble up on the client?

First, we'll start with the server. I'm using the JBoss AS7 application server and embedding Jetty within my web application. Thanks to this article, I was able to easily add the latest Jetty server to my maven project (dependencies below) to get everything up and running in a few minutes.

A few things worth noting:

  • Security: Since our WebSocket server is running on a different port (8081) than our AS7 server (8080), we must account for not having the ability to share cookies, etc...
  • Proxies: As if proxy servers weren't already a huge problem for running WebSockets and HTTP over the same port, we are now running the separately (but I have a semi-solution for this below)
  • Threading: Since we're observing/listening for CDI events, we must perform some thread same operations and connection sharing.

So, if you're still reading ;) let's get on with the code.

Download the latest JBoss AS7 (7.1.0.CR1b as of this writing)

Add the Jetty maven dependencies to your project. This demo is based off of the original html5-mobile quickstart for JBoss AS7.

Next we setup the WebSocket server using Jetty's WebSocketHandler and embedding it inside a ServletContextListener. Here we're sharing a synchronized set of WebSocket connections across threads. Using the synchronized keyword, we ensure that only a single thread can execute a method or block at one time. The ChatWebSocketHandler contains a global Set of webSocket connections and adds each new connection as it's made within the Jetty server View complete source here.

Now we'll create a method to observe CDI events and send the fired "Member" events to all active connections.

The above code will observe the following event when a new Member is registered through the web interface.

Finally, we setup our WebSocket JavaScript client and safely avoid using the eval() method to execute the received JavaScript.

Here is the JavaScript code which listens for our CDI event, and executes the necessary client side code. (This is the alert popup seen in the video above.)

One additional piece I added to this approach is the use of HAProxy. This gives us a reverse-proxy on the WebSocket port (8081), in the end allowing all traffic (HTTP and ws/wss) to be sent across a central port - 8080 in this case.

As you can see, this is a very prototyped approach to achieve $SUBJECT, but it's a step forward in adding a usable programming layer on top of the WebSocket protocol. There's probably a few framework out there which try to provide a programming model on top of WebSockets, so leave comments if you know of any.

My New Career Choice at Red Hat

04 July 2011

Life | jboss |

July 1st marked my first day on the JBoss RichFaces team. I've decided to push myself and get out of my comfort zone. It seems that a developer only has so many years that he or she can sustain the same position doing the same thing and dealing with the same technology.

I’ve been with Red Hat almost 4 years now and have enjoyed every second of it, and this is the first time in my career that I have chosen the position for myself while working within a company. It’s usually the other way around - as you are either picked for your skills and talent to work on a specific team or for whatever reason you are just told to move to another team.

As for my new position, I have been designated to serve on JBoss’ mobile working group (see Tiger Team). I will be part time on the actual RichFaces project (making the project work on mobile devices) and the other part heavily focused on HTML5 and the Mobile Web. This is a new frontier for developers as we try to create HTML5/CSS3 based web apps that not only match the native app feel but also answer the question “How can we make the mobile web faster using JBoss middleware?”.

As things grow, so will the project and the team. I find excitement in bringing grass roots projects from nothing into full blown enterprise supported products ;) Luckily I was in the right place at the right time and I must say that it was quite an honor to be allowed to make such a move. I’m looking forward to making good stuff happen.

Stay tuned…

Developing Portlets using JSF, Ajax, and Seam (Part 1 of 3)

06 August 2008

Java | bridge | container | jboss | jsf | jsr | portal | portlet |

InfoQ just published the first in a series of 3 articles for the JBoss Portlet Bridge. The author of this series did an unbelievable job. I could write a whole post about how great his article(s) are, but I would hate to loose sight of this post topic :-) heh - just kidding... the author is me!


This first part is about basic JSF development with an easy to follow tutorial and real world development tips. The next one will be about RichFaces and the final (about Seam) will be published right after the release of Beta 4 in early September.

Enjoy!
http://www.infoq.com/articles/jsf-ajax-seam-portlets-pt-1

http://www.infoq.com/articles/jsf-ajax-seam-portlets-pt-2

Page and Component Modal with a4j:status

20 January 2008

Java | demo | jboss | modal | richfaces |

I haven't really had a chance to look at RichFaces OOB modal, but I had written this one over a year ago when Ajax4JSF was still on java.net

Due to an overwhelming interest in the previous article I decided to spend some time developing this modal into a demo application and to add some new features. Modals are good to some and hated by others, they have their place and can certainly add some cleaner usability to any website. The cool thing about a modal window is that the user doesn't feel like they are being redirected to another page. They can still keep their focus on the content at hand while multitasking and spawning another workflow.

So what about component based modals? We know good and well what a page-locking modal is, but has anyone tried to implement a modal that only covers the area of the active ajax component?

This is a component based modal. It basically blocks out the activated component per ajax request.

This demo is already setup and ready to go, check it out here and the instructions on getting it running are in the home page description. This is the same demo I used in my previous Running Seam on Tomcat... article - now updated to the latest version of Seam and cleaned up a bit (and also put it under Google code vcs).

And that's not all! To make life even easier I wrapped the modal(s) up in a nice and neat Facelets component. The modals also allow for unlimited modals-per-page. Meaning that you can have 10000 modals on one page without conflicts ;). Here's how you use it:

 
 
<hc:modal modalId="loading-modal" modalContainerId="loading-modal-msg" hidden="true" width="129px"> 

 Content that you want in the modal goes here... 
</hc:modal> 
 
 


... then put the a4j:status tag inside of an a4j:region. Note the javascript methods being called. You could use these in any onclick event that needs to present a modal.


 
 <a4j:status for="stat1" forceId="true" id="ajaxStatus" 

 onstart="alertModal('loading-modal','loading-modal-msg');" 
 onstop="hideContentModal('loading-modal','loading-modal-msg');"> 

 <f:facet name="start"> 
 
 </f:facet> 
 </a4j:status> 
 


This is a work in progress and maybe some day I will cleanup my js, explain why I did things the way I did them, and package this up in a component jar. For now this is it.

Seam 2.0GA in JBoss Portal (in 5 minutes)

15 November 2007

Java | jboss | portal | richfaces | seam |

**Update - See this article for more info.