In the the second part of the “Photostream” trilogy, we will look at how the server notifies all the clients who are observing its stream. There are 2 ways we can do this; either by using server sent events or with websocket.
Since JavaEE 7 supports websocket I’ll be using websocket. Websocket is a 2 way communication channel. In photostream app, the notification/data only flows on way viz. from the server to the client (those observing our photostream) so server sent event (SSE) is actually more appropriate. But to use SSE in JavaEE (in Glassfish/Payara in particular), you have to use add additional libraries.
In you’re using Glassfish/Payara and you would like to try SSE, see this document.
Rather than creating one long screencast, I’ve split it into 3 parts.
The first part – upload service and and Angular client.
The second part – server notification using websocket
The third part – hybrid mobile app to take pictures and uploading them.
Here is the first part
Some points to note about
I’m using asynchronous Servlet to handle the file upload. This is to improve performance and to better utilize server resources by releasing the request thread when the image file is being persisted. We can resume the request once the file have been saved
Since this is a simple application, I’ve saved the images directly in the document root. You should use a CMS or something like a GridFS to save your images
The source code for the first part is available here. Its a NetBeans project and it deploys to Glassfish/Payara.
Instead of writing a blog for this month, I’ve done a short (30 mins) screencast on how to use Ionic, Angular and Cordova to create a hybrid mobile app.
The source (just the www directory and the APK) can be found here.
The app is incomplete; one of the things that you’ll notice is that that when you try to follow a link, the app will open that in a browser. But when you click on the back button, it does not go back to the app. You need to handle the link and display that in the inappbrowser plugin. I’ll leave that as an exercise for the reader.
I initially wanted to display the blogs using drawer navigation; this would make the video longer that I intended. So if your’re curious have a look at Ionic’s side menus.