Testing Java Web Start with VirtualBox (15 Minutes)
Description
This demo begins by building a Java Web Start enabled Swing database application. The application is then deployed to the Apache server that's part of the Sun Web Stack. It also uses the MySQL database server, also from the Sun Web Stack. We then launch Windows XP in VirtualBox and test the application, which will initially fail. After looking at some troubleshooting steps we will realize the problem is references to localhost for our database configuration. After fixing this the application should launch successfully and we can compare its look and feel on both Solaris, Windows and Ubuntu.
OpenSolaris Versions Supported
OpenSolaris 2008.05
Points to Hit
- With VirtualBox, it's free and painless to test your applications on other operating systems.
- With ZFS, we can snapshot our test environments and quickly roll them back to their, clean pre-test state.
Demo Prep
One Time
- Install the Sun Web Stack.
- Add the Apache documents directory, /var/apache22/2.2/htdocs, to the NetBeans Favorites window.
- Using NetBeans, create a new MySQL database called statusDB.
- Create a MySQL username (ev) and password (ev) so that you can access the statusDB database:
% mysql -u root -p password: ***** mysql> grant all on statusDB.* to ev@'%' identified by 'ev'; mysql> grant all on statusDB.* to ev@localhost identified by 'ev';
- Run the SQL script to create the tables used in the demo.
- Install VirtualBox
- Create a ZFS file system for VirtualBox:
- Quit VirtualBox if it is running
- First, move the existing ~/.VirtualBox directory
- Run pfexec zfs create -o mountpoint=/export/home/<your home folder>/.VirtualBox rpool/vbox
- Copy the contents of the moved ~/.VirtualBox directory to the new ~/.VirtualBox directory, which is now its own ZFS file system.
- Install Ubuntu (or your favorite Linux) as a Guest OS.
- Install the Guest Additions.
- sudu su.
- /media/cdrom/VboxLinuxAdditions-x86.run
- Configure Ubuntu with Host Interface Networking (rather than the default NAT).
- Install Sun JDK 6 by running sudo apt-get install sun-java6-jdk. (Really only the JRE is needed, but the JDK is needed for the Testing Web Applications demo.
- Configure Ubuntu to use a static IP address. Add that address, along with the Ubuntu server's host name, to your OpenSolaris /etc/hosts file.
- Install the Guest Additions.
- Install Windows XP as a Guest OS, including the Guest Additions.
- Install the Sun JRE
Pre-demo
- Have Ubuntu in a Saved state
- Have Windows XP in a Saved state
- Start NetBeans
- If necessary, do the demo reset steps.
Gotchas
- If you will not have a network connection, you need to configure OpenSolaris with a static IP address, so the Ubuntu will have something to reference OpenSolaris.
- Host Interface Networking in VirtualBox can get a little dicey. First, not that it only works over a wired interface, so you have to have a hard network connection when giving this presentation. When that's not possible, I bring a router to assign my machine and the Ubuntu guest and IP address.
- I find it difficult to get both Unbutu and Windows XP running at the same time w/out running into memory constraints. And I have 4 GB.
Demo
- Point out that all of the components we will be using, NetBeans, MySQL and Apache, were all installed with a single IPS command: pkg install amp-dev.
Create the Swing Database Application
A side benefit of this demo is we can quickly show off the power of creating in JSR 295/6 database application.
- In NetBeans, create a new Java Desktop Application project named EmployeeStatus.
- Select Database Application as the Application Shell.
- Select statusDB as the Database Connection and evangelist as the Database Table.
- Create the Detail Area as a Table, selecting the status table and click Finish.
- Run the application to show how it behaves.
Configure the Application for Java Web Start
- Open the application's properties, select the Web Start category.
- Select Enable Web Start and Self-signed, which is fine for the purposes of this demo. Close the properties dialog.
- From the configuration drop down on the toolbar, select Web Start and then Run the project again. The application should now launch as a JNLP app.
Deploy and Test the Application Locally from Apache
- Switch to the Files window and copy the contents of the project's dist directory to Apache's htdocs directory which should already be set up in the Favorites window. You could show how easy it is to get the location of this directory from the Web Stack GUI's Options dialog.
- Browse to http://localhost/launch.html and launch the application. You should end up just seeing the jnlp code on the browser window. Ask the audience what the problem is? JNLP needs to be configured as a Apache MIME type.
- Edit /etc/apache2/2.2/mime.types and add application/x-java-jnlp-file jnlp. You can show how easy it is to find the location of this file by looking at the Apache configuration file in the Web Stack Options dialog.
- From a terminal, run svcadm restart apache22
- Test that the Apache now successfully start JWS.
- You've introduced a new OpenSolaris feature, SMF. Return to the presentation to cover SMF.
(Optional) Take a ZFS snapshot of your VirtualBox file system.
By using ZFS, we're free to do whatever we like to the guest operating systems. At the end of the test we'll simply restore them to their pre-test state.
- pfexec zfs snapshot rpool/vbox@pre-test
Test the application from Windows XP.
- Restore Windows XP from it's saved state and go into Full Screen mode.
- Open Internet Explorer and using the IP address of the OpenSolaris host, test the connection to Apache. You should see the "It works!" page.
- Browse to the launch page.
- The application should fail to launch. Looking at the details you'll see it's unable to load the local resource.
- Return to OpenSolaris and edit the launch.jnlp file setting the codebase to "http://<host IP address>/".
- Restart Apache: svcadm restart apache22.
- Test again from Windows XP. It will appear to be working, then silently fail. What recommendations does the audience have for solving the problem?
- Open the Java Control Panel and Show the console (Advanced tab). Launch the application again.
- Look at the console output. Ask the audience what's the problem? (The database connection).
- Return to NetBeans and open persistence.xml. What's wrong? The toplink.jdbc.url is set to localhost. Change it to your IP address. Build the project, which should package EmployeeStatus.jar.
- Switch the the Files window and copy EmployeeStatus.jar. (Note, if you did a Clean and Build, instead of just a build, you also need to copy the lib directory because the certificates are updated in all the jars).
- Switch to the Favorites window and delete the existing EmployeeStatus.jar. Paste the new EmployeeStatus.jar into htdocs.
- Switch to Windows and test the application again. It should now work.
Compare UIs
- Switch to seamless mode and compare the UI on OpenSolaris and Windows XP.
- A a new record in one UI, refresh to see it in the other.
- Close Windows XP, showing VirtualBox's Save State feature.
Test in Ubuntu
Now that we've worked out the kinks, it will work flawlessly on other operating systems, right?
- To conserve memory, close Windows XP, saving the machine state.
- Restore Ubuntu from it's saved state.
- Open Firefox and using the IP address of the OpenSolaris host, test the connection to Apache. You should see the "It works!" page.
- Open the launch page. Low and behold, it works great here too.
- Switch to seamless mode and compare the UI with OpenSolaris.
- When finished, just power off the machine. There's no need to worry about it's state as we're going to rollback to the pre-test snapshot anyhow.
Restore the guest VMs
- zfs rollback rpool/vbox@pre-test
Demo Reset
These are the necessary steps to take in order to successfully run the demo again on the same machine.
- Comment out the JNLP MIME type from /etc/apache2/2.2/mime.types
- Delete the EmployeeStatus project
- Remove the application from Apache
- Restore the database tables
The following steps are only necessary if your guest VMs are not under a ZFS file system and pre-test snapshot.
- Windows XP VM
- Hide the Java Console
- Close all open windows
- Unbutu
- Delete launch.jnlp from the Desktop
- Hide the Java Console
- Run the JNLP file using OpenJDK's javaws, so it returns to the default selection.